yours, mine and almost anyone's initial contact with law enforcement is usually under what is knowns as "reasonable suspicion." Authority can stop you and ask quesiton based on practically no suspicious activity at all.
The Coastie's authority to seach you vessel for limited reasons is allowed, even though it seems to violate the constitution, because the courts have found that your rights are subject to rights of others to be free from a danger that might be caused by you. They can do so in a way that is narrowly tailored to resolve certain court recognized things, like the presence of safety equipment.
Neither the coast guard nor anyone else, can thoroughly search every compartment in a boat without "probably cause." Normally the law requires probable cause plus an exigent circumstance to conduct a search or arrest. But the courts have ruled as a practical matter the portability of boats, airplanes and automobiles is iteself an exigent circumstance.
So, authorities can board your boat to search for safety gear, to review your identification, and to inquire as to your intentions simply because your boat is a boat. Then, once there, if they reasonably believe a weapon is or could be present and that you or someone else on your boat poses a danger, they can search compartments which are reasonably in your or your passengers' reach and that could reasonably contain a dangerous weapon. For example, after the satisfactory completion of a normal safety and environmental inspection, they could handcuff you and seach all nearby lockers and cubbyholes. If they found a matchbox, however, they could not open it without probable cause as it is not large enough to hide a weapon.
This is of course, the theory of the law. In practice, few sailors are handcuffed and their immediate surroundings searched. But you see how easy it is on the part of hte authorities to do so. By the way these are the same rules as those applied to automobile stops.
Some additional points to remember are taht they cannot keep you longer than is resonable to accomplish their goal. They cannot keep you for an hour while they wait for a drug sniffing dog, but if one is readily available without an unreasonable wait, you can get sniffed.
all of this law predates Bush 1 and 2, and Bill and Hillary Rhodam (her name is not nor was it ever Clinton.)
Lastly, if your boat is documented, the Gov't can even confiscate it for the public use. That was the original purpose of documentation.