Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/test/sshd-keepalive-scripts.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 9 set -u 10 INFRA=$(cd "$(dirname "$0")/.." && pwd) 11 docker run --rm --cpuset-cpus 12-14 -v "$INFRA:/infra:ro" ubuntu:26.04 bash -c ' 12 set -u 13 pass=0; fail=0 14 ok() { pass=$((pass+1)); echo "PASS $*"; } 15 bad() { fail=$((fail+1)); echo "FAIL $*"; } 16 export DEBIAN_FRONTEND=noninteractive 17 apt-get -qq update >/dev/null && apt-get -qq install -y openssh-server >/dev/null 2>&1 || { echo "apt failed"; exit 2; } 18 mkdir -p /run/sshd; ssh-keygen -A >/dev/null 19 echo "sshd: $(sshd -V 2>&1 | head -n 1)" 20 ka() { sshd -T 2>/dev/null | grep -E "^clientalive(interval|countmax) " | sort | tr "\n" " "; } 21 fsum() { (cd /etc/ssh && find . -type f | sort | xargs sha256sum); } 22 fsum > /root/before.sum; before=$(ka) 23 [ "$before" = "clientalivecountmax 3 clientaliveinterval 0 " ] && ok "before: $before" || bad "before: $before" 24 SSHD_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)" 26 SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-apply.sh /infra 2>/dev/null && bad "second apply accepted" || ok "second apply refused" 27 SSHD_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)" 29 fsum > /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 31 mkdir -p /root/bad/hub; printf "ClientAliveInterval fifteen\n" > /root/bad/hub/sshd-forward-keepalive.conf 32 SSHD_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" 34 SSHD_RELOAD=true bash /infra/hub/sshd-keepalive-rollback.sh 2>/dev/null && bad "rollback with nothing installed accepted" || ok "rollback with nothing installed refused" 35 SSHD_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)" 37 SSHD_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)" 39 echo "sshd-keepalive-scripts: $pass passed, $fail failed" 40 [ "$fail" = 0 ]'