Skip to content

Conversation

@blaisemGH
Copy link

Bug

While ssh-keygen creates public keys that end in a newline (which is used in current tests), sometimes this newline is lost, e.g., when the key is mounted by a configmap in k8s. In this scenario, the current implementation breaks the authorized_keys file, making sftp with subsequent public keys impossible.

Before

Multiple keys for a single host are merged into authorized_keys via cat and append, e.g., cat $keyFile >> authorized_keys. When a key does not have a trailing newline, the append concatenates the next key on the same line as the previous key, and the keys can no longer be parsed.

After

Using paste -d "\\n" -s inserts a newline between public keys if and only if the key is missing a trailing newline.

Example (pseudo code)

Before:

cat $keyFile1 >> authorized_keys.tmp
cat $keyFile2 >> authorized_keys.tmp
cat authorized_keys.tmp
<key1><key2>

After:

paste -d "\\n" -s "$keyDir"/* > authorized_keys.tmp
cat authorized_keys.tmp
<key1>
<key2>

@blaisemGH
Copy link
Author

blaisemGH commented Nov 29, 2024

Fix for issue #283. I didn't find the issue until after implementation, so there is already PR #289. I guess my PR adds a unit test. Would be fine with either one being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant