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: bootstrap: ssh key of the init node is duplicated in the authorized_keys files of other node (bsc#1218940) #1311

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,8 +1829,9 @@ def swap_public_ssh_key(

if add:
public_key = generate_ssh_key_pair_on_remote(local_sudoer, remote_node, remote_sudoer, remote_user_to_swap)
_, _, local_authorized_file = key_files(local_user_to_swap).values()
sh.LocalShell().get_stdout_or_raise_error(local_user_to_swap, "sed -i '$a {}' '{}'".format(public_key, local_authorized_file))
ssh_key.AuthorizedKeyManager(sh.SSHShell(sh.LocalShell(), local_user_to_swap)).add(
None, local_user_to_swap, ssh_key.InMemoryPublicKey(public_key),
)
return public_key
else:
try:
Expand Down
2 changes: 1 addition & 1 deletion crmsh/ssh_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _add_by_editing_file(cls, user: str, key: Key):
public_key = key.public_key()
dir = f'~{user}/.ssh'
file = f'{dir}/authorized_keys'
cmd = f'''if ! grep '{public_key}' {file} > /dev/null; then
cmd = f'''if ! grep -F '{public_key}' {file} > /dev/null; then
if [ -s {file} ]; then
sed -i '$a {public_key}' {file}
else
Expand Down