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.
This commit is contained in:
Lance Walters 2026-12-03 02:52:58 -05:00
commit d1343bbbc3
4 changed files with 120 additions and 15 deletions

View file

@ -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'