diff --git a/infrastructure/networking/rosenpass/README.md b/infrastructure/networking/rosenpass/README.md index c7443ca..e9f069a 100644 --- a/infrastructure/networking/rosenpass/README.md +++ b/infrastructure/networking/rosenpass/README.md @@ -83,6 +83,59 @@ it after the `values.yaml` change is reconciled). (age > 900 s for 10 m), both `severity: warning`, both with `absent()` guards so a missing series alerts instead of reading as healthy. +`RosenpassPskRotationStalled` keys on `(node, interface)`, so it covers Link B +(`interface="wg-remote"`) as soon as that series exists — no rule change needed. +The `absent()` arms still name `wg0` only, so a *disappeared* `wg-remote` series +is currently silent; adding that arm plus a metric for the UPnP mapping below is +the remaining gap. + +## Link B (rpi wg-remote ↔ linode wg0) + +Link B is the second transport link: rpi `wg-remote` `10.20.0.2` ↔ linode `wg0` +`10.20.0.1`, the exchange on UDP 9999 across the public internet. Two facts make +it fragile in ways Link A is not: + +- **The Pi's inbound path is a UPnP mapping**, because the home router has no + accessible admin panel. `rosenpass-upnp.sh` re-asserts + `UDP 9999 -> 192.168.1.125:9999 'rosenpass-pq'` with a permanent lease every + 15 minutes, logs to `logger -t rosenpass-upnp` and exits non-zero when the + mapping cannot be restored. Install: + + ```sh + install -m 0755 rosenpass-upnp.sh /usr/local/sbin/ + install -m 0644 rosenpass-upnp.service rosenpass-upnp.timer /etc/systemd/system/ + systemctl daemon-reload && systemctl enable --now rosenpass-upnp.timer + upnpc -l | grep 9999 # 9999->192.168.1.125:9999, lease 0 + ``` + +- **The linode's peer block needs the Pi's public address, which is residential + DHCP.** Chosen strategy: a **documented static endpoint, no sync timer** — + proved from the router itself: `upnpc -s` reports the WAN connection + `Connected, uptime=…` with `Time started : Thu Sep 10 16:38:13 2026` and + `ExternalIPAddress = 137.118.156.124`, i.e. ~83 days on the address that is + configured, and three independent echo services agreed (2026-12-03). If the + address moves the exchange stops and the link keeps its last PSK — which is + what `rosenpass_psk_rotation_age_seconds{interface="wg-remote"}` catches. + Re-point by editing `endpoint = ":9999"` in the linode's + `/etc/rosenpass/config.toml` and `systemctl restart rosenpass` there (both + ends do not need restarting; the Pi dials `50.116.38.217:9999`). + +Rollout order that cannot strand the far end: this link carries the only SSH path +to the linode, so `/root/rosenpass-linkb-rollback.sh` +(`linkb-rollback-rpi.sh`, `linkb-rollback-linode.sh`) is staged on **both** hosts +and armed as a transient `systemd-run --on-active=420s` timer *before* the +linode's unit starts, self-cancelling via `/run/rosenpass-linkb-ok`. It restores +the Pi's Link A-only `/etc/rosenpass/config.toml.pre-linkb` and the static +`PresharedKey`s from the untouched `/etc/wireguard/*.conf` with `wg syncconf`. +The Linode end is restored by `wg syncconf wg0` from its own conf, so the hub's +client peers keep working. + +Verify both ends agree and the key rotates, without printing key material (run +as root on the Pi): `linkb-verify.sh` — it hashes each end's PSK, compares them, +and prints the Link A sentinel so a scoped rotation is distinguishable from an +interface-wide one. Expect a changed digest 180 s apart with `agree` on both +samples. + ## Testing the rules without merging `kustomize build monitoring/controllers/home` proves the rule renders; these two diff --git a/infrastructure/networking/rosenpass/linkb-rollback-linode.sh b/infrastructure/networking/rosenpass/linkb-rollback-linode.sh new file mode 100755 index 0000000..60aca1f --- /dev/null +++ b/infrastructure/networking/rosenpass/linkb-rollback-linode.sh @@ -0,0 +1,40 @@ +#!/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)" diff --git a/infrastructure/networking/rosenpass/linkb-rollback-rpi.sh b/infrastructure/networking/rosenpass/linkb-rollback-rpi.sh new file mode 100755 index 0000000..31d6d44 --- /dev/null +++ b/infrastructure/networking/rosenpass/linkb-rollback-rpi.sh @@ -0,0 +1,54 @@ +#!/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)" diff --git a/infrastructure/networking/rosenpass/linkb-verify.sh b/infrastructure/networking/rosenpass/linkb-verify.sh new file mode 100755 index 0000000..5d8973c --- /dev/null +++ b/infrastructure/networking/rosenpass/linkb-verify.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Sample Link B PSK hashes on both ends. Prints no key material: the preshared +# key line is filtered on each host and only its SHA-256 (first 16 hex) leaves. +set -u +LINKB_LINODE='/2Y0XpJYd9Vl9Al6zNAlQimEYA+xY9Y5PO6nUDkfKEA=' # linode wg0 pub (peer on the Pi) +LINKB_RPI='h1v1Rhrnq2N2kt454xQamL1Y1x0TaICa1zoKgyZHpkM=' # rpi wg-remote pub (peer on the linode) +LINKA='+e50qTPdZiyxMtYHRSdGILIrh06JflFQq5+TZRjVyic=' # siriussec (Link A sentinel) + +h() { tr -d '\n' | sha256sum | cut -c1-16; } + +ts=$(date -u +%FT%TZ) + +pi_linkb=$(wg show wg-remote preshared-keys 2>/dev/null | grep -F "$LINKB_LINODE" | awk '{print $2}' | h) +pi_linka=$(wg show wg0 preshared-keys 2>/dev/null | grep -F "$LINKA" | awk '{print $2}' | h) + +ln_linkb=$(ssh -n -i /home/sirius/.ssh/linode_admin -o BatchMode=yes -o ConnectTimeout=10 root@10.20.0.1 \ + "wg show wg0 preshared-keys | grep -F '$LINKB_RPI' | awk '{print \$2}'" | h) + +pi_hs=$(wg show wg-remote latest-handshakes 2>/dev/null | grep -F "$LINKB_LINODE" | awk '{print $2}') +ln_hs=$(ssh -n -i /home/sirius/.ssh/linode_admin -o BatchMode=yes -o ConnectTimeout=10 root@10.20.0.1 \ + "wg show wg0 latest-handshakes | grep -F '$LINKB_RPI' | awk '{print \$2}'") + +agree="MISMATCH" +[ "$pi_linkb" = "$ln_linkb" ] && agree="agree" +printf '%s linkB pi=%s linode=%s %s | linkA(pi)=%s | hs pi=%s linode=%s\n' \ + "$ts" "$pi_linkb" "$ln_linkb" "$agree" "$pi_linka" "$pi_hs" "$ln_hs" diff --git a/infrastructure/networking/rosenpass/rosenpass-upnp.service b/infrastructure/networking/rosenpass/rosenpass-upnp.service new file mode 100644 index 0000000..e1675b2 --- /dev/null +++ b/infrastructure/networking/rosenpass/rosenpass-upnp.service @@ -0,0 +1,13 @@ +[Unit] +Description=Re-assert UPnP mapping for Rosenpass Link B (UDP 9999 -> rpi) +Documentation=https://github.com/rosenpass/rosenpass +After=network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/rosenpass-upnp.sh +# A router reboot drops the mapping; retry a few times before giving up so a +# transient WAN/IGD hiccup does not page anyone. +Restart=on-failure +RestartSec=30s diff --git a/infrastructure/networking/rosenpass/rosenpass-upnp.sh b/infrastructure/networking/rosenpass/rosenpass-upnp.sh new file mode 100755 index 0000000..6f74e27 --- /dev/null +++ b/infrastructure/networking/rosenpass/rosenpass-upnp.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# rosenpass-upnp.sh - re-assert the permanent UPnP mapping that gives the +# Linode a way back to Rosenpass on the Pi (UDP 9999 -> 192.168.1.125:9999). +# +# The home router's admin panel is inaccessible, so this mapping is the ONLY +# inbound path for the Rosenpass exchange on Link B (rpi wg-remote <-> +# linode wg0). It is runtime state: a router reboot, a factory reset or a UPnP +# daemon hiccup drops it, and the failure is silent - the link keeps its last +# PSK and simply stops being post-quantum. Hence this timer. +# +# Idempotent: re-adding an identical permanent-lease mapping is a no-op, so it +# is safe to run on a schedule. Never prints key material (it handles none). +set -uo pipefail + +LAN_IP=192.168.1.125 +PORT=9999 +DESC=rosenpass-pq + +out=$(upnpc -e "$DESC" -a "$LAN_IP" "$PORT" "$PORT" UDP 0 2>&1) || true + +# upnpc prints the mapping as " 0 UDP 9999->192.168.1.125:9999 'rosenpass-pq'" +if ! upnpc -l 2>/dev/null | grep -q "${PORT}->${LAN_IP}:${PORT}"; then + logger -t rosenpass-upnp "mapping missing after re-assert: ${out}" + exit 1 +fi diff --git a/infrastructure/networking/rosenpass/rosenpass-upnp.timer b/infrastructure/networking/rosenpass/rosenpass-upnp.timer new file mode 100644 index 0000000..4fbcc35 --- /dev/null +++ b/infrastructure/networking/rosenpass/rosenpass-upnp.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Re-assert the Rosenpass Link B UPnP mapping every 15 minutes + +[Timer] +OnBootSec=2min +OnUnitActiveSec=15min +AccuracySec=30s +Unit=rosenpass-upnp.service + +[Install] +WantedBy=timers.target