mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Previously, an empty line would result in a failing ssh-keys:list call, or a failure to verify the file. Newlines should be ignored.
38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
list_ssh_keys() {
|
|
declare desc="List ssh key hashes"
|
|
local cmd="ssh-keys:list"
|
|
verify_ssh_key_file
|
|
sshcommand list dokku
|
|
}
|
|
|
|
verify_ssh_key_file() {
|
|
declare desc="Test that public key is valid"
|
|
[[ -s ${DOKKU_ROOT}/.ssh/authorized_keys ]] || dokku_log_fail "No public keys found."
|
|
local key line=0
|
|
local TMP_KEY_FILE
|
|
TMP_KEY_FILE=$(mktemp "/tmp/dokku-${FUNCNAME[0]}.XXXX")
|
|
trap "rm -rf '$TMP_KEY_FILE' >/dev/null" RETURN INT TERM EXIT
|
|
|
|
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"
|
|
}
|
|
|
|
verify_ssh_key_exists() {
|
|
declare desc="Test that public key exists"
|
|
[[ -e ${DOKKU_ROOT}/.ssh/authorized_keys ]] || dokku_log_fail "No public keys found."
|
|
}
|
|
|
|
create_ssh_key_file() {
|
|
declare desc="Ensure the public key file exists"
|
|
touch "${DOKKU_ROOT}/.ssh/authorized_keys"
|
|
}
|