homek8s/infrastructure/networking/rosenpass/README.md
Lance Walters d1343bbbc3 feat(rosenpass): alert on a vanished Link B series and on the UPnP mapping
Link B (rpi wg-remote <-> linode wg0) depends on a permanent UPnP mapping
UDP 9999 -> 192.168.1.125:9999 for its inbound path, and the 15-minute
rosenpass-upnp.timer only logged to the journal when it could not re-assert
it. Two gaps closed:

* RosenpassPskRotationStalled gains absent(rosenpass_psk_rotation_age_seconds
  {node="rpi", interface="wg-remote"}). Without it a dead metrics timer or
  script on the Pi silently dropped the Link B series while the rule kept
  reading healthy. No siriussec/wg-remote arm: that interface does not exist
  there.

* rosenpass-upnp.sh now stamps its result to /run/rosenpass-upnp.present (1/0)
  and rosenpass-metrics.sh reads that file into rosenpass_upnp_mapping_present
  {node="rpi"} plus rosenpass_upnp_last_check_timestamp_seconds. The 60 s
  metrics timer never calls upnpc (that would poll the IGD 1440x/day); a host
  without the state file (siriussec) emits neither series. New
  RosenpassUpnpMappingLost alert fires on value 0, on a state file older than
  30 minutes (stopped timer / hung IGD, so a stale 1 cannot read healthy), or
  on a missing series.
2026-12-03 02:52:58 -05:00

8.9 KiB

Rosenpass monitoring (host exporters for Link A and Link B)

Rosenpass rotates the WireGuard preshared key on Link A (rpi wg0 10.10.0.1 ↔ siriussec wg0 10.10.0.2) and on Link B (rpi wg-remote 10.20.0.2 ↔ linode wg0 10.20.0.1) about every two minutes. WireGuard keeps using the last PSK it was given, so if the exchange dies the tunnel stays up and silently stops being post-quantum. These files make that state visible in Prometheus.

They are host configuration, not cluster manifests — nothing here is reconciled by Flux. The cluster side is monitoring/controllers/home/rosenpass.yaml (PrometheusRule) plus the prometheus-node-exporter block in monitoring/controllers/home/values.yaml, which enables the textfile collector.

Why a host script instead of a collector

kube-prometheus-stack-prometheus-node-exporter is distroless and ships without --collector.textfile.directory; --collector.systemd would need dbus plumbing the DaemonSet does not have. So one POSIX sh script writes a textfile that node-exporter serves from /metrics.

Install (rpi and siriussec only — never linode)

install -m 0755 rosenpass-metrics.sh /usr/local/sbin/rosenpass-metrics.sh
install -m 0644 rosenpass-metrics.service /etc/systemd/system/
install -m 0644 rosenpass-metrics.timer   /etc/systemd/system/
# Shared with the node-exporter DaemonSet's hostPath. The unit's sandbox sets
# ProtectSystem=strict, so this must exist before the first run (the kubelet's
# DirectoryOrCreate would normally make it once node-exporter rolls out).
install -d -m 0755 /var/lib/node-exporter/textfile
systemctl daemon-reload
systemctl enable --now rosenpass-metrics.timer
systemctl start rosenpass-metrics.service   # first sample now, not in 60 s

Requires wg, sha256sum, systemctl and awk — present on Debian (rpi) and Arch (siriussec).

Series

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 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. 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 <interface> preshared-keys and stores only the SHA-256 digest plus the last-change timestamp in /var/lib/rosenpass-exporter/last-hash-<interface> (root-only, one file per interface so a Link B rotation is never recorded as a Link A one). When the digest changes the timestamp advances; otherwise only the age metric grows. Key material is never printed, logged or persisted. The timer's own journal therefore carries no key bytes — do not "improve" the script by echoing the listing.

An interface unreadable (down, no CAP_NET_ADMIN) emits no series for that interface rather than resetting its age; rosenpass_unit_active and the absent() arms of the alerts cover that case, so a broken exporter still pages.

Verify

systemctl list-timers rosenpass-metrics.timer
cat /var/lib/node-exporter/textfile/rosenpass.prom

Both metrics should be present and the age well under 300 s once the cluster scrapes the file (the file exists on the host either way; Prometheus only sees it after the values.yaml change is reconciled).

Alerts

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. 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.

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 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:

    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 = "<new-ip>: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 PresharedKeys 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 prove the PromQL, before Flux ever sees it (a rule that loads but selects nothing is the failure mode that matters here):

# 1. syntax + expression validation. promtool wants a bare `groups:` file, so
#    strip the CRD wrapper first (PyYAML; jq cannot read YAML).
python3 - <<'PY'
import yaml
d = yaml.safe_load(open('monitoring/controllers/home/rosenpass.yaml'))
yaml.safe_dump({'groups': d['spec']['groups']}, open('/tmp/rosenpass-rules.yaml', 'w'))
PY
kubectl -n monitoring run promtool-check --rm -i --restart=Never \
  --image=quay.io/prometheus/prometheus:v3.15.1-distroless \
  --command -- /bin/promtool check rules /dev/stdin < /tmp/rosenpass-rules.yaml
# 2. behaviour: promtool test rules with input_series. Mount the rule file and
#    a test file (rule_files: [rosenpass-rules.yaml]) from a ConfigMap and check
#    four scenarios — healthy (no alerts), one unit down (only that node), age
#    over threshold plus a missing peer series, and every series missing (both
#    absent() arms). Expect `SUCCESS`. Note promtool compares annotations
#    exactly, so expectations have to carry the rendered text.

Keep the test file out of the repo: it duplicates the annotation strings, so any edit to the alerts would have to re-derive it from rosenpass.yaml.