My impression, based on many years of Trek watching, is that the only rule is, "Will it make a good story?" If it will, it's allowed (although usually only for an episode or so, because we viewers have such short and immature attention spans

), and if it doesn't, it isn't.
The in-universe rule is that there don't seem to be any rules - at least not really strict ones. People in the command structure seem to generally hold back, but there are notable exceptions, of course.
This is one of my biggest Trek peeves, in fact. I know it's fiction, I know such a thing as Starfleet doesn't exist, but why not have at least some rules to give this fictional world a much-needed dose of reality? Because the plain fact is that captains and first officers, at the minimum, should not be involved with someone under their command. Humans may, I supposed, eventually evolve beyond the need for such a rule, but it's going to take a lot longer than 300 or 400 years, I can promise you that.