diff --git a/infrastructure/networking/rosenpass/README.md b/infrastructure/networking/rosenpass/README.md index e9f069a..6ccc5f0 100644 --- a/infrastructure/networking/rosenpass/README.md +++ b/infrastructure/networking/rosenpass/README.md @@ -44,6 +44,8 @@ Arch (siriussec). rosenpass_unit_active{node="rpi|siriussec"} 0|1 rosenpass_psk_rotation_age_seconds{node=...,interface="wg0|wg-remote"} rosenpass_psk_rotation_last_change_timestamp_seconds{node=...,interface="wg0|wg-remote"} +rosenpass_upnp_mapping_present{node="rpi"} 0|1 +rosenpass_upnp_last_check_timestamp_seconds{node="rpi"} ``` One series set per interface: `wg0` is Link A and `wg-remote` is Link B, and an @@ -51,7 +53,17 @@ interface absent on that host (wg-remote on siriussec, where it does not exist) is skipped. `RosenpassPskRotationStalled` is interface-agnostic (`max by (node, interface) ... > 900`), so a stalled Link B pages as soon as the `wg-remote` series exists — which is why hashing only `wg0` left Link B -unobserved. +unobserved. Its `absent()` arms name `rpi/wg0`, `rpi/wg-remote` and +`siriussec/wg0`, so a vanished Link B series pages too while siriussec never +claims a `wg-remote` it does not have. + +`rosenpass_upnp_mapping_present` is the state `rosenpass-upnp.sh` stamped on its +last 15-minute run (`/run/rosenpass-upnp.present`, `1`/`0`), and +`rosenpass_upnp_last_check_timestamp_seconds` is that file's mtime — so a +stopped timer reads as stale rather than as a flat healthy `1`. The 60-second +metrics timer only reads the file; it never calls `upnpc`, which would poll the +router's IGD 1440 times a day. Where the state file does not exist (siriussec) +neither series is emitted. The script hashes the output of `wg show preshared-keys` and stores only the SHA-256 digest plus the last-change timestamp in @@ -81,13 +93,15 @@ it after the `values.yaml` change is reconciled). `RosenpassDown` (unit inactive for 5 m) and `RosenpassPskRotationStalled` (age > 900 s for 10 m), both `severity: warning`, both with `absent()` guards -so a missing series alerts instead of reading as healthy. +so a missing series alerts instead of reading as healthy. Both cover **Link A +and Link B**: the rotation rule keys on `(node, interface)`, and its `absent()` +arms name `rpi/wg0`, `rpi/wg-remote` and `siriussec/wg0`. -`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. +A third rule, `RosenpassUpnpMappingLost` (`severity: warning`, 10 m), covers +Link B's single inbound path: it fires when +`rosenpass_upnp_mapping_present == 0`, when no `rosenpass-upnp` run has stamped +the state for over 30 minutes (stopped timer, hung IGD), or when the series is +absent altogether. ## Link B (rpi wg-remote ↔ linode wg0) diff --git a/infrastructure/networking/rosenpass/rosenpass-metrics.sh b/infrastructure/networking/rosenpass/rosenpass-metrics.sh index 85407ae..8cda18e 100644 --- a/infrastructure/networking/rosenpass/rosenpass-metrics.sh +++ b/infrastructure/networking/rosenpass/rosenpass-metrics.sh @@ -21,6 +21,15 @@ # last changed. Rotation runs about every two minutes. # rosenpass_psk_rotation_last_change_timestamp_seconds{node,interface} # unix timestamp of that last observed change. +# rosenpass_upnp_mapping_present{node} +# 1/0 state that rosenpass-upnp.sh stamped on its +# last run (Link B's only inbound path on the Pi). +# Only emitted where that unit runs: no state file, +# no series, so siriussec does not advertise it. +# rosenpass_upnp_last_check_timestamp_seconds{node} +# unix mtime of that state file, so a stopped +# rosenpass-upnp.timer reads as stale rather than as +# a flat healthy 1. # # Interfaces are emitted independently: wg0 is Link A (rpi <-> siriussec) and # wg-remote is Link B (rpi <-> linode, through a permanent UPnP mapping on a @@ -59,7 +68,23 @@ if [ "$(systemctl is-active "$UNIT" 2>/dev/null || true)" = "active" ]; then active=1 fi -# --- 2. PSK rotation, per interface ----------------------------------------- +# --- 2. UPnP mapping state (Link B inbound path) ----------------------------- +# rosenpass-upnp.sh stamps 1/0 into /run on each of its 15-min runs. This timer +# must NOT call upnpc itself: that would poll the IGD 1440x/day and put the +# fragile component in the hot path. No state file means this host does not run +# that unit (siriussec), so emit nothing there. +UPNP_STATE=/run/rosenpass-upnp.present +upnp="" +upnp_ts="" +if [ -r "$UPNP_STATE" ]; then + upnp=$(head -n 1 "$UPNP_STATE" 2>/dev/null | tr -d '[:space:]') + case "$upnp" in + 0 | 1) upnp_ts=$(stat -c %Y "$UPNP_STATE" 2>/dev/null || echo "$now") ;; + *) upnp="" ;; + esac +fi + +# --- 3. PSK rotation, per interface ----------------------------------------- # `wg show ... preshared-keys` fails (and prints nothing) when the interface is # absent; command substitution would otherwise hash an empty string, which looks # like a change on the first poll after the interface returns. Only hash real @@ -71,6 +96,15 @@ tmp="$OUT_FILE.$$" printf '# TYPE rosenpass_unit_active gauge\n' printf 'rosenpass_unit_active{node="%s"} %s\n' "$NODE" "$active" + if [ -n "$upnp" ]; then + printf '# HELP rosenpass_upnp_mapping_present The Link B UPnP mapping (UDP 9999 -> rpi) is present (1) or missing (0), as of the last rosenpass-upnp.sh run.\n' + printf '# TYPE rosenpass_upnp_mapping_present gauge\n' + printf 'rosenpass_upnp_mapping_present{node="%s"} %s\n' "$NODE" "$upnp" + printf '# HELP rosenpass_upnp_last_check_timestamp_seconds Unix timestamp of the last rosenpass-upnp.sh run that wrote the state file.\n' + printf '# TYPE rosenpass_upnp_last_check_timestamp_seconds gauge\n' + printf 'rosenpass_upnp_last_check_timestamp_seconds{node="%s"} %s\n' "$NODE" "$upnp_ts" + fi + printf '# HELP rosenpass_psk_rotation_age_seconds Seconds since that interface preshared-key set last changed.\n' printf '# TYPE rosenpass_psk_rotation_age_seconds gauge\n' printf '# HELP rosenpass_psk_rotation_last_change_timestamp_seconds Unix timestamp of the last observed preshared-key change on that interface.\n' diff --git a/infrastructure/networking/rosenpass/rosenpass-upnp.sh b/infrastructure/networking/rosenpass/rosenpass-upnp.sh index 6f74e27..b655579 100755 --- a/infrastructure/networking/rosenpass/rosenpass-upnp.sh +++ b/infrastructure/networking/rosenpass/rosenpass-upnp.sh @@ -15,11 +15,23 @@ set -uo pipefail LAN_IP=192.168.1.125 PORT=9999 DESC=rosenpass-pq +# Result of this run, read by rosenpass-metrics.sh (60 s textfile collector) so +# the mapping is observable without polling the IGD from that timer. /run is +# tmpfs: on a reboot the file is gone and the metric is absent until this unit +# runs again (OnBootSec=2min), which the alert treats as "unknown", not "lost". +STATE=/run/rosenpass-upnp.present + +set_present() { + printf '%s\n' "$1" > "$STATE.tmp" && mv "$STATE.tmp" "$STATE" +} 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 + set_present 0 logger -t rosenpass-upnp "mapping missing after re-assert: ${out}" exit 1 fi + +set_present 1 diff --git a/monitoring/controllers/home/rosenpass.yaml b/monitoring/controllers/home/rosenpass.yaml index 90c290b..e05b185 100644 --- a/monitoring/controllers/home/rosenpass.yaml +++ b/monitoring/controllers/home/rosenpass.yaml @@ -19,14 +19,25 @@ # Series, emitted per host, never containing key material (the PSK set is only # SHA-256 hashed, in a root-only state file): # rosenpass_unit_active{node="rpi|siriussec"} 0|1 -# rosenpass_psk_rotation_age_seconds{node=...,interface="wg0"} -# rosenpass_psk_rotation_last_change_timestamp_seconds{node=...,interface="wg0"} +# rosenpass_psk_rotation_age_seconds{node=...,interface="wg0|wg-remote"} +# rosenpass_psk_rotation_last_change_timestamp_seconds{node=...,interface="wg0|wg-remote"} +# rosenpass_upnp_mapping_present{node="rpi"} 0|1 +# rosenpass_upnp_last_check_timestamp_seconds{node="rpi"} # -# Both rules carry an absent() arm deliberately: a metric that simply stops -# arriving (timer disabled, script broken, node-exporter down, scrape lost) +# Both rotation rules carry an absent() arm deliberately: a metric that simply +# stops arriving (timer disabled, script broken, node-exporter down, scrape lost) # must alert, because "nothing happened" is exactly what a healthy rotation -# looks like from Prometheus' side. The absent arms name the two hosts that run -# the timer so linode — which has node-exporter but no rosenpass — does not page. +# looks like from Prometheus' side. The absent arms name the hosts and +# interfaces that actually run the timer — rpi wg0 + wg-remote (Link A + Link B), +# siriussec wg0 (Link A only; it has no wg-remote) — so linode, which has +# node-exporter but no rosenpass, and an interface absent from a host do not +# page. +# +# Link B's inbound path is a permanent UPnP mapping on the Pi's router (which +# has no accessible admin panel). rosenpass-upnp.sh re-asserts it every 15 min +# and stamps 1/0 into /run, which rosenpass-metrics.sh turns into the series +# below. Without that mapping the exchange cannot be dialled, the link keeps its +# last PSK and silently stops being post-quantum. apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: @@ -74,6 +85,8 @@ spec: ( absent(rosenpass_psk_rotation_age_seconds{node="rpi", interface="wg0"}) or + absent(rosenpass_psk_rotation_age_seconds{node="rpi", interface="wg-remote"}) + or absent(rosenpass_psk_rotation_age_seconds{node="siriussec", interface="wg0"}) ) for: 10m @@ -92,3 +105,35 @@ spec: `journalctl -u rosenpass -n 30` on both rpi and siriussec, and confirm the Pi still admits 9999/udp from 192.168.1.179 (`sudo ufw status | grep 9999`). + - alert: RosenpassUpnpMappingLost + expr: | + ( + max by (node) (rosenpass_upnp_mapping_present) == 0 + ) + or + ( + time() - max by (node) (rosenpass_upnp_last_check_timestamp_seconds) > 1800 + ) + or + absent(rosenpass_upnp_mapping_present{node="rpi"}) + for: 10m + labels: + severity: warning + annotations: + summary: >- + Link B UPnP mapping missing or unverified on {{ $labels.node }} + description: >- + Link B (rpi wg-remote 10.20.0.2 <-> linode wg0 10.20.0.1) can only + be dialled inbound through a permanent UPnP mapping + UDP 9999 -> 192.168.1.125:9999 on the Pi's router, and + rosenpass-upnp.timer re-asserts it every 15 minutes. Either the + last run reported the mapping missing (value 0), no run has + updated the state for over 30 minutes (timer or router IGD gone), + or the series is absent entirely (state file cleared by a reboot, + metrics timer dead). The link keeps passing traffic on its last + preshared key, so this is invisible from the tunnel. On rpi check + `systemctl status rosenpass-upnp.timer`, + `journalctl -t rosenpass-upnp -n 20` and `upnpc -l | grep 9999`; + re-assert by hand with + `sudo systemctl start rosenpass-upnp.service`. If the router + rebooted, the mapping comes back on the next timer run.