Skip to content

Commit

Permalink
Fix: bootstrap: clear stall data about ssh users left possiblely from…
Browse files Browse the repository at this point in the history
… previous setups (bsc#1219476)

/root/.config/crm/crm.conf may contain `core.hosts` and
`core.no_generating_ssh_key` from previous cluster setup. They should be
clear on `crm cluster init` and `crm cluster join`.
  • Loading branch information
nicholasyang2022 committed Feb 5, 2024
1 parent 1d89c5b commit 4073436
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,10 @@ def init_ssh_impl(local_user: str, ssh_public_keys: typing.List[ssh_key.Key], us
change_user_shell('hacluster')

user_by_host = utils.HostUserConfig()
user_by_host.clear()
user_by_host.set_no_generating_ssh_key(bool(ssh_public_keys))
user_by_host.save_local()
# TODO: clean up user_by_host
if user_node_list:
print()
if ssh_public_keys:
Expand Down Expand Up @@ -1770,6 +1773,7 @@ def join_ssh_impl(local_user, seed_host, seed_user, ssh_public_keys: typing.List
),
)
user_by_host = utils.HostUserConfig()
user_by_host.clear()
user_by_host.add(seed_user, seed_host)
user_by_host.add(local_user, utils.this_node())
user_by_host.set_no_generating_ssh_key(bool(ssh_public_keys))
Expand Down Expand Up @@ -2958,6 +2962,7 @@ def bootstrap_arbitrator(context):
raise ValueError(f"Failed to login to {remote_user}@{node}. Please check the credentials.")
swap_public_ssh_key(node, local_user, remote_user, local_user, remote_user, add=True)
user_by_host = utils.HostUserConfig()
user_by_host.clear()
user_by_host.add(local_user, utils.this_node())
user_by_host.add(remote_user, node)
user_by_host.set_no_generating_ssh_key(context.use_ssh_agent)
Expand Down
4 changes: 4 additions & 0 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,10 @@ def save_remote(self, remote_hosts: typing.Iterable[str]):
'yes' if self._no_generating_ssh_key else 'no'
))

def clear(self):
self._hosts_users = dict()
self._no_generating_ssh_key = False

def get(self, host):
return self._hosts_users[host]

Expand Down

0 comments on commit 4073436

Please sign in to comment.