When we describe someone as being “goodhearted,” it means that the person literally has a force field of good energy radiating from their heart. Good, honest, trustworthy people have an aura of good energy around them. Dogs have been aware of this magnetic field for centuries and will naturally gravitate toward those who emit good energy.
Dogs will also know if you are a good person based on your body language and how you treat others. If your dealings with others are just and fair, your dog will pick up on that based on how people react to you.
It isn’t entirely clear how dogs make these moral judgments, but it is clear that you need to be consistently fair, both to your dog and to those around you, to let your pet know that you are a good person.