3.6 KiB
Durable Stage cleanup verification
This change replaces the SHA-pinned transient timer with a root-owned intent journal
and a fixed host systemd retry worker. No host service is installed or enabled by
the CI credential command. The tracked deploy.yml → ci-host-deploy.sh →
deploy.sh path invokes install-stage-principal-cleanup.py from the verified
immutable release before stage_rollout. It atomically installs the root-owned
worker (0755) and supplied systemd units (0644), reloads systemd, enables/starts
the timer and verifies enabled/active state. Failure aborts rollout. No manual
sudo provisioning is required or permitted during review. The open wrapper refuses to operate
without an enabled and active timer. Never overwrite or delete the 0700 root-owned
/opt/services/canina/stage-principal-cleanup journal during deployments.
A journal entry is fsynced before provisioning and contains the exact session, random generation, creation SHA, bounded TTL and immutable cleanup deadline. Repeated opens fail rather than replace an intent or renew TTL. Close and the 30-second boot/periodic retry worker retain intents on lock contention, unavailable containers/DB, and relational deletion failures. Cleanup resolves the current Stage container ID once, verifies its cleanup capability, and authenticates against its current artifact SHA while retaining original session/generation ownership. Older artifacts without generation cleanup support fail closed; never roll back to one with a pending principal. Persisted expiry remains independently enforced at login, refresh and every scoped JWT request.
Revocation commits before private-handle removal; relational deletion is subsequent. A transaction acquires a generation/session-fenced row lock before touching related records. Failed deletion retains a revoked row and a pending retry intent, but no credential handle. Wrong ownership/generation never invokes the handle callback. The CLI requires the generation supplied by the private journal; no broader admin or production authority was introduced.
Verification performed in a new isolated worktree and disposable Docker network:
- Cleanup fence tests: RED (replacement generation was revoked; callback missing), then GREEN (2 tests).
- Python simulated worker tests: restart/redeploy, failed-delete retry, lock contention, immutable container ID/current artifact and old-CLI refusal (4 tests).
- Persisted account lifecycle plus delete/recreate access AND refresh regression.
- Actual CLI via ts-node with real disposable Postgres/Redis and HTTP adminLogin handler, injected PostgreSQL delete trigger failure: confirmed revocation, private handle removal, then successful repeated cleanup after trigger removal.
- TypeScript
tsc --noEmit: passed. - Full migration chain attempt on fresh disposable database: baseline failure in
20261020000000_add_blog_freshness_authorship (
blogsmissing). Not concealed. Independent migration test constructed the pre-Stage schema excluding all three new fields, then applied the EXACT committed 20261024090000 migration with psql ON_ERROR_STOP before exercising persisted lifecycle. Not db-push-only testing.
No live account, Stage/Production DB mutation, deployment, push, host service change, or retry of the previous pending-approval operation was performed.
Invocation after normal reviewed deployment and host prerequisite provisioning:
sudo -n env CI=true STAGE_TEST_APPROVAL=owner-authorized-stage-editorial bash /opt/services/canina/releases/<promoted-sha>/scripts/stage-test-principal-host.sh <promoted-sha> <unique-session> 600 open
Use the same command with close immediately after the authorized test.