I suspect the search is legal. Not sure about insisting the captain stay on the flight deck.
The last time I was in Russia, on a 45 minute turnround at a remote stand, our passports were taken away, and an armed guard prevented me from coming down the stairs to supervise the refuel and do the walkround. Only when a superior officer reappeared was I allowed off. No, not in the Soviet era (2004)