#!/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)"