Repository navigation
feat(audit): append-only, hash-chained audit log (M3a, #107) - #137
Merged
Merged
Conversation
Upgrades each tenant's audit_log in place (product owner's decision, 28 Oct) instead of adding an audit_events table. - Migration 0006 adds actor, tenant_schema, before_value, after_value, prev_hash and row_hash. A BEFORE INSERT trigger serialises writers with an advisory lock, assigns the id under it, and links each row to the previous one. Existing rows are chained during the upgrade. - Triggers reject UPDATE, DELETE and TRUNCATE for every role, owner included. The hash chain exposes a row changed or removed with the trigger disabled. - The actor is the signed-in username, or "api_key" for the shared key. Password resets now record the admin as the actor instead of in the mode column. - GET /api/audit/verify recomputes the chain (tenant_admin, auditor). CI replica 318/0/0, evals 26/26, make lint and make health clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019YPoXzBSj89ZHgw7nfTmbB
This was referenced Oct 28, 2026
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.
Refs #107. This is part M3a of ART Milestone 3. The parts and the product owner's decisions of 28 Oct are on #107.
What it does
audit_login place (decision 1):actor,tenant_schema,before_value,after_value,prev_hashandrow_hash.api_keyfor the shared key.tenant_scopesets it the same way it sets the tenant schema. Password resets now record the admin as the actor, which retires the stopgap of writing it intomode.GET /api/audit/verify(tenant_admin, auditor) recomputes the chain. It returns{rows, intact, firstBadId}./api/audit/logentries now includeactor.What it doesn't do yet
test_a_changed_row_breaks_the_chain_at_that_rowdoes exactly this.Verification
make lint(flake8, bandit)make healthtests/test_audit_append_only.pyI broke the code in three places to check that the tests catch it. Each time, the expected test failed:
firstBadId: 3)prev_hashlink checkAlso changed:⚠️ Partial.
test_migrationsandtest_tenant_isolationnow expect head0006. The VCRM BR-35 row is updated, and its status staysGenerated by Claude Code