I had a sunroof rattle that was driving me crazy until I finally figured it out.
Does your sunroof rattle go away when you have the sunroof in the open position (popped up, not slid open)? If so, then try this:
Open the sunroof all the way (slid open) and wipe out the channel where the seals on your sunroof rest against the paint. Clean it really good. Now wipe down the seal around the sunroof. You can clean the front edge while it's still slid open, but then you'll have to close it and pop it up to get to the sides & rear edge. Anyway, the point is to make sure you wipe it down all the way around. Once you do that, take some silicone spray on a rag and wipe down the entire seal again.
I did that more than a year ago and my rattle never returned. The whole time I thought part of the sunroof linkage or mechanism was causing my rattling noise, and it was just the seal that needed to be cleaned. If your problem is similar, give it a shot...it definitely worked for me.