Merge pull request #3591 from palfrey/3590-ssh-key-without-newlines

Allow SSH keys with no ending newline
This commit is contained in:
Jose Diaz-Gonzalez
2019-06-14 12:59:02 -05:00
committed by GitHub
2 changed files with 9 additions and 1 deletions

View File

@@ -29,7 +29,8 @@ add_keys() {
fi
local count="$(wc -l "$KEY_FILE" | awk '{ print $1; }')"
[[ "$count" -eq 1 ]] || dokku_log_fail "Too many keys provided, set one per invocation of dokku ssh-keys:add <NAME> <KEY_FILE>"
# Don't check for "-eq 1" as no newlines is also a valid SSH key
[[ "$count" -lt 2 ]] || dokku_log_fail "Too many keys provided, set one per invocation of dokku ssh-keys:add <NAME> <KEY_FILE>"
ssh-keygen -lf "$KEY_FILE" &>/dev/null || dokku_log_fail "Key specified in is not a valid ssh public key"
create_ssh_key_file
verify_ssh_key_exists

View File

@@ -13,6 +13,9 @@ setup() {
# now create key that will be really used
create_key
# Test key without a trailing newline
echo -n "$KEY" > /tmp/testkey-no-newline.pub
# the temporary key is useful for adding in the file with two keys
# useful for a negative test
{ cat /tmp/testkey.pub ; echo "$KEY" ; } > /tmp/testkey-double.pub
@@ -70,6 +73,10 @@ teardown() {
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ssh-keys:add name5 /tmp/testkey-no-newline.pub"
echo "output: $output"
echo "status: $status"
assert_success
# leave this as the last test in the sequence! It introduces an error in authorized_keys
run /bin/bash -c 'echo invalid >> "${DOKKU_ROOT:-/home/dokku}/.ssh/authorized_keys"'