Repository navigation
backup: durable intents for pairing, pin and deposit (§9.3) - #25
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-25, 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 |
Spec §9.3: an external effect commits an operation_intents row before it starts, and its audit record is the completion append in the same transaction that ends the intent. The record is noted on the intent first, so a failed append fails the action (500, ErrNotRecorded) and is replayed when the intent is reconciled; nothing is only logged. Startup and every deposit (under the backup-run lock) settle pending deposits; pairing and pin settle intents older than 20 minutes. A pending intent ends at its noted outcome or outcome_unknown, and a later successful deposit supersedes unknown ones. A lost KyRecovery pairing answer ends outcome_unknown. Settings publication commits the exempt-network list with its record; backup export sends no capsule without its record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8d0f1cb to
338d5d5
Compare
f1a8806 to
7716dec
Compare
Security review P2: reconciliation replayed a persisted outcome no one authenticated, so a database writer could have a forged record appended under the chain key. Notes now carry an HMAC binding operation ID, kind, subject, state and record; a failing note ends outcome_unknown with operation.outcome_rejected and is never appended. PR Reviewer Guide: settling is one conditional UPDATE, and reconciliation moves only pending intents, so concurrent reconcilers append one record per intent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed in fa9213a. Security P2: noted outcomes carry an HMAC (key derived from the audit key) binding operation ID, kind, subject, state and the exact record; reconciliation replays only authenticated notes, and a failing one ends |
… into kyguard/intents Drops audit-chain's "scope of this PR" decision 19: this PR builds what it deferred. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up the stack's merge commits as pushed. No content change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reconciler settles only if the note it read is unchanged, so a note written after its read stays pending and is replayed, not stranded as outcome_unknown. The elected worker reconciles pairing and pin intents older than StaleIntent each tick, so one too young at startup is not left pending until the next request of its kind. 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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Joins this stack's operation_intents with the one #8's merged migration 100 creates. Migration 16 is gone; migration 200 rebuilds the table as the superset (outcome, failed, (kind, state) index), rows kept. The KyRecovery pairing intent is kind recovery_pairing, so the broker sweep and this reconciler never settle each other's intents. A test fails on a registry out of version order. DECISIONS 19d. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The broker stack and this one each declared IntentPending and IntentComplete. store.go keeps the states; IntentOutcomeUnknown stays as the broker's alias of IntentUnknown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Migration 17 (cli_login_codes) stays; migration 16 is gone (#25 moved the intents table to migration 200). migrate_postgres keeps both lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Security review: a writer without the audit key could reset a settled intent and replay its still-valid note into a second success record (and, for a deposit, supersede unknown deposits). Completion records now name their operation first; replaying a note checks, in the settling transaction, for a completion record of that operation in the chain and ends outcome_rejected (note_consumed) if one exists. Every settle clears the note with its record. Guide (Lost Completion): the owning process notes its outcome on an intent reconciled outcome_unknown too, and reconciliation replays noted unknown intents, so a failed append there is not lost. A reconciler settles only from the state it read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In one line: KyRecovery pairing claims, recovery-key pins and deposits now leave a durable record before they start. A crash or a failed audit write can no longer lose what happened.
What changed
operation_intentstable (migration 16). A pairing claim, a pin and a deposit each commit apendingrow before the effect starts.complete,failedoroutcome_unknown). The record is noted on the intent first. So when the append fails, the action answers 500 instead of success, and the record is appended later. Nothing is only logged any more (DECISIONS 19 replaced).backup-runlock) settle pending deposits first. Pairing and pin settle intents older than 20 minutes. A settled intent ends at its noted outcome, elseoutcome_unknownwith a criticaloperation.outcome_unknownrecord.outcome_unknowndeposits. Every run seals a fresh capsule, so lost bytes are never replayed.outcome_unknown(the code may have been spent).Review this
internal/store/intents.go:SettleandReconcile. The note-then-settle order is what keeps a failed append from being lost, andsettleis the supersede rule.internal/backup/run.go: where the deposit intent is taken (after collecting, only when paired) and how the run's outcome maps to a state.internal/api/backup_handlers.go: the pairing and pin handlers. Each failure picksfailedoroutcome_unknown.Checked: full suite with
-race, plus the FIPS profile, on SQLite and PostgreSQL 17 at 7716dec. All 8 mutations below fail their tests.Not checked: the e2e compose suite locally (Major has no free Docker address pool; it runs in CI).
Decided for you: an extra
failedstate and anoutcomecolumn beyond the spec's states (DECISIONS 19b). A 20-minute staleness bound for pairing and pin, which hold no shared lock (19a).Review fixes (fa9213a): a noted outcome is authenticated (HMAC over operation ID, kind, subject, state, record) before reconciliation replays it, and a failing note ends
outcome_unknownwithoperation.outcome_rejectedand is never appended (security P2). Settling is one conditionalUPDATE, and reconciliation moves onlypendingintents, so concurrent reconcilers append once (Guide). Checked at fa9213a: race and FIPS suites on SQLite (k83) and PostgreSQL 17 (k82), exit 0.You need to: review. Held unmerged by rule. At the stack join, drop the duplicate
operation_intentstable from the broker stack's migration 100.§13 Phase 0 checklist: Chained audit append on both drivers, transaction rules, fixed inherited paths (§9.3): the transaction rules and inherited paths that #19 left. Acceptance 12, the external-effect clause.
Detail
Mutation table (each mutation makes the named test fail)
Beginin the collect callbackTestStartupReconcilesADepositLostInACrashbackup.RunTestRetriedDepositReconcilesFirstAndSupersedesTestReconcileEndsLostDepositsAndASuccessSupersedesThemTestFailedCompletionAppendIsReplayedFromTheIntentReconcileIntentsTestStartupReconcilesADepositLostInACrashTestPinKeySettlesItsIntentoutcome_unknownfailedTestLostPairingClaimEndsOutcomeUnknownUpdateSettingsTestExemptNetworksRollBackWithTheirAuditTestReconcileRejectsAForgedNote(edited and written)outcome_unknowntooTestConcurrentReconcilersSettleOnce(30 records for 10; both drivers)All run on K hosts (k83), SQLite.
Checks at 7716dec
gofmt,go vet,go build,go test -race -count=1 -p 2 ./...and the same underGODEBUG=fips140=on: SQLite pass (k82), PostgreSQL 17 pass (k83). An earlier head failed on PostgreSQL only: the snapshot test seeds every table and had nooperation_intentsrow. That is fixed, and this head is rebased on the sso: identity by (issuer, subject); fresh, per-app sign-in #7/auth: pending SSO sessions and TOTP step-up (§7.3) #17–store: chained audit append on both drivers (§9.3) #19 review fixes.Stack
#1 → #3 → #7 → #17 → #18 → #19 → this.
Stack merge (hawthorn fix-auth-3): head 9dd679a merges
kyguard/audit-chain(plain merge commits, no rebase; 005efec merged it first, and 9dd679a 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): Guide "Unreconciled Intents" and "Lost Outcome"
outcomeis still the note it read (AND outcome = ?on the conditionalUPDATE). A note written after the read leaves the intentpending, and the next pass replays it instead of stranding it asoutcome_unknown.backup.ReconcileStaleevery tick. It settles pairing and pin intents older thanStaleIntent, so an intent too young at startup no longer waits for another request of its kind. Startup uses the same function. DECISIONS 19a is updated (0e0092d).outcome = ?conditionTestReconcilerDoesNotStrandANoteWrittenAfterItsReadReconcileStalefrom the worker tickTestBackupLoopReconcilesStalePairingAndPinIntentsAffected packages (
store,backup,cmd/server,api) pass with-raceon k82. Also mergeskyguard/audit-chain(main, #17, #18).Round 4b (hawthorn): joined with #8's
operation_intentsmainnow has Broker listener, CA and pairing (§4.1) #8's migration 100, which createsoperation_intents. This PR's migration 16 created the same table, so a fresh database would refuse to start. Migration 16 is gone. Migration 200 (kyguard_intents_outcome, inmigrations/kyguard_intents.go) rebuilds the table, keeping its rows, as the superset this PR needs:outcome, thefailedstate and a(kind, state)index. SQLite cannot change a CHECK in place, hence the rebuild. Versions from 200 keep the auth stack clear of the broker stack's 100+.kind = 'pairing': a broker pairing in Broker listener, CA and pairing (§4.1) #8, a KyRecovery pairing claim here. Each reconciler would have settled the other's intents (Broker listener, CA and pairing (§4.1) #8's startup sweep runs onpairing). The KyRecovery claim is nowrecovery_pairing.IntentPendingandIntentCompleteconstants are now one set, andIntentOutcomeUnknownstays as an alias.TestRegistryIsAscendingfails if file-orderinitappends ever put a lower version after a higher one. Note for the reporting stack's join:kyguard_reporting.gosorts afterkyguard_intents.go, so its 102 and 103 would land after 200 and this test will flag it.BeginIntent(..., "pairing", ...)in the handlerTestLostPairingClaimEndsOutcomeUnknownReconcileStaleonpairingTestBackupLoopReconcilesStalePairingAndPinIntentsTestRecoveryAndBrokerPairingIntentsStaySeparateChecks: 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.
Round 4c (hawthorn): security P2 and Guide "Lost Completion"
internal/store/intents.go) (9763317): a noted outcome can be replayed into the chain only once. Completion records now start withoperation_id=<id>. Replaying a note checks, in the settling transaction, for a completion record of that operation already in the chain, and if one exists it ends the intentoutcome_rejected(reason=note_consumed). Every settle clears the note in the same transaction as its record.outcome_unknown, and reconciliation replays noted unknown intents, so a failed append there is no longer lost. A reconciler now settles only from the exact state it read, so two concurrent reconcilers still append once.TestAConsumedNoteIsNotReplayedAgainpendingintentsTestANoteOnAnUnknownIntentIsReplayedoutcome_unknown)TestConcurrentReconcilersSettleOnceChecks: race + FIPS, SQLite and PostgreSQL 17, at the bottom (#19 @ 896dc31: SQLite on Major with every K host busy, exit 0; PostgreSQL own container, exit 0) and the top (#28 @ 5909f87: SQLite k81 exit 0, PostgreSQL own container exit 0).
🤖 Generated with Claude Code