Both. The order of ranks goes like so:
The Secret Rank is awarded after [SPOILERS] beating Primal Dialga, in a postgame mission where you rescue Scizor from Crevice Cave. He will bestow you with the Secret Rank.
Source: Experience (I've gotten Guildmaster in Sky) and [Bulbapedia.]
*Please note that the Master★, Master★★, Master★★★, and Guildmaster ranks are only available in Explorers of Sky.