It's in the contract
(c) Guest agrees Carnival has, at all times with or without notice, the right to enter and search Guest’s stateroom, personal safe or storage spaces, or to search or screen any Guest, and/or personal effects, at any location, to ensure compliance with any of the restrictions set forth in this agreement. Any Guest who refuses any such search or screening may be denied boarding or disembarked and no refund of the cruise fare will be issued.