feat(core): fail-safe hardening — live-flag, watchdog, procd fixes

Close the "rules live, engine dead" LAN-blackout class and make an admin
`stop` durable:
- live-flag /var/run/shater.active gates hotplug/cron reconcile, so `stop`
  sticks — a WAN flap can no longer resurrect interception behind a stopped
  engine.
- procd respawn retry=0 (never abandon the engine while rules stand) + guard
  that /usr/bin/xray is executable before installing the data plane.
- shater-cron watchdog: engine dead N ticks with interception live escalates
  per kill_switch (open -> auto-stop/fail-open, closed -> crit log).
- fix procd cron detach: `command "$INIT_SCRIPT" loop` (rc.common dispatch)
  instead of `/bin/sh $INIT_SCRIPT loop`, which detached the loop from procd
  (running:false + respawn churn) — the auto-updater/watchdog ran unsupervised.
- run.json regenerated at start after sysupgrade; cron stamps only on success
  with backoff, and waits for a default route before boot-time fetches.
- sysctl route_localnet/accept_local scoped to lo (was all — WAN anti-spoof
  weakening); applied at install time so no reboot is needed.
- fix stale example filenames; bump shater-core to r19.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LLthkP2S8WAfxu7fcYbPfE
This commit is contained in:
omarandClaude Opus 4.8 committed 2026-07-13 03:37:26 +03:00
1 parent f1e4f16a9f
commit 65883e20d9
8 files changed
+269 -81

No files matched your search

@@ -3,10 +3,13 @@
#
# netifd wipes `ip rule` / `ip route` on `network reload` and on interface
# churn, so our policy routing must be re-persisted on every ifup/ifdown.
# xrayctl reconcile is idempotent, so re-running it here is safe and cheap.
# xrayctl reconcile is idempotent (flock-serialized, hash-compared), so
# re-running it here is safe and cheap.
#
# Fully inert unless the Shater stack is enabled — never disturbs connectivity
# on boxes where the package is merely installed.
# Fully inert unless the Shater stack is enabled AND the main service is live
# (ACTIVE_FLAG raised by /etc/init.d/shater start, cleared by stop). Guarding
# on the flag — not just on UCI — means an admin `stop` sticks: a WAN flap can
# never resurrect interception behind a deliberately stopped engine.
[ -x /usr/bin/xrayctl ] || exit 0
@@ -15,9 +18,22 @@ case "$ACTION" in
*) exit 0 ;;
esac
# Only act when explicitly enabled.
# Only act when explicitly enabled AND the service is meant to be running.
en=$(uci -q get shater.globals.enabled) || exit 0
[ "$en" = "1" ] || exit 0
[ -f /var/run/shater.active ] || exit 0
# Coalesce interface-flap storms: each reconcile runs a full `xray -test`,
# which is real CPU on small routers. The FIRST event in a burst schedules one
# reconcile 2s out (absorbing the burst's rule-wipes); followers in that window
# exit — their wipes are covered by the pending pass. The marker is released
# BEFORE reconciling so an event landing mid-reconcile schedules a fresh pass
# and no wipe is ever left unrepaired.
pending=/var/run/shater/hotplug.pending
mkdir -p /var/run/shater
mkdir "$pending" 2>/dev/null || exit 0
sleep 2
rmdir "$pending" 2>/dev/null
/usr/bin/xrayctl reconcile >/dev/null 2>&1