dnd 5e – Can a charmed Beast Master ranger’s Primal Companion attack the charmer?

If a Beast Master ranger has a Primal Companion, and the ranger is charmed, can the charmed ranger instruct their Primal Companion to attack the charmer?

I ask this because the Primal Companion feature states that a ranger must use their bonus action (or one of their attacks) to have their Primal Companion take the Attack option. I believe that would count as a harmful effect against the charmer, so I’m wondering if that’s the correct interpretation.