summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-07-12 18:33:22 +0100
committerGitHub <noreply@github.com>2024-07-12 18:33:22 +0100
commit10aa89ddb0d36dae87ba098ee9b52ebe981ce7f5 (patch)
tree0ebad9c41c07f242d70a4b4551d9b195b7d391bb
parent77862f882245a62efef6095e2739d6edfb91d674 (diff)
parentd5b2df9ee794feeaf2f606448cb8497f0508f98e (diff)
downloadvyos-cloud-init-10aa89ddb0d36dae87ba098ee9b52ebe981ce7f5.tar.gz
vyos-cloud-init-10aa89ddb0d36dae87ba098ee9b52ebe981ce7f5.zip
Merge pull request #79 from vyos/mergify/bp/circinus/pr-78
SSH KEY: T6568: Fixed adding SSH keys with same comments (backport #78)
-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: