homelab/ansible/roles/pia-gateway/templates/pia-killswitch-reassert.service.j2
Nik Afiq 89d289addf feat: add periodic kill-switch reassertion timer
Found live, 2026-09-22: after fixing pia-killswitch.sh's FORWARD-jump
repositioning and getting one pia-gateway register attempt past the
safety check, the very next attempt - roughly an hour later, no
reboot, no UFW reload, no script content change in between - hit the
identical "FORWARD jump to kill-switch chain is not first" failure
again. This disproves the earlier assumption that kube-router/dockerd
reassert their own position-1 jumps only at boot/restart scale:
kube-router resyncs on ordinary Kubernetes API events, and this
cluster's CronJobs (ca-sync, porkbun-ddns, gitea-backup) each
create/delete a Pod every few minutes - plausible triggers for
kube-router's own reconciliation loop, and therefore plausible
triggers for this drift, recurring on a timescale of minutes.

The reposition logic itself (previous commit) is correct - it just
only ran on the existing triggers (boot, UFW reload, an
Ansible-detected script content change), none of which fired between
the two attempts.

Adds pia-killswitch-reassert.timer/.service: re-runs the already fully
idempotent pia-killswitch.sh every pia_healthcheck_interval_sec (same
cadence as the health check), giving it regular chances to run instead
of only sporadic ones. Deliberately separate from
pia-gateway-recover.timer and NOT gated by pia_auto_recovery_enabled -
this is the kill switch continuing to assert its own already-
established, narrowly-scoped state (source rule, table default,
FORWARD jump position), the same kind of thing it already does
unconditionally at boot and after a UFW reload, just on a schedule
too - not the higher-level automatic recovery/registration logic the
plan was deliberately cautious about running unattended.

Unblocked live in the meantime with a manual
`sudo systemctl restart pia-killswitch.service`.

Offline checks: yamllint, ansible-playbook --syntax-check, rendered
templates (Jinja2 + bash -n on the updated script), ansible-lint
(diffed against main - no new finding categories), full pia_gateway.py
test suite (94/94, unaffected by this change) all pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 19:08:28 +09:00

31 lines
1.6 KiB
Django/Jinja

# Managed by Ansible (role: pia-gateway). Do not edit by hand.
#
# Periodically re-runs the kill-switch seed script (pia-killswitch.sh) so
# its invariants — source rule, table default, and specifically the
# FORWARD jump's position — are re-asserted on a schedule, not only at
# the external trigger points that used to be the only times it ran
# (boot, a UFW reload, or an Ansible-detected content change to the
# script itself). Needed because other host components that also manage
# iptables — kube-router and dockerd — reassert their OWN position-1
# jumps independently, and confirmed live (2026-09-22) to do so more
# often than originally assumed: the FORWARD jump drifted twice within
# about an hour under this cluster's ordinary CronJob/pod churn (ca-sync,
# porkbun-ddns, gitea-backup, ...), not just at boot-scale events.
#
# The script itself is already fully idempotent (safe to run repeatedly
# — see its own header comment); this unit just gives it more chances to
# run. Deliberately separate from pia-gateway-recover.timer and NOT
# gated by pia_auto_recovery_enabled: this is the kill switch continuing
# to assert its own already-established, narrowly-scoped state — the
# same kind of thing it already does unconditionally at boot and after a
# UFW reload, just on a schedule too — not the higher-level automatic
# recovery/registration logic the plan was deliberately cautious about
# running unattended.
[Unit]
Description=Periodically re-assert the PIA gateway kill switch's FORWARD jump position
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/pia-killswitch.sh
LimitCORE=0