Skip to content

security: fail-closed startup, secret rotation, target-gate backfill and kernel kill-switch - #715

Merged
BaaRai merged 2 commits into
mainfrom
sec/p0-failclosed
Nov 30, 2026
Merged

BaaRai merged 2 commits into
mainfrom
sec/p0-failclosed

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Summary

Security hardening for the panel and the agent execution boundary. This is the first half of the fix for the execution-scope gap tracked in #421, #423, #554 and #555, and confirmed publicly by the 28 November 2026 writeup.

What changes

  • Fail-closed startup. The isolation self-test now stops the server on every platform unless ARTEX_ALLOW_UNISOLATED=1 is set explicitly. The key directory is tightened to 0700 and existing key files to 0600 at startup, so a host bind mount cannot mask the image permissions.
  • Atomic secret rotation. db.RotateSecretKey, artex -rotate-secrets and scripts/rotate-secrets.sh re-encrypt every sealed database value and bump auth.password_version in one transaction before the new key is moved into place. Existing sessions are invalidated.
  • Target gate backfill. Migration 0022_target_gate_backfill.sql sets target_gate=true on active scoped tasks that did not opt out, and persists an explicit opt-out in tasks.target_gate_opt_out. New scoped tasks default the gate ON; TargetGate: &false is the explicit opt-out.
  • Real kill switch. Engine.Pause and Engine.BeginDelete set PR_SET_CHILD_SUBREAPER and terminate the executor UID or the task descendant tree from /proc. Tests cover setsid, nohup, a double-fork with trap '' TERM, an active egress loop, and verify that egress stops after pause.

Upgrade notes

  • Startup is fail-closed. A host that cannot apply the executor isolation must set ARTEX_ALLOW_UNISOLATED=1 deliberately.
  • Scoped tasks created before this change are backfilled to target_gate=true; pass an explicit opt-out to keep a task ungated.
  • scripts/rotate-secrets.sh --dsn ... is required when PostgreSQL holds enc:v1:* values; rotating the files alone leaves those rows unreadable.

Tests

  • go build ./..., go vet ./...
  • go test -p 1 ./... on PostgreSQL 16, 23/23 packages
  • go test -race ./server kill-switch tests: setsid, nohup, double-fork trap '' TERM, post-pause egress
  • migration contiguity 1..22 and the 0022 backfill
  • scripts/rotate-secrets.sh and -rotate-secrets against a disposable database

References and credits

The scope and isolation gaps were reported and designed in public before the writeup: #421 and #423 by @youssefmedhatl, #554 and #555 by @renaesop, with the two-sources-of-truth analysis by @Dukotah in #421. This change implements the first part of that work. The execution sandbox follows in a second pull request.

…ate backfill, and kernel kill-switch

- Startup fail-closed: LockDownKeyDir explicitly chmods 0700 an existing key
  dir (counteracting host bind mounts) and 0600 existing key files; adds keys/
  itself alongside jwt.key, secret.key, and config.json to IsolationSelfTest;
  makes IsolationSelfTest fatal unless ARTEX_ALLOW_UNISOLATED=1 is set.
- Secret rotation: adds db.RotateSecretKey (single atomic transaction
  re-encrypting all sealed columns/settings and bumping auth.password_version),
  cmd/artex -rotate-secrets, scripts/rotate-secrets.sh, and OPS/SECURITY docs.
- Scoped defaults, backfill & posture warnings: TargetGate defaults ON for
  tasks with CompanyIDs or InterceptRules (explicit opt-out persisted in
  tasks.target_gate_opt_out); migration 0022_target_gate_backfill.sql backfills
  existing active scoped tasks that did not explicitly opt out; egress-guard
  defaults to EGRESS_MODE=enforce when scope lists exist; loud startup warning
  when target gate or egress enforcement is off.
- Kernel-backed local kill-switch: enables PR_SET_CHILD_SUBREAPER and scans
  /proc (without trusting agent-writable state) on Engine.Pause/BeginDelete to
  kill escaped setsid, nohup, and nested double-fork daemons (plus all
  execPriv.UID processes in isolated mode) within <= 5s with zero post-pause
  egress.
@BaaRai
BaaRai merged commit 4d8c2c7 into main Nov 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant