You’ve probably seen it many a time in any movie featuring vessels of any kind. Before coming aboard said vessel the person wanting to come aboard asks for permission from the commanding officer/captain/pirate with the biggest cutlass. It’s not just a movie line, it’s real life.
Boat owners tend to be a bit overly protective of their vessels. They have put a lot of time, effort, and money into keeping it afloat. Like anyone who owns land, a boat owner is very particular about who may or may not come aboard their vessel. So, as a courtesy, and to keep one’s head attached to one’s shoulders, anyone who has any sense of self preservation will indeed, ask permission before setting foot on a vessel. To board without permission could be construed as an act of piracy, punishable by bullet between the eyes if one is not careful. It is assumed that if you come aboard without permission, it is your intent to steal said vessel, do bodily harm to captain and crew, or otherwise be looking for trouble. And if you do come aboard without permission, you deserve whatever harm befalls you.
I’m not totally up on how the laws of the sea or land come into play with something like this. I do know that any and all law enforcement reserves the right to board any vessel at anytime they see fit for any reason. The smart law enforcement, unless they are doing a surprise raid in full knowledge of what is aboard, will announce their identity and intentions before stepping foot on any vessel. To not warn the captain and crew ahead of time could well result in some extreme unpleasantness for all parties involved. (One of the first things you will be asked when being boarded is if you have any weapons on board. Best to say yes if you do, let them know where the weapons are, and everything will be fine.)
So anytime you happen to come around any boat, no matter the size, shape, or location, always ask for permission to board. Or learn to duck and run.