homek8s/infrastructure/networking/rosenpass/README.md

106 lines
4.5 KiB
Markdown

# 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.
## 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):
```sh
# 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
```
```sh
# 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`.