Record access decisions, conversation creates and admin changes in the audit chain (Part B, #11) #53
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/rag-rust!53
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/11b-decision-events"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs #11 (Part B of two; does not close it, see "Not in this PR").
What this adds
Part B records, in the audit chain from Part A (#52), the events Part A deferred. Plan:
docs/superpowers/plans/2026-10-23-audit-decision-events.md.Enforcer::newtakes a requiredAuditSink.RequestAccess::permitsstays synchronous and tallies each decision by (resource kind, action, outcome); every protected route callsaccess.finish(result)before it builds a response, which writes one aggregatedaccess.decisionrow per key in one transaction (AuditSink::record_all).Enforcer::resource/search_scoperecord inline. Permit rows carryreturned_count, Deny rowsdecision_count; denials never carry a resource id; absent, foreign, forbidden and malformed ids each cost one write of the same shape. A sink failure on an authenticated request is the uniform 503 and nothing is served. Skip rules avoid double writes: upload decisions (registration/refusal rows), audit-route and conversation-create permits on success (their own rows), and a replayed upload writes one explicit permit row.Enforcer(not returned to clients); registration, refusal, decision and audit-read rows of a request share it. Admin routes mint their own.admin.change, reason derived on the server, actor's organization).identity_eventsstays; new nullableidentity_events.correlation_id(migration 0011) links the trails.decision_countmetadata key, and the audit reader now tolerates an unknown stored row (event: None, renderedunreadable) instead of failing the whole page.docs/security/audit.md("Access decision events", limits, deferrals) and the operations guides corrected (stale statements about audit and unmounted admin routes fixed).Claims and limits (please read)
__system__would let unauthenticated callers flood one global chain), session/policy-source failures, requests that make no decision (an empty list page, query-parsing 400s), admin read endpoints, passkey/login/registration/recovery-code events, and denied audit requests only where no organization is known.audit_append. With a working sink, no response bytes or headers change.returned_countcounts permitted decisions (history counts the conversation plus each permitted message, including one the source check later withholds).unavailablerow for a request already answered 503 (loader or context failure).Not in this PR
Producers for policy/marking/crypto/audit-config/feedback events (the event kinds exist), retention/pruning, keyed MAC/anchoring, dual control, rate limiting, a response-visible correlation id, recording of anonymous requests, and an end-to-end test that
admin.changerows appear through the audit read/export API and that the admin route's correlation id reaches the audit row.Verification (head
bd1b0a0)cargo fmt --checkandcargo clippy --workspace --all-targets --locked -- -D warningsclean;cargo test --workspace --locked181 passed, 0 failed. PostgreSQL suites (bash scripts/test-postgres.sh --local): I did not get one uninterrupted green local run on the final head. The first full run stopped inaudit_decisions_postgres(3 of 15 tests failed in fixture setup atmigrate(...); 15/15 twice standalone afterwards); a second full run passed 16 of 17 suites and failed 1 of 6 inrevocation_postgresat the passkey login helper (6/6 on a later rerun). The implementers' per-round full runs on earlier heads were green. The local Docker Postgres holds ~2,000 leakedrag_test_*databases (a test that panics leaks its database), which slows setup and is probably the cause; CI is the check that matters. The coverage script was not run locally.Known local flakes unrelated to this change: the Docker VM clock jitters ±100 ms against the host (registry
created_atassertion now tolerates 5 s), passkey/webauthn helper tests,audit_postgres::twenty_concurrent_appends, and one unexplainedadmin_postgres403 (likely mixed application/database clocks aroundvalid_from).Synthetic data only; no production, classified-deployment, assurance or PQC claim.
🤖 Generated with Claude Code