This arrangement is called a "protectorate" and is used by small countries all around the world.
Some that come to mind immediately:
- Italy has Vatican City and San Marino
- France has Monaco and Andorra
- the USA has the Marshall Islands, Amerocan Samoa, and several other Pacfic islands- at one time even including the Phillipines
- the Uk has several former colonies that are now independent but still ask for British protection
- Russia has South Ossetia, Abkhazia, and several other disputed states. Apparently, Crimea just joined that list on Saturday, at least by its own rules.
Protectorates are recognized by international law and norms, and are thus as "legal" as anything in international law. Indeed, the fact that the UN recognizes this arrangement can be proven by the fact that East Timor (Timor-Leste) was itself a protectorate [under UN auspices from 1999 - 2002.