Not sure if your dealing with factory or aftermarket, but the theory is the same either way.

If all is quiet with the roof closed then you know the tension imparted by the latches are holding it all secure, noisy when open, there is no tension on the flange and it is likely moving about a wee bit.
Check all the mounting hardware, something has to be loose/broken to allow movement.

Some people will use caulking/silicone to seal/glue it, while praying to the Goop gods.
But that option is rarely successful, YMMV.