summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2024-07-11 15:04:16 +0300
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-07-12 12:50:49 +0000
commit90271f46d0caf88a7d5cd9d3a72eb291b38d2d35 (patch)
treee01b74779291219777a0422cb57d2e69e10ff39b
parent61d7ba9ba122e1ca210f2a7f0524684a4040922d (diff)
downloadvyos-cloud-init-mergify/bp/sagitta/pr-78.tar.gz
vyos-cloud-init-mergify/bp/sagitta/pr-78.zip
SSH KEY: T6568: Fixed adding SSH keys with same commentsmergify/bp/sagitta/pr-78
If a key with the same comment already exists in a configuration, generate a new ID for a new one. Example of such a case: ``` ssh-rsa <base64> my_user_name ssh-ed25519 <base64> my_user_name ``` (cherry picked from commit c02b1151e584ea6c0bca35ba6aa87504566f6949)
-rw-r--r--cloudinit/config/cc_vyos.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py
index 9c9ac697..96324e4b 100644
--- a/cloudinit/config/cc_vyos.py
+++ b/cloudinit/config/cc_vyos.py
@@ -91,6 +91,11 @@ def set_ssh_login(config, user, key_string):
logger.info("Generating UUID for an SSH key because a comment is empty or unacceptable by CLI")
key_parsed.comment = "cloud-init-{}".format(uuid4())
+ # check if a key with the same comment already exists
+ if config.exists(['system', 'login', 'user', user, 'authentication', 'public-keys', key_parsed.comment]):
+ logger.debug("Generating UUID for an SSH key because a public key with comment {} already exists for user {}".format(key_parsed.comment, user))
+ key_parsed.comment = "cloud-init-{}".format(uuid4())
+
config.set(['system', 'login', 'user', user, 'authentication', 'public-keys', key_parsed.comment, 'key'], value=key_parsed.base64, replace=True)
config.set(['system', 'login', 'user', user, 'authentication', 'public-keys', key_parsed.comment, 'type'], value=key_parsed.keytype, replace=True)
if key_parsed.options: