interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / test / sshd-keepalive-scripts.sh

40 lines · 3600 bytes Raw Blame History
1#!/usr/bin/env bash
2# Rehearsal of hub/sshd-keepalive-apply.sh and hub/sshd-keepalive-rollback.sh in an ubuntu:26.04
3# container with Ubuntu's openssh-server (no systemd there, so SSHD_RELOAD=true; the live hub reloads
4# ssh.service). Checks: apply changes `sshd -T` from 0/3 to 15/4; a second apply is refused; a broken
5# drop-in is caught by `sshd -t` and removed again; rollback returns `sshd -T` to 0/3 and leaves
6# /etc/ssh byte-identical to before; a failed reload removes the drop-in and leaves `sshd -T`
7# unchanged; a drop-in sshd does not read is removed and ssh is reloaded back.
8# bash infra/test/sshd-keepalive-scripts.sh
9set -u
10INFRA=$(cd "$(dirname "$0")/.." && pwd)
11docker run --rm --cpuset-cpus 12-14 -v "$INFRA:/infra:ro" ubuntu:26.04 bash -c '
12set -u
13pass=0; fail=0
14ok() { pass=$((pass+1)); echo "PASS $*"; }
15bad() { fail=$((fail+1)); echo "FAIL $*"; }
16export DEBIAN_FRONTEND=noninteractive
17apt-get -qq update >/dev/null && apt-get -qq install -y openssh-server >/dev/null 2>&1 || { echo "apt failed"; exit 2; }
18mkdir -p /run/sshd; ssh-keygen -A >/dev/null
19echo "sshd: $(sshd -V 2>&1 | head -n 1)"
20ka() { sshd -T 2>/dev/null | grep -E "^clientalive(interval|countmax) " | sort | tr "\n" " "; }
21fsum() { (cd /etc/ssh && find . -type f | sort | xargs sha256sum); }
22fsum > /root/before.sum; before=$(ka)
23[ "$before" = "clientalivecountmax 3 clientaliveinterval 0 " ] && ok "before: $before" || bad "before: $before"
24SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-apply.sh /infra && ok "apply rc 0" || bad "apply rc $?"
25[ "$(ka)" = "clientalivecountmax 4 clientaliveinterval 15 " ] && ok "after apply: $(ka)" || bad "after apply: $(ka)"
26SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-apply.sh /infra 2>/dev/null && bad "second apply accepted" || ok "second apply refused"
27SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-rollback.sh && ok "rollback rc 0" || bad "rollback rc $?"
28[ "$(ka)" = "$before" ] && ok "after rollback: $(ka)" || bad "after rollback: $(ka)"
29fsum > /root/after.sum; cmp -s /root/before.sum /root/after.sum && ok "/etc/ssh files byte-identical after rollback ($(wc -l < /root/after.sum) files)" || bad "/etc/ssh files differ after rollback"
30# broken drop-in: sshd -t must catch it and the file must be gone again
31mkdir -p /root/bad/hub; printf "ClientAliveInterval fifteen\n" > /root/bad/hub/sshd-forward-keepalive.conf
32SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-apply.sh /root/bad 2>&1 | tail -n 1
33[ ! -e /etc/ssh/sshd_config.d/40-forward-keepalive.conf ] && [ "$(ka)" = "$before" ] && ok "broken drop-in rejected and removed" || bad "broken drop-in left behind"
34SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-rollback.sh 2>/dev/null && bad "rollback with nothing installed accepted" || ok "rollback with nothing installed refused"
35SSHD_RELOAD=false bash /infra/hub/sshd-keepalive-apply.sh /infra >/tmp/ka-reload.out 2>&1; rc=$?
36[ "$rc" != 0 ] && [ ! -e /etc/ssh/sshd_config.d/40-forward-keepalive.conf ] && [ "$(ka)" = "$before" ] && ok "reload failure removed the drop-in and left sshd -T unchanged" || bad "reload failure rc $rc ka $(ka) $(tail -n 1 /tmp/ka-reload.out)"
37SSHD_DROPIN=/tmp/not-included.conf SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-apply.sh /infra >/tmp/ka-mismatch.out 2>&1; rc=$?
38[ "$rc" != 0 ] && [ ! -e /tmp/not-included.conf ] && [ "$(ka)" = "$before" ] && grep -q "drop-in removed, ssh reloaded" /tmp/ka-mismatch.out && ok "sshd -T mismatch removed the drop-in and reloaded back" || bad "sshd -T mismatch rc $rc $(tail -n 1 /tmp/ka-mismatch.out)"
39echo "sshd-keepalive-scripts: $pass passed, $fail failed"
40[ "$fail" = 0 ]'