homek8s/infrastructure/networking/rosenpass/linkb-rollback-linode.sh

40 lines
1.5 KiB
Shell
Raw Permalink Normal View History

#!/bin/bash
# Self-cancelling rollback for the Link B rollout, Linode end (wg0 hub).
#
# Armed as a transient `systemd-run --on-active=420s` timer on the Linode before
# rosenpass is started there. It acts locally, because the only SSH path to this
# host runs over the tunnel a PSK mismatch would break.
#
# Cancelled by touching /run/rosenpass-linkb-ok on this host once rotation and
# the cluster are verified.
#
# What it restores: the static PresharedKeys of every peer in
# /etc/wireguard/wg0.conf, and stops/disables the rosenpass unit. It never
# brings the interface down.
set -u
log() { logger -t rosenpass-linkb "$*"; echo "$*"; }
# Self-cancel: the operator touches this flag after verification, so this script
# is a no-op if the run actually succeeded.
if [ -f /run/rosenpass-linkb-ok ]; then
log "watchdog fired but /run/rosenpass-linkb-ok exists - no action taken"
exit 0
fi
log "ROLLBACK triggered: Link B did not verify within the watchdog window"
systemctl disable --now rosenpass.service || log "warn: disable --now rosenpass failed"
if wg-quick strip wg0 > /run/wg0.rollback.stripped 2>/dev/null; then
if wg syncconf wg0 /run/wg0.rollback.stripped; then
log "wg0 synced from conf: static PresharedKeys restored for all peers"
else
log "ERROR: wg syncconf wg0 failed; live PSKs unchanged"
fi
else
log "ERROR: wg-quick strip wg0 failed; live PSKs unchanged"
fi
rm -f /run/wg0.rollback.stripped
log "ROLLBACK done - verify: wg show wg0 latest-handshakes (rpi peer < 180 s)"