From a848d92823ffab898220045616f2d5529c967810 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Wed, 12 Jun 2019 22:16:02 +0100 Subject: [PATCH 1/2] Allow SSH keys with no ending newline (fixes #3590) --- plugins/ssh-keys/subcommands/add | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/ssh-keys/subcommands/add b/plugins/ssh-keys/subcommands/add index dd3ba7afc..b6fa76bce 100755 --- a/plugins/ssh-keys/subcommands/add +++ b/plugins/ssh-keys/subcommands/add @@ -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 " + # 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 " 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 From 024fd958e86430f4c5d35e42933d56dab7eb6134 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Wed, 12 Jun 2019 22:30:26 +0100 Subject: [PATCH 2/2] Add no-newline SSH key test --- tests/unit/30_ssh_keys.bats | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/30_ssh_keys.bats b/tests/unit/30_ssh_keys.bats index 3b23aefea..b024a9427 100644 --- a/tests/unit/30_ssh_keys.bats +++ b/tests/unit/30_ssh_keys.bats @@ -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"'