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

Fix bug #283: Multiple keys are added to authorized_keys without line breaks #424

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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