From 699719b600528799c33f61c15e4e964dc9cfe332 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 5 Jul 2019 10:00:52 -0400 Subject: [PATCH] fix: handle case where there are empty newlines in the authorized_keys file Previously, an empty line would result in a failing ssh-keys:list call, or a failure to verify the file. Newlines should be ignored. --- plugins/ssh-keys/functions | 1 + tests/unit/30_ssh_keys.bats | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/plugins/ssh-keys/functions b/plugins/ssh-keys/functions index 7368a2749..4569d9f1c 100755 --- a/plugins/ssh-keys/functions +++ b/plugins/ssh-keys/functions @@ -20,6 +20,7 @@ verify_ssh_key_file() { while read -r key; do line=$((line + 1)) + [[ -z "$key" ]] && continue echo "$key" >"$TMP_KEY_FILE" ssh-keygen -lf "$TMP_KEY_FILE" &>/dev/null || dokku_log_fail "${DOKKU_ROOT}/.ssh/authorized_keys line $line failed ssh-keygen check." done <"${DOKKU_ROOT}/.ssh/authorized_keys" diff --git a/tests/unit/30_ssh_keys.bats b/tests/unit/30_ssh_keys.bats index b024a9427..7c8274753 100644 --- a/tests/unit/30_ssh_keys.bats +++ b/tests/unit/30_ssh_keys.bats @@ -53,6 +53,10 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c 'echo "" >> "${DOKKU_ROOT:-/home/dokku}/.ssh/authorized_keys"' + echo "output: $output" + echo "status: $status" + assert_success run /bin/bash -c "dokku ssh-keys:list | grep name1" echo "output: $output" echo "status: $status"