fix(auth): persist generation-fenced Stage principal cleanup retries

This commit is contained in:
devops authored and devops committed 2026-10-24 13:04:35 +00:00
1 parent 80a2e188cf
commit 70a5449d35
13 files changed
+323 -44

No files matched your search

@@ -0,0 +1,52 @@
# 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. Deployment must first install the reviewed worker as
`/opt/services/canina/stage-principal-cleanup.py` (root:root 0755), install the two
supplied systemd units under `/etc/systemd/system`, daemon-reload, and enable/start
`canina-stage-principal-cleanup.timer`. This is a promotion prerequisite, NOT an
instruction to run these actions 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 (`blogs` missing). 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.
+1 -9
View File
@@ -31,15 +31,7 @@ role checks remain unchanged. The canonical default administrator is untouched.
tests. This revokes persisted authentication BEFORE relational deletion and
removes the private credential file. Close is idempotent when absent.
A host systemd timer is armed before creation for independent TTL cleanup even
if CI disappears. Persisted expiry is checked at login, refresh, and every JWT
request, so killing the timer cannot extend access. Failed cleanup leaves revoked
credentials. Cleanup timer is pinned to the creation SHA: finish/close before
redeploy; if redeployed, use the approved CI recovery session with its recorded
ownership rather than changing an unrelated account. A collision with the exact
ID, email or mobile fails closed; an owned retry with the same secret cannot
extend expiry. The test principal is limited in JWT strategy to task reads,
proposal creation, Gate1 decisions and editorial failure. All other paths deny.
A durable root-owned host cleanup journal and boot/periodic systemd retry worker must be provisioned before opening a session. Cleanup follows the current Stage artifact but retains the original exact session and generation fence; persisted expiry cannot be extended. See [cleanup verification and promotion prerequisites](stage-principal-cleanup-verification.md). No live host services are changed by review tests.
## Verification