feat(monitoring): alert on Rosenpass unit state and stalled PSK rotation

Rosenpass rotates the Link A preshared key (rpi wg0 10.10.0.1 <->
siriussec wg0 10.10.0.2) about every two minutes, but WireGuard keeps
using the last key it received: a dead or wedged exchange leaves the
tunnel up and silently non-post-quantum, with no alerting signal.

node-exporter here is distroless without the textfile collector (and
without the dbus plumbing --collector.systemd needs), so observe the
host directly:

- infrastructure/networking/rosenpass/: POSIX sh script run by a 60 s
  systemd timer on rpi and siriussec that writes
  /var/lib/node-exporter/textfile/rosenpass.prom. It exports
  rosenpass_unit_active, rosenpass_psk_rotation_age_seconds and
  rosenpass_psk_rotation_last_change_timestamp_seconds; the PSK listing
  is only ever sha256'd, never logged or persisted.
- values.yaml: enable --collector.textfile.directory and mount the
  hostPath (DirectoryOrCreate, so linode's node-exporter still starts).
  extraArgs replaces the subchart defaults, so the two filesystem
  exclusions are repeated verbatim.
- rosenpass.yaml: RosenpassDown (5 m) and RosenpassPskRotationStalled
  (age > 900 s, 10 m), both warning, both with absent() arms so a
  missing series alerts instead of reading as healthy.

Host units are installed out of band (see the directory README); the
GitOps side needs a merge before Prometheus loads the rules.
This commit is contained in:
Lance Walters 2026-12-03 02:16:30 -05:00
commit 5177b13004
7 changed files with 333 additions and 0 deletions

View file

@ -0,0 +1,74 @@
# Rosenpass monitoring (host exporters for Link A)
Rosenpass rotates the WireGuard preshared key on **Link A** (`rpi` wg0
`10.10.0.1` ↔ `siriussec` wg0 `10.10.0.2`) 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)
```sh
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"}
rosenpass_psk_rotation_last_change_timestamp_seconds{node=...,interface="wg0"}
```
The script hashes the output of `wg show wg0 preshared-keys` and stores only
the SHA-256 digest plus the last-change timestamp in
`/var/lib/rosenpass-exporter/last-hash` (root-only). 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.
`wg0` unreadable (interface down, no `CAP_NET_ADMIN`) leaves the age metric
unchanged rather than resetting it; `rosenpass_unit_active` and the `absent()`
arms of the alerts cover that case, so a broken exporter still pages.
## Verify
```sh
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.

View file

@ -0,0 +1,23 @@
[Unit]
Description=Rosenpass health metrics for node-exporter (textfile collector)
Documentation=file:///usr/local/sbin/rosenpass-metrics.sh
# No Requires=/After= on rosenpass.service or [email protected] on purpose:
# the recorder has to keep running and keep exporting while the unit it watches
# is dead or the interface is down — a hard dependency would take the metric
# away exactly when it becomes the alert.
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/rosenpass-metrics.sh
User=root
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
# /var/lib/rosenpass-exporter (hash state) is created by systemd.
StateDirectory=rosenpass-exporter
# The textfile dir is shared with the node-exporter DaemonSet (hostPath). It is
# created by the install step; the leading `-` keeps the unit startable if a
# node has lost it (the node-exporter DirectoryOrCreate recreates it), instead
# of failing the whole unit with 226/NAMESPACE.
ReadWritePaths=-/var/lib/node-exporter/textfile

View file

@ -0,0 +1,100 @@
#!/bin/sh
# rosenpass-metrics.sh — emit Rosenpass health metrics for node-exporter's
# textfile collector.
#
# Installed on rpi and siriussec ONLY (the two ends of Link A: rpi wg0
# 10.10.0.1 <-> siriussec wg0 10.10.0.2), run every 60 s by
# rosenpass-metrics.timer as root. See README.md in this directory.
#
# Why a host script: kube-prometheus-stack-prometheus-node-exporter is
# distroless and ships without --collector.textfile.directory (and without the
# dbus plumbing --collector.systemd needs), so nothing inside the cluster can
# observe a host systemd unit. This writes a textfile that the DaemonSet's
# textfile collector then serves on :9100/metrics.
#
# Signals:
# rosenpass_unit_active{node}
# 1 when `systemctl is-active rosenpass.service`
# says active, else 0.
# rosenpass_psk_rotation_age_seconds{node,interface}
# seconds since the wg0 preshared-key set last
# changed. Rotation runs about every two minutes.
# rosenpass_psk_rotation_last_change_timestamp_seconds{node,interface}
# unix timestamp of that last observed change.
#
# The preshared key is NEVER printed, logged or stored: the key listing is
# piped straight into sha256sum and only the hex digest is kept, in a
# root-only state file. Do not add an `echo` of the listing while debugging.
#
# Deliberately independent of rosenpass.service: this script must keep
# reporting (unit_active=0, age growing) while the thing it watches is dead.
set -eu
NODE=$(hostname -s)
IFACE=wg0
UNIT=rosenpass.service
STATE_DIR=/var/lib/rosenpass-exporter
STATE_FILE=$STATE_DIR/last-hash
OUT_DIR=/var/lib/node-exporter/textfile
OUT_FILE=$OUT_DIR/rosenpass.prom
# 0644 so the node-exporter container (nobody/65534) can read the file and the
# directory stays traversable.
umask 022
mkdir -p "$STATE_DIR" "$OUT_DIR"
now=$(date +%s)
# --- 1. unit state -----------------------------------------------------------
active=0
if [ "$(systemctl is-active "$UNIT" 2>/dev/null || true)" = "active" ]; then
active=1
fi
# --- 2. PSK rotation ---------------------------------------------------------
# `wg show ... preshared-keys` fails (and prints nothing) when wg0 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 output.
psk_list=$(wg show "$IFACE" preshared-keys 2>/dev/null || true)
last_hash=""
last_change=""
if [ -f "$STATE_FILE" ]; then
last_hash=$(sed -n '1p' "$STATE_FILE")
last_change=$(sed -n '2p' "$STATE_FILE")
fi
if [ -n "$psk_list" ]; then
hash_now=$(printf '%s' "$psk_list" | sha256sum | awk '{print $1}')
if [ "$hash_now" != "$last_hash" ]; then
# First observation or an actual rotation: stamp it.
last_change=$now
printf '%s\n%s\n' "$hash_now" "$last_change" > "$STATE_FILE.tmp"
mv "$STATE_FILE.tmp" "$STATE_FILE"
fi
elif [ -z "$last_change" ]; then
# wg unreadable and no history: nothing to compare against yet.
last_change=""
fi
# --- 3. write the textfile atomically ---------------------------------------
tmp="$OUT_FILE.$$"
{
printf '# HELP rosenpass_unit_active rosenpass.service is active (1) or not (0).\n'
printf '# TYPE rosenpass_unit_active gauge\n'
printf 'rosenpass_unit_active{node="%s"} %s\n' "$NODE" "$active"
if [ -n "$last_change" ]; then
age=$((now - last_change))
[ "$age" -ge 0 ] || age=0
printf '# HELP rosenpass_psk_rotation_age_seconds Seconds since the wg0 preshared-key set last changed.\n'
printf '# TYPE rosenpass_psk_rotation_age_seconds gauge\n'
printf 'rosenpass_psk_rotation_age_seconds{node="%s",interface="%s"} %s\n' "$NODE" "$IFACE" "$age"
printf '# HELP rosenpass_psk_rotation_last_change_timestamp_seconds Unix timestamp of the last observed wg0 preshared-key change.\n'
printf '# TYPE rosenpass_psk_rotation_last_change_timestamp_seconds gauge\n'
printf 'rosenpass_psk_rotation_last_change_timestamp_seconds{node="%s",interface="%s"} %s\n' "$NODE" "$IFACE" "$last_change"
fi
} > "$tmp"
chmod 0644 "$tmp"
mv "$tmp" "$OUT_FILE"

View file

@ -0,0 +1,11 @@
[Unit]
Description=Collect Rosenpass health metrics every 60s
[Timer]
OnBootSec=30s
OnUnitActiveSec=60s
AccuracySec=5s
Unit=rosenpass-metrics.service
[Install]
WantedBy=timers.target