Repository navigation
store: chained audit append on both drivers (§9.3) - #19
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process: ⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵🧪 PR contains tests⚡ No major issues detectedAdvisory only: this comment never gates the pull request. |
Security review - clearedDetail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-19, where it is readable by the operator and expires seven days after the last post. gpt-6.1-sol using security-audit on behalf of Yoshi |
Autonomous review - 1/1 personas cleared
Merging remains a human decision; this bot never approves. gpt-6.1-sol using security-audit on behalf of Yoshi |
Implement spec §9.3: audit_records gains seq, prev_hash and hash, and audit_chain_head (unseeded; empty means genesis) is the anchor. One writer, appendAudit, runs inside the caller's transaction: it takes the PostgreSQL advisory lock (SQLite transactions now begin immediate), resumes the chain from the head record and inserts record and head together. The key is HKDF(encryption key, kyguard:auditchain). revokePasswordGrants, SCIM create and adopt, SSO provisioning, role changes and SCIM adoption now audit in their own transaction through store.WithAudit; back-channel logout fails on a failed audit write. No LogAudit result is discarded any more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Security review P2: verification now rejects a stored field that differs from its canonical rendering, which the HMAC covers, instead of re-sanitizing it into a match. PR Reviewer Guide: records written before migration 15 are chained when the store opens, so the first append after an upgrade succeeds; PostgreSQL verification reads head and records in one REPEATABLE READ snapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
283d936 to
54bd0f2
Compare
8d0f1cb to
338d5d5
Compare
|
Fixed in 338d5d5. Security P2: verification rejects any stored field that differs from its canonical rendering ( |
Security review P2: every keyed open signed any unchained row, so a database writer without the key could have a fabricated record authenticated at the next start. Only the open that applies migration 15 now chains the records it found; a row that appears unchained later stays unchained and verification reports it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Security P2 (legacy signing) fixed in f0d21d4: migrations.RunApplied reports what an open applied, and legacy rows are chained only by the open that applies migration 15. |
PR Reviewer Guide: a start interrupted after migration 15 committed but before chaining left the older records unchained for good. The migration runner now takes per-version hooks run in that version's transaction, and the store chains the records there, so schema and chain commit together; without the key such a database refuses to migrate. The store gets its chain key at construction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Guide (interrupted upgrade) fixed in 13abb62: |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/DECISIONS.md
…t-chain Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings main (#8's broker tables) in. migrate_postgres.go keeps both table lists; DECISIONS keeps both sides in number order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#8's auditTx inserted audit_records directly, outside the chain, so on this branch every broker record (bundle import, pools, pairing, intent sweeps) left VerifyAuditChain failing. auditTx now calls appendAudit, in the caller's transaction, as its own comment anticipated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merger (saltmarsh-merge): closing and reopening right away so CodeQL runs now that the base is |
In one line: The audit log is now a hash chain with one writer inside the caller's transaction. A failed audit write fails the action, and an edited or truncated log no longer verifies.
What changed
audit_recordsgainsseq,prev_hashandhash.audit_chain_headis the anchor: it is not seeded, and an empty head means genesis.appendAudit, runs inside the caller's transaction. On PostgreSQL it holdspg_advisory_xact_lock; SQLite transactions now beginimmediate. It resumes the chain from the head record and writes record and head together.HKDF(encryption key, "kyguard:auditchain"). Without it, no audit write succeeds.revokePasswordGrants(password change), SCIM create and adopt, SSO provisioning and role changes audit in their own transaction (store.WithAudit). NoLogAuditresult is discarded any more, and back-channel logout fails on a failed audit write.VerifyAuditChainchecks the whole log against the head.Review this
internal/store/auditchain.go: the append. Locking and the genesis case decide whether two writers can fork the chain.internal/store/factory.go_txlock=immediate: this changes every SQLite write transaction.Checked:
go test -raceand the FIPS profile, full suite, SQLite and PostgreSQL 17 at this head. Mutation table below.Not checked: the external-effect half of acceptance 12 (
operation_intents,outcome_unknown). It is the next PR in this stack. Until then a failed audit write after a backup run (recordRun) is only logged (DECISIONS 19), and the next PR removes that.You need to: review. Held unmerged by rule.
§13 Phase 0 checklist: Chained audit append on both drivers, transaction rules, fixed inherited paths (§9.3), except intents. Acceptance 12, except the intent clauses.
Detail
Mutation table (each mutation makes the named test fail)
TestConcurrentAuditWritersMakeOneChain(genesis race)revokePasswordGrantsTestAuditChainCoversPasswordChangesAndDetectsTamperingTestAuditChainCoversPasswordChangesAndDetectsTampering(truncation)TestFailedAuditRollsBackTheActionhawthorn ran these at the pre-rebase head 7c86931. Since then the branch moved only by rebasing.
TestAuditWriteNeedsTheChainKeyandTestSnapshotWithoutAnAuditHeadcover the key floor and the unseeded head.Checks at 8d0f1cb
gofmt,go vet,go build,go test -race -count=1 -p 2 ./...and the same underGODEBUG=fips140=on: SQLite pass (Major, kslot; every K host was busy); PostgreSQL 17 pass (Major, own postgres:17-alpine container). Exit 0 on both.Stack
#1 → #3 → #7 → #17 → #18 → #19 (this).
Review fixes (hawthorn fix-auth)
TestNoncanonicalStoredFieldBreaksTheChainTestRecordsFromBeforeTheChainAreChainedAtOpenTestVerifyWhileWritersAppendChecked at 338d5d5: race and FIPS suites on SQLite (Major) and PostgreSQL 17 (Major, own container), exit 0.
Review fixes, round 2
TestRecordsFromBeforeTheChainAreChainedOnceChecked at f0d21d4: race and FIPS suites on SQLite (Major) and PostgreSQL 17 (k82), exit 0. #25–#28 sit on 338d5d5; the root thread holds restacks, so they do not have this commit yet.
Review fixes, round 3
TestRecordsFromBeforeTheChainAreChainedOnceChecked at 13abb62: race and FIPS suites on SQLite (Major) and PostgreSQL 17 (Major, own container), exit 0.
Stack merge (hawthorn fix-auth-3): head bc26fc3 merges
kyguard/routes(plain merge commits, no rebase; 9192b01 merged it first, and bc26fc3 adds a content-free merge of the pushed commit below), so this PR carries #7's fail-closed SSO sign-in (9220dd7) and every fix below it. The only conflicts were indocs/DECISIONS.md, and both sides were kept. Go vet passes at this head; CI runs the suites.Round 4 (hawthorn): main merged; broker audit records chained
kyguard/routes, which carriesorigin/mainwith Broker listener, CA and pairing (§4.1) #8's broker stack.migrate_postgres.gokeeps both table lists, and DECISIONS keeps both sides.auditTxinsertedaudit_recordsdirectly, outside the hash chain. On this branch every broker record (bundle import, pools, pairing claims, intent sweeps) leftVerifyAuditChainfailing.auditTxnow callsappendAuditin the caller's transaction, as its own comment anticipated.auditTx(direct insert)TestExpirePendingIntentsLeavesYoungOnes(now verifies the chain)Checks: race + FIPS on SQLite and PostgreSQL 17, at the bottom (#18 @ bd2fb58: SQLite k81 exit 0, PostgreSQL own container exit 0) and the top (#28 @ 0cb6d83: SQLite k82 exit 0, PostgreSQL own container exit 0). Affected packages were also run at this head on k82.
🤖 Generated with Claude Code