Author the vpn_egress_gateway role + playbook that stands up the NODE-level PIA OpenVPN tunnel on egress-gateway node(s) — the host half of ADR-0015. The CiliumEgressGatewayPolicy steering vpn-class pods is separate GitOps against the same contract (group vpn_egress_gateway, node label homelab.keithjackson.dev/egress-gateway=true, host iface tun0). Honors all four ADR-0015 invariants: - Split-tunnel (inv 1&2): OpenVPN route-noexec + pull-filter ignore redirect-gateway => installs no routes; policy routing in a dedicated table (51820) with `ip rule from <tun0-addr>` steers ONLY Cilium-SNAT'd vpn-class traffic. Node default route stays on the WAN, tunnel up or down. - Scoped nftables kill-switch (inv 3&4): own inet table, policy accept, drops only tunnel-sourced (@vpn_egress_gateway_src set) packets not leaving tun0 => vpn-class fails closed (blackhole), node/internet-class fail open (WAN), never matched. PIA creds + the proven sweden-aes-128-cbc-udp-ip .ovpn come from Ansible vault (host-side per ADR-0015/docs-07); vault keys documented, no secret values committed. ansible-lint (production) + yamllint clean. Not deployed: green conformance is gated on the live tunnel (operator host creds) — see role README. Co-Authored-By: Claude Opus 4.8 <[email protected]>
role: vpn_egress_gateway (ADR-0015)
Stands up the node-level VPN tunnel on the egress-gateway node(s): a host OpenVPN
systemd service (PIA over OpenVPN-UDP), split-tunnel via policy routing, and a
scoped nftables kill-switch. This is the host half of ADR-0015; the
CiliumEgressGatewayPolicy that steers egress-class=vpn pods to this node's tun0 is
separate GitOps authored against the shared interface contract below.
CONFORMANCE IS GATED ON A LIVE TUNNEL. This role cannot be proven green without the operator's PIA host credentials (see "What requires a live tunnel"). Authoring + lint pass in CI; the
egress-class/vpn-killswitchconformance tests (R-NET-05/06/07) go green only once the tunnel is live in dev/test.
Interface contract (shared with the Cilium-policy agent)
- Inventory group
vpn_egress_gateway— the egress-gateway node(s) (initiallyk3s-dev-3). - k8s node label
homelab.keithjackson.dev/egress-gateway=true— set by this role; theCiliumEgressGatewayPolicyselects the gateway node by it. - Host tunnel iface
tun0— the Cilium policy SNATs vpn-class pods out of it. - Optional fwmark
0x1c8— a contract hook (see kill-switch layering) the Cilium side MAY stamp on vpn-class packets for a tunnel-down-independent host backstop.
How the four ADR-0015 invariants are met
1 & 2 — split-tunnel; tun0 is never a default route
templates/vpn-egress.conf.j2 includes the operator's proven .ovpn and layers on
route-noexec + pull-filter ignore "redirect-gateway", so OpenVPN installs no routes and
never touches the main routing table. The node's own default route stays on the WAN whether
the tunnel is up or down — k3s/etcd/kubelet are unaffected.
Steering is done with policy routing in a dedicated table (51820, named vpn_egress):
- The OpenVPN up-script adds
default dev tun0to table51820and an ip-rulefrom <tun0-addr> lookup 51820(priority 5000). Only packets whose source is the tunnel address — i.e. the vpn-class pods Cilium has SNAT'd totun0— consult that table. Nothing else does, so nothing else is re-routed. - The down-script removes the ip-rule and the tunnel default (leaving the blackhole).
3 & 4 — kill-switch scoped to vpn-class, opposite fail directions
Two independent layers, both scoped so they can only ever affect vpn-class traffic:
- Routing blackhole (fail-closed fallback). Table
51820always carries a permanentblackhole default(installed byvpn-egress-killswitch.service, metric 4000). When the tunnel default is withdrawn (flap / partial teardown) while the ip-rule still steers, packets hit the blackhole instead of falling through to the WAN. - nftables backstop (
templates/vpn-egress-killswitch.nft.j2). Owninet vpn_egress_gateway_killswitchtable, base chain policyaccept(so it can only drop the narrow matches, never break anything). Inpostrouting:oifname tun0 ip saddr @vpn_egress_gateway_src accept— tunnel up: let steered traffic out.ip saddr @vpn_egress_gateway_src oifname != tun0 drop— fail closed: a tunnel-sourced packet trying to leave any other interface is dropped (no WAN leak).meta mark 0x1c8 oifname != tun0 drop— the optional fwmark backstop.
@vpn_egress_gateway_src holds the live tun0 address (added by the up-script, flushed by the
down-script). Node traffic and internet-class traffic are never in the set, never carry the
mark, and are never targeted — so they always hit policy accept and fail open toward the
WAN (invariant 4), tunnel up or down. The opposite directions are structural, not incidental.
Why the node default route is provably unaffected (design-level verification)
- OpenVPN runs with
route-noexecandpull-filter ignore "redirect-gateway"→ it adds zero routes and cannot install a0.0.0.0/0viatun0. (This is exactly the failure mode that madehostNetworkgluetun non-viable in ADR-0015; here OpenVPN is explicitly told not to route.) - All tunnel routing lives in table 51820 only; the up/down scripts touch that table and
ip-rules, never
table main/table default. - The ip-rule matches
from <tun0-addr>— an address the node itself never sources traffic from — so node-originated and internet-class packets never enter the tunnel table. - The nft table is policy accept and matches only
@vpn_egress_gateway_src/ the fwmark. - Live check (post-deploy):
ip route show table main defaultstill points at the WAN NIC, andcurl ipinfofrom the node shows the WAN IP, with the tunnel both up and forced down.
Kill-switch layering & ESCALATION (honest limit)
- The nft
@vpn_egress_gateway_srcrule and the routing blackhole robustly cover the case where the tunnel is up but a vpn-class packet is (mis)routed toward the WAN, and flaps. - The tunnel fully-down case relies on Cilium Egress Gateway itself failing closed when
its egress interface
tun0is absent (Cilium 1.16 drops egress-gateway-marked traffic with no valid egress path rather than falling back to the node's default route) plus the routing blackhole. That is the ADR's expected behavior. - For a host backstop that is fully independent of Cilium even in a fail-open regression when
the tunnel is down (no tun0 address to key on), the host needs a stable marker on vpn-class
packets. The only contract-available marker is the
0x1c8fwmark hook — which the Cilium-policy side must stamp. ESCALATION for the PM: either (a) confirm the Cilium Egress Gateway 1.16 fail-closed + routing-blackhole guarantee is accepted as sufficient for R-NET-06, or (b) add the shared fwmark to the interface contract so the CiliumEgressGatewayPolicy marks vpn-class traffic and this role's fwmark rule becomes the tunnel-down-independent backstop. This is flagged rather than worked around — no spec was weakened to reach done.
What requires a LIVE tunnel to validate (cannot be tested without operator creds)
- The PIA
.ovpn+ username/password actually authenticate andtun0comes up as a host iface. egress-class: a vpn-class pod's public IP is the PIA Stockholm IP; internet-class shows the WAN IP.vpn-killswitch: forcingtun0/the tunnel service down blackholes vpn-class egress (no leak) while internet-class is unaffected — the R-NET-06 fault-injection gate.- That Cilium Egress Gateway SNAT to
tun0traverses hostpostroutingso the nft set-scoped rules actually see the packets (eBPF datapath interaction — see escalation). - MTU/PMTU across
pod → tun0 → PIA(in-pod gluetun needed 1300 for Cilium VXLAN; on the node the tunnel rides the physical WAN, sovpn_egress_gateway_tun_mtudefaults empty — verify live). - Port forwarding (PIA NAT-PMP) for qBittorrent — ADR-0015 Phase-6 follow-up, not in this role.
Files
defaults/main.yml— allvpn_egress_gateway_*vars; the three vault-backed credential vars.tasks/main.yml— packages, rt_tables, config/scripts/units, enable+start, node label.handlers/main.yml— daemon-reload, kill-switch reload, tunnel restart.templates/— wrapper.conf, credentials, up/down scripts, nft ruleset, both systemd units.- Playbook:
playbooks/vpn.egress.gateway.yml. Vault keys:inventory/group_vars/vpn_egress_gateway/README.md.