From ecd114ca5a79473e38e303dcaea9ba3f27862b0b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 3 Mar 2022 12:34:37 -0500 Subject: [PATCH] Add script for setting up ssh A frequent scenario is to 'refresh' ssh configuration toward the end of: -changing trust nodes -Adding a collective member -Repairing a broken configuration -As part of 'confluent-ifying' a node that wasn't confluent deployed --- misc/setupssh.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 misc/setupssh.sh diff --git a/misc/setupssh.sh b/misc/setupssh.sh new file mode 100644 index 00000000..7ac31040 --- /dev/null +++ b/misc/setupssh.sh @@ -0,0 +1,32 @@ +[ -f /lib/confluent/functions ] && . /lib/confluent/functions +[ -f /etc/confluent/functions ] && . /etc/confluent/functions +[ -f /opt/confluent/bin/apiclient ] && confapiclient=/opt/confluent/bin/apiclient +[ -f /etc/confluent/apiclient ] && confapiclient=/etc/confluent/apiclient +nodename=$(grep ^NODENAME: /etc/confluent.info|awk '{print $NF}') +for pubkey in /etc/ssh/ssh_host*key.pub; do + certfile=${pubkey/.pub/-cert.pub} + rm $certfile + confluentpython $confapiclient /confluent-api/self/sshcert $pubkey -o $certfile +done +TMPDIR=$(mktemp -d) +cd $TMPDIR +confluentpython $confapiclient /confluent-public/site/initramfs.tgz -o initramfs.tgz +tar xf initramfs.tgz +for ca in ssh/*.ca; do + LINE=$(cat $ca) + cp -af /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts.new + grep -v "$LINE" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.new + echo '@cert-authority *' $LINE >> /etc/ssh/ssh_known_hosts.new + mv /etc/ssh/ssh_known_hosts.new /etc/ssh/ssh_known_hosts +done +for pubkey in ssh/*.*pubkey; do + LINE=$(cat $pubkey) + cp -af /root/.ssh/authorized_keys /root/.ssh/authorized_keys.new + grep -v "$LINE" /root/.ssh/authorized_keys > /root/.ssh/authorized_keys.new + echo "$LINE" >> /root/.ssh/authorized_keys.new + mv /root/.ssh/authorized_keys.new /root/.ssh/authorized_keys +done +confluentpython $confapiclient /confluent-api/self/nodelist | sed -e 's/^- //' > /etc/ssh/shosts.equiv +cat /etc/ssh/shosts.equiv > /root/.shosts +cd - +rm -rf $TMPDIR