feat(audit): WORM signed export — AuditExporter + POST /v1/audit/export (Step 6.6b) - #154
Merged
Merged
Conversation
…rt (Step 6.6b)
Complete Step 6.6 with immutability at rest. AuditExporter (rag_core.audit_export,
pure stdlib) builds a self-verifying AuditExport bundle with two independent
integrity checks: content_hash (SHA-256 over the canonical events — pins the exact
set + order, recomputed on verify so any add/remove/edit is caught even without
the secret) and signature (HMAC-SHA256 over "<timestamp>.<content_hash>",
mirroring the Step 5.1 ProvenanceSigner scheme). verify() returns
{signed, content_ok, verified, reason}; chain_verified attests the source store's
whole-log chain was intact at export time.
POST /v1/audit/export is tenant-scoped (the caller's events only — same isolation
as GET /v1/audit); ragctl audit exports the whole log in-process. Because
integrity is content_hash + HMAC over whatever events are included (not the global
chain head), the same verify() works for both, and the bundle verifies offline —
the artifact an operator archives to immutable storage (S3 Object Lock).
Opt-in signing via cfg.audit.export_secret (env-interpolated); empty → unsigned
but content-hashed. Adds AuditExport / AuditExportSignature /
AuditExportVerification core types + ragctl audit (export/verify round-trip).
Deferred: a durable live-store backend + auditing beyond corpus.route.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes Step 6.6 — Immutable audit log (6.6a shipped the read API + chain verification in #153). 6.6a's hash chain gives tamper-evidence for the live log; 6.6b adds immutability at rest via a self-verifying signed export.
AuditExporter(rag_core.audit_export, pure stdlib) builds anAuditExportbundle with two independent integrity checks:content_hash— SHA-256 over the canonical serialisation of the events (pins the exact set + order; recomputed on verify, so any add/remove/edit is caught even without the secret).signature— HMAC-SHA256 overf"{timestamp}.{content_hash}", mirroring the Step 5.1ProvenanceSignerscheme.verify()→{signed, content_ok, verified, reason}withreason∈ok/unsigned/no_secret/content_mismatch/signature_mismatch.chain_verifiedattests the source log's whole-log chain was intact at export time.POST /v1/audit/exportis tenant-scoped (the caller's events only — same isolation asGET /v1/audit);ragctl auditexports the whole log in-process. Because integrity iscontent_hash+ HMAC over whatever events are included (not the global chain head), the sameverify()works for both, and the bundle verifies offline — the artifact an operator archives to immutable storage (S3 Object Lock).cfg.audit.export_secret(env-interpolated, mirrorsprovenance.signing_secret); empty (default) → content-hashed but unsigned bundle.Scope / deferred: a durable live-store
AuditStorebackend (Postgres / append-only ledger) and expanding what gets audited beyondcorpus.routeremain follow-ups.Tests & gates
tests/audit/test_export.py— content_hash determinism, sign→verify, unsigned, no_secret, wrong-secret, content tamper → content_mismatch, signature tamper → signature_mismatch, empty); gateway (apps/gateway/tests/test_audit.py— tenant-scoped + signed + offline-verifies + cross-tenant isolation + unsigned + disabled→404 + no-auth→401);ragctl auditround-trip + file verify.tests/ packages/2328 passed, 1 skipped; gateway suite 281 (verified +5 vsmain, no regression). Green: ruff,mypy --strict(299 files), RAG001, policy-coverage, log-schema, schema-drift + openapi-drift (dist/schemas+dist/openapi.*+dist/rag.schema.*regenerated).Documentation
Test plan
uv run pytest tests/ packages/ -m "not integration"— 2328 passed, 1 skippeduv run pytest apps/gateway/tests— 281 passedmypy --strict(299 files) + RAG001 + policy-coverage + log-schema + schema/openapi-drift🤖 Generated with Claude Code