Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
kandra: Support installing multiple ssh keys from multiple secrets.
Alex Vandivera959f71208e7
diff --git a/puppet/kandra/files/install-ssh-keys b/puppet/kandra/files/install-ssh-keysindex a93fbccf46a..b7723f53a3b 100755--- a/puppet/kandra/files/install-ssh-keys+++ b/puppet/kandra/files/install-ssh-keys@@ -1,8 +1,24 @@#!/usr/bin/env bashset -euo pipefail+args="$(getopt -o '' --long check -- "$@")"+eval "set -- $args"+check=false+while true; do+ case "$1" in+ --check)+ check=true+ shift+ ;;+ --)+ shift+ break+ ;;+ esac+done+username="$1"-ssh_secret_name="$2"+shifthomedir="$(getent passwd "$username" | cut -d: -f6)"sshdir="$homedir/.ssh"@@ -15,20 +31,22 @@ trap cleanup EXITumask 033-keydata="$(/srv/zulip-aws-tools/bin/aws --output text \- secretsmanager get-secret-value \- --secret-id "$ssh_secret_name" \- --query SecretString)"-for keyfile in $(jq -r 'keys[]' <<<"$keydata"); do- touch "$workdir/$keyfile"- if [[ "$keyfile" != *".pub" ]]; then- chmod 600 "$workdir/$keyfile"- fi- jq -r ".[\"$keyfile\"]" <<<"$keydata" | base64 -d >"$workdir/$keyfile"- chown "$username:$username" "$workdir/$keyfile"+for ssh_secret_name in "$@"; do+ keydata="$(/srv/zulip-aws-tools/bin/aws --output text \+ secretsmanager get-secret-value \+ --secret-id "$ssh_secret_name" \+ --query SecretString)"+ for keyfile in $(jq -r 'keys[]' <<<"$keydata"); do+ touch "$workdir/$keyfile"+ if [[ "$keyfile" != *".pub" ]]; then+ chmod 600 "$workdir/$keyfile"+ fi+ jq -r ".[\"$keyfile\"]" <<<"$keydata" | base64 -d >"$workdir/$keyfile"+ chown "$username:$username" "$workdir/$keyfile"+ donedone-if [ "$#" -gt 2 ]; then+if [ "$check" = "true" ]; thendiff -rN -x config -x authorized_keys -x known_hosts \"$workdir/" "$sshdir/"exit 0diff --git a/puppet/kandra/manifests/ssh_keys.pp b/puppet/kandra/manifests/ssh_keys.ppindex 2318430e1f0..8e1697ea066 100644--- a/puppet/kandra/manifests/ssh_keys.pp+++ b/puppet/kandra/manifests/ssh_keys.pp@@ -4,12 +4,14 @@ define kandra::ssh_keys($user = $nameif $keys == true {$keypath = "prod/ssh/keys/${user}"+ } elsif $keys.is_a(Array) {+ $keypath = join($keys.map |$k| {"prod/ssh/keys/${k}"}, ' ')} else {$keypath = "prod/ssh/keys/${keys}"}exec { "ssh_keys ${user}":require => File['/usr/local/bin/install-ssh-keys'],command => "/usr/local/bin/install-ssh-keys ${user} ${keypath}",- unless => "[ -f /usr/local/bin/install-ssh-keys ] && /usr/local/bin/install-ssh-keys ${user} ${keypath} check",+ unless => "[ -f /usr/local/bin/install-ssh-keys ] && /usr/local/bin/install-ssh-keys --check ${user} ${keypath}",}}