homek8s/infrastructure/networking/rosenpass/linkb-rollback-rpi.sh
Lance Walters 5fc7cd4ead docs(rosenpass): commit the Link B host artifacts and the endpoint decision
Link B (rpi wg-remote 10.20.0.2 <-> linode wg0 10.20.0.1) is now under
Rosenpass too. The pieces that only existed on the hosts are committed
here with an install/diagnosis write-up, because all three are runtime
state someone will have to rebuild:

- rosenpass-upnp.{sh,service,timer} - re-assert the permanent UPnP mapping
  UDP 9999 -> 192.168.1.125 every 15 min (the router has no admin panel,
  and a dropped mapping is silent).
- linkb-rollback-{rpi,linode}.sh - the self-cancelling watchdogs; this link
  carries the only SSH path to the linode, so the rollback is local and
  staged on both ends before the far unit starts.
- linkb-verify.sh - hashes each end's PSK and compares them without
  printing key material.

Endpoint strategy recorded: the Pi's public address is residential DHCP
but provably static (IGD uptime since 2026-09-10, ~83 days on the
configured 137.118.156.124), so the linode config pins it and a moved
address is caught by the per-interface rotation-age series rather than by
a sync timer.
2026-12-03 02:46:10 -05:00

54 lines
2.3 KiB
Shell
Executable file

#!/bin/bash
# Self-cancelling rollback for the Link B rollout (rpi wg-remote <-> linode wg0).
#
# Armed as a transient `systemd-run --on-active=420s` timer before rosenpass is
# started on the Linode. It must live on THIS host and act locally: a PSK
# mismatch on Link B kills the WireGuard tunnel, and that tunnel is the only SSH
# path to the far end, so no remote rollback can be delivered over it.
#
# Cancelled by touching /run/rosenpass-linkb-ok (checked by the timer unit's
# command, not here) once rotation and the cluster are verified.
#
# What it restores:
# 1. the pre-rollout rosenpass config (Link A peer only - Link A keeps working)
# 2. the static PresharedKey on the wg-remote peer, from /etc/wireguard/wg-remote.conf
#
# Never touches wg0 (Link A) or any client peer.
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"
# 1. Stop rosenpass first, so it cannot re-inject a rotating PSK mid-restore.
systemctl disable --now rosenpass.service || log "warn: disable --now rosenpass failed"
# 2. Put the Link A-only config back and bring Link A's rotation back up.
if [ -f /etc/rosenpass/config.toml.pre-linkb ]; then
cp -a /etc/rosenpass/config.toml.pre-linkb /etc/rosenpass/config.toml
log "restored /etc/rosenpass/config.toml from config.toml.pre-linkb"
else
log "warn: /etc/rosenpass/config.toml.pre-linkb missing; config left as-is"
fi
systemctl enable --now rosenpass.service || log "warn: restarting rosenpass failed"
# 3. Restore the static PSK on wg-remote from the conf (the rollback floor).
if wg-quick strip wg-remote > /run/wg-remote.rollback.stripped 2>/dev/null; then
if wg syncconf wg-remote /run/wg-remote.rollback.stripped; then
log "wg-remote synced from conf: static PresharedKey restored"
else
log "ERROR: wg syncconf wg-remote failed; live PSK unchanged"
fi
else
log "ERROR: wg-quick strip wg-remote failed; live PSK unchanged"
fi
rm -f /run/wg-remote.rollback.stripped
log "ROLLBACK done - verify: wg show wg-remote latest-handshakes (expect < 180 s)"