Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crmsh-4.6] Fix: sh: guide users to setup key-based ssh authentication when non-interactive authentcation fails (bsc#1219045) #1309

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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():

Check warning on line 61 in crmsh/sh.py

View check run for this annotation

Codecov / codecov/patch

crmsh/sh.py#L60-L61

Added lines #L60 - L61 were not covered by tests
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()

Check warning on line 66 in crmsh/sh.py

View check run for this annotation

Codecov / codecov/patch

crmsh/sh.py#L66

Added line #L66 was not covered by tests


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"'

Check warning on line 74 in crmsh/sh.py

View check run for this annotation

Codecov / codecov/patch

crmsh/sh.py#L72-L74

Added lines #L72 - L74 were not covered by tests


class CommandFailure(Error):
Expand Down Expand Up @@ -335,7 +342,7 @@
**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())

Check warning on line 345 in crmsh/sh.py

View check run for this annotation

Codecov / codecov/patch

crmsh/sh.py#L345

Added line #L345 was not covered by tests
else:
return result

Expand Down