One dead uplink, seven outages: a WireGuard rule-priority race
28 October 2026
Context
- The media node reaches the internet only through a full-tunnel WireGuard VPN; it is also a k3s node running Cilium.
- Its applications kept their own error messages (“all indexers unavailable”, timeouts), so the first hour went into blaming the remote sites.
Symptom
- Every outbound request from the media node returned
000, including control targets that block nobody (example.com,registry.npmjs.org,api.telegram.org). Egress was dead; no site was blocking it. wg showreported a recent handshake, but no traffic came back.- Seven outages in three days, each after a deploy that restarted the tunnel. A manual
systemctl restartneeded a power-cycle: ARP answered, nothing above layer 2.
Causes
- Stale private key after a rolled-back deploy. WireGuard handshakes with a mismatched key, then blackholes the payload. Four of the seven outages.
- Rule-priority race. The tunnel’s ip rules landed above
local, so the node stopped answering its own address. ::/0in allowedIPs on a peer without IPv6: a second blackhole, for v6 traffic.
Why 98 and 99
wg-quickadds its rules withoutpref. The kernel’sfib_default_rule_pref()then uses the priority of the second rule in the list, minus one.- Cilium’s rule sits at 9 and
localat 100, so the kernel picks 99 and 98: abovelocal. If the tunnel comes up before Cilium, it gets 32765 and works. On boot this is a race; on a running node a restart loses every time. - Reproduced on a staging KVM guest (same Cilium image, a tunnel to a dead endpoint): 3 strands in about 21 cold boots.
- Same guest, same tables, seconds apart: explicit
prefreachable 10/10, nopref0/10.
Fix
ip -4 rule add pref 32765 not fwmark 51820 table 51820
ip -4 rule add pref 32764 table main suppress_prefixlength 0nix flake checkfails if eitherprefis removed or awg-quickinterface returns.- A reconciler converges the live tunnel with
wg set; it never restarts it. --node-ipand--advertise-addressare pinned. With the tunnel as default route, k3s had advertised10.2.0.2, and etcd could not rejoin.- Result on 2026-10-28: 3/3 restarts, rules at 32764/32765, a fresh handshake each time.
Monitoring added
- A 30-second timer writes handshake age and transfer counters for node-exporter’s textfile collector.
- Alerts:
WireGuardNoHandshake(over 5 minutes),WireGuardHandshakeStale(over 3 minutes for 10 minutes),WireGuardMetricsMissing. - The metrics were absent at first: the file was
0600and node-exporter ran asnobody. Only the “missing” alert fired.
What I took from it
- The lock was the bug. “Never restart the tunnel” was written down as a rule; it described the symptom and hid the defect behind a habit. The two
prefvalues are what actually keep the node up. - Boot is part of the acceptance test. Two more bugs only appeared after a power cut: the endpoint route was pinned before the NIC had an address, and k3s advertised the tunnel’s address to etcd.
- Prove egress before blaming a site. One
curlloop with control targets is the first line of the runbook page now.