Add the tamper-evident audit chain, sink and authorized reader (Part A, #11) #52
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!52
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/11-audit-trail"
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 A of two; does not close it, see "Not in this PR").
What this adds
crates/audit: typed, closed audit events and theAuditSink/AuditReaderports. No free-text field exists, so content cannot be put in by construction; denial events cannot carry a resource id; config-change events require actor and reason.audit_append,audit_verify,audit_checkpoint,audit_read; built-insha256()under a per-organization advisory lock; database clock authoritative).rag_apploses every table privilege onaudit_eventsand can only executeaudit_append; a statement-level trigger (ENABLE ALWAYS) refuses UPDATE/DELETE/TRUNCATE; the startup guard rejects any extra privilege.denial_codecolumn; storedevent_type/decisionspellings are unchanged.rag_audit_readerrole with its own startup guard andAUDIT_READER_DATABASE_URL; routesGET /api/v1/audit/events,/verify,/exportauthorized through theEnforcerwithReadAudit(andExport), neveris_admin. Reads and exports are themselves audited before answering. Export is capped at 10,000 rows (413) and fails closed (503) if it cannot deliver the head it read. No development account gets either action by default.docs/security/audit.md(event fields, the chain and its limits, outage policy, reader model, "Deferred and open");postgres.md,documents.md,authorization.md,conversations.mdcorrected and cross-linked. Plan:docs/superpowers/plans/2026-10-23-audit-trail-chain.md.Claims and limits (please read)
rag_audit_readercan read any scope; per-organization isolation is enforced in the API layer (scope comes from the verified subject), not by the database.events/exportreturn 503 for that organization (verify still works); a Part B design input.Not in this PR (Part B / later)
Access-decision events from the
Enforcer, the conversationAUDIT(#11)markers, admin events, a request-level correlation id (audit rows currently get a fresh one), recording of denied audit requests and of the early 404 exits in the document routes, producers for policy/marking/crypto/audit-config/feedback events (the kinds exist), retention/pruning, keyed MAC/anchoring.Verification (head
6573933)cargo fmt --checkandcargo clippy --workspace --all-targets --locked -- -D warningsclean;cargo test --workspace --locked161 passed, 0 failed;bash scripts/test-postgres.sh --localexits 0 with every suite green, includingaudit_postgres(20),audit_reader_postgres(27),audit_api_postgres(8). The coverage script was not run locally; CI will run it (new suites registered).Known flakes, unrelated to this change:
documents_registry_postgres::active_attributes_hides_quarantined_and_returns_latest_activefailed once (the database container's clock reads ~150 ms ahead of the host and the test compares the two; it passed on reruns and onmain), and a passkey login helper failed intermittently in three suites only while overlapping background runs held the cluster; the clean run did not reproduce it.Synthetic data only.
🤖 Generated with Claude Code