Fix bug #283: Multiple keys are added to authorized_keys without line breaks #424
+57
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
After: