know which side bread is buttered on
know which side (your) bread is buttered (on)
to be careful not to upset people who you know can help you.
Ollie won't refuse to come with us. He knows which side his bread is buttered.
Cambridge English Idioms Dictionary