use ssh certificates

Ricard Illa 2022-09-10 23:32:59 +02:00
parent f953c20d19
commit 22b987c57a
No known key found for this signature in database
GPG Key ID: F69A672B72E54902
1 changed files with 12 additions and 1 deletions

View File

@ -18,6 +18,8 @@ if [ -z "$SSH_KEY" ]; then
exit 1 exit 1
fi fi
SSH_KEY_CERT="${SSH_KEY_CERT:-${PLUGIN_KEY_CERT}}"
KNOWN_HOSTS="${KNOWN_HOSTS:=${PLUGIN_KNOWN_HOSTS}}" KNOWN_HOSTS="${KNOWN_HOSTS:=${PLUGIN_KNOWN_HOSTS}}"
SOURCES="${SOURCES:-${PLUGIN_SOURCES}}" SOURCES="${SOURCES:-${PLUGIN_SOURCES}}"
@ -38,10 +40,19 @@ ARGS=${ARGS:-${PLUGIN_ARGS}}
# prepare SSH # prepare SSH
mkdir -p "$HOME/.ssh" mkdir -p "$HOME/.ssh"
keyfile="$HOME/.ssh/id_rsa" keyfile="$HOME/.ssh/user_key"
echo "$SSH_KEY" > "$keyfile" echo "$SSH_KEY" > "$keyfile"
chmod 0600 "$keyfile" chmod 0600 "$keyfile"
echo 'Host *' > "$HOME/.ssh/config"
echo " IdentityFile $keyfile" >> "$HOME/.ssh/config"
if [ -n "${SSH_KEY_CERT}" ]; then
certfile="$HOME/.ssh/user_key-cert.pub"
echo "${SSH_KEY_CERT}" > "$certfile"
echo " CertificateFile $certfile" >> "$HOME/.ssh/config"
fi
known_hosts_file="${HOME}/.ssh/known_hosts" known_hosts_file="${HOME}/.ssh/known_hosts"
[ -n "${KNOWN_HOSTS}" ] && echo "${KNOWN_HOSTS}" >> "$known_hosts_file" [ -n "${KNOWN_HOSTS}" ] && echo "${KNOWN_HOSTS}" >> "$known_hosts_file"
[ -f "${known_hosts_file}" ] && chmod 0600 "$known_hosts_file" [ -f "${known_hosts_file}" ] && chmod 0600 "$known_hosts_file"