Skip to content

Commit

Permalink
Dev: bootstrap: allow to authenticate interactively in `crm cluster j…
Browse files Browse the repository at this point in the history
…oin --use-ssh-agent`
  • Loading branch information
nicholasyang2022 committed Oct 31, 2023
1 parent 53f1cd3 commit 7890220
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,15 +1788,16 @@ def join_ssh_with_ssh_agent(
):
# As ssh-agent is used, the local_user does not have any effects
shell = sh.SSHShell(local_shell, 'root')
authorized_key_manager = ssh_key.AuthorizedKeyManager(shell)
if not shell.can_run_as(seed_host, seed_user):
raise ValueError(f'Failed to login to {seed_user}@{seed_host}')
for key in ssh_public_keys:
authorized_key_manager.add(seed_host, seed_user, key)
if seed_user != 'root' and 0 != shell.subprocess_run_without_input(
seed_host, seed_user, 'sudo true',
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode:
raise ValueError(f'Failed to sudo on {seed_user}@{seed_host}')
authorized_key_manager = ssh_key.AuthorizedKeyManager(shell)
for key in ssh_public_keys:
authorized_key_manager.add(None, local_user, key)

Expand Down

0 comments on commit 7890220

Please sign in to comment.