Skip to content

Commit

Permalink
Fix: sh: guide users to setup key-based ssh authentication when
Browse files Browse the repository at this point in the history
non-interactive authentcation fails (bsc#1219045)
  • Loading branch information
nicholasyang2022 committed Jan 22, 2024
1 parent 1eb5327 commit 03a9250
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions crmsh/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,22 @@ def __init__(self, cmd: str, host: typing.Optional[str], user: str, msg: str):
self.host = host
self.user = user

@staticmethod
def diagnose() -> str:
if user_of_host.instance().use_ssh_agent():
with StringIO() as buf:
def diagnose(self) -> str:
with StringIO() as buf:
if user_of_host.instance().use_ssh_agent():
if 'SSH_AUTH_SOCK' not in os.environ:
buf.write('Environment variable SSH_AUTH_SOCK does not exist.')
if 'SUDO_USER' in os.environ:
buf.write(' Please check whether ssh-agent is available and consider using "sudo --preserve-env=SSH_AUTH_SOCK".')
return buf.getvalue()
return buf.getvalue()


class NonInteractiveSSHAuthorizationError(AuthorizationError):

def diagnose(self) -> str:
ret = super().diagnose()
if not ret:
return 'Please configure passwordless authentication with "crm cluster init ssh" and "crm cluster join ssh"'


class CommandFailure(Error):
Expand Down Expand Up @@ -335,7 +342,7 @@ def subprocess_run_without_input(self, host: typing.Optional[str], user: typing.
**kwargs,
)
if self.raise_ssh_error and result.returncode == 255:
raise AuthorizationError(cmd, host, remote_user, Utils.decode_str(result.stderr).strip())
raise NonInteractiveSSHAuthorizationError(cmd, host, remote_user, Utils.decode_str(result.stderr).strip())
else:
return result

Expand Down

0 comments on commit 03a9250

Please sign in to comment.