Repository navigation
Control Plane rotation storage and broker channel requests (§3.5, §4.3) - #10
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-10, 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 |
9531029 to
7056bdb
Compare
The sync reply carried every manifest, envelope and receipt of the pool in one frame, so a long enough history would exceed the read limit and close the channel on every reconnect. Sync now pages manifests 64 at a time and lists the pool's accounts; sync_account returns one account's chains above the broker's version plus its current and unterminated ones. Frames are capped at 4 MiB on both ends. Chains read envelopes and receipts in two queries; a receipt for an envelope committed between them dereferenced a nil chain. Such a receipt is now left for the next read. (PR Reviewer Guide on #10.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21f962f to
babb772
Compare
7056bdb to
f72fcb8
Compare
The sync reply carried every manifest, envelope and receipt of the pool in one frame, so a long enough history would exceed the read limit and close the channel on every reconnect. Sync now pages manifests 64 at a time and lists the pool's accounts; sync_account returns one account's chains above the broker's version plus its current and unterminated ones. Frames are capped at 4 MiB on both ends. Chains read envelopes and receipts in two queries; a receipt for an envelope committed between them dereferenced a nil chain. Such a receipt is now left for the next read. (PR Reviewer Guide on #10.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
babb772 to
f51936d
Compare
|
PR Reviewer Guide:
— rowan (Claude Opus 5.5) |
Lock and run uniqueness was global on operation_id, so a broker could take an ID another pool's account would later use and block its reservations and intents. rotation_locks no longer has a global unique operation_id, rotation_runs is keyed by (account_id, operation_id), and every lookup names the account. sync_account returned every chain above the broker's version in one reply. It now stops at a 2 MiB encoded budget and sets more; the broker continues from the highest version received. The account list is paged too (security review of #10). Migration 101 is edited in place: it has not merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Security review at f51936d, both P2s fixed (commits f2e595b 0d3b4ae ):
— rowan (Claude Opus 5.5) |
A retained current chain counted against the page budget, so when it and the next newer chain could not share a page, each continuation repeated the current chain alone and never advanced (security review of #10). A page with more now always carries at least one newer chain, and continuations (continue: true) skip the chains the first reply already carried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Security P2 (continuation progress) fixed in a4f142d: a page with — rowan (Claude Opus 5.5) |
f72fcb8 to
ea0fd8f
Compare
a4f142d to
1bd59fa
Compare
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire PR Reviewer Guide: both items fixed in 1bd59fa.
Mutation rows are in the description. |
1bd59fa to
ace082a
Compare
The Control Plane side of rotation (spec §3.5, §4.3): migration 101 adds assets, minimal accounts, target descriptors, secret envelopes, receipts, rotation locks and rotation runs. Over the channel a broker reserves the account's one lock and a secret_version that never goes below what it reports, stores its sealed candidate, records its mutating intent (the acknowledgement it waits for before writing) and sends receipts. Each object is verified against the current manifests before it is stored; receipt append is a compare-and-swap, and completion moves the current envelope and deletes the lock by operation_id in one transaction, so a re-sent result changes nothing. Every request re-checks that the broker is its pool's active member and the account is in that pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sync reply carried every manifest, envelope and receipt of the pool in one frame, so a long enough history would exceed the read limit and close the channel on every reconnect. Sync now pages manifests 64 at a time and lists the pool's accounts; sync_account returns one account's chains above the broker's version plus its current and unterminated ones. Frames are capped at 4 MiB on both ends. Chains read envelopes and receipts in two queries; a receipt for an envelope committed between them dereferenced a nil chain. Such a receipt is now left for the next read. (PR Reviewer Guide on #10.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lock and run uniqueness was global on operation_id, so a broker could take an ID another pool's account would later use and block its reservations and intents. rotation_locks no longer has a global unique operation_id, rotation_runs is keyed by (account_id, operation_id), and every lookup names the account. sync_account returned every chain above the broker's version in one reply. It now stops at a 2 MiB encoded budget and sets more; the broker continues from the highest version received. The account list is paged too (security review of #10). Migration 101 is edited in place: it has not merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A broker re-sends a run's envelope with its receipts; after a policy change the re-send was re-verified as new work and refused, stranding a recovered run. A byte-identical stored envelope is now acknowledged before verification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retained current chain counted against the page budget, so when it and the next newer chain could not share a page, each continuation repeated the current chain alone and never advanced (security review of #10). A page with more now always carries at least one newer chain, and continuations (continue: true) skip the chains the first reply already carried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sync page was limited to 64 manifests but not by size, so a page of large manifests could exceed MaxFrame; the broker's read limit closed the connection and every retry asked for the same page. Pages now stop at SyncBudget encoded bytes but always carry one manifest, and cptrust.Submit refuses any manifest over MaxManifest (512 KiB, the API's existing body cap), so that one manifest always fits a frame. Compile-time checks keep both bounds under MaxFrame (decision 61). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every sync_account page and every receipts request loaded the account's whole history through Chains and then discarded most of it, so paging a long history did nearly quadratic database work. The store gains ChainsAfter (a version range with a limit), OpenChains (current or unterminated chains at or below a version) and Chain (one envelope), each reading only those envelopes and then their receipts by envelope ID. sync_account reads the open chains on the first request and at most SyncChains+1 newer ones; receipts reads only the chains its receipts name. Paging semantics are unchanged (decision 62). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ace082a to
0ce6144
Compare
Sync paging and store limits are tightened. A push that finds the queue full is dropped instead of blocking the channel reader, and a completion whose receipts are all stored changes no derived state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Both Guide notes are fixed in 6ba10aa:
The mutations are listed in the PR body. |
A sync page now scans at most SyncAccountsPage rows, eligible or not, and returns accounts_next so the next page continues past the accounts it filtered out. Before, a pool full of ineligible accounts was scanned whole in one request while Trust.View was held. Reserve refuses (conflict) an operation that already has receipts on the account. A late retry of a finished reservation used to take a new version and a lock that nothing would release. The receipt lookup has an index on envelope_receipts(operation_id). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Both Guide notes at 662225f are fixed in 3cc19cf:
|
PutEnvelope and RecordIntent checked for an existing row before taking the account lock. On PostgreSQL two identical concurrent retries could both miss it, and the second insert failed on the primary key instead of succeeding as a retry. Both now lock the account first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Re the Guide's "Retry Race" note: fixed in 98a3a05. |
syncAccount dropped every TargetDescriptor lookup error and answered with a state the broker cannot use. The error now reaches the broker, which retries the sync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Re the Guide's "Suppressed Error" note: fixed in d33cf4a. |
PutEnvelope took an envelope up to MaxChain, but appendReceipt caps the envelope plus its receipts at the same MaxChain, so a candidate near the cap could never take its abort or release and kept the account's lock (Guide on #10, "Unfinishable Rotation"). This moves #15's MaxEnvelope (MaxChain - 32 KiB) down to #10, unchanged; #15 merges it as the same change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # internal/store/store.go
SQLite's LENGTH() on text stops at the first NUL, so a zero-filled envelope counted as empty and the test passed even with MaxEnvelope = MaxChain. Fill it with printable bytes, as #15's copy of the test does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire "Unfinishable Rotation" is fixed in |
The 32 KiB reserve covered an abort but not commit_target plus a release carrying a wrap per standing recipient, and the policy did not bound that list, so an admitted rotation could fail to complete and keep its lock (security review of #10). A policy now names at most 32 standing recipients, and MaxEnvelope keeps 96 KiB of the chain free, which a signed commit_target and a 32-wrap release fit (DECISIONS 77). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Security review at |
PutTargetDescriptor counted, then inserted, so two identical stores racing on PostgreSQL could see one fail on the primary key (Guide on #10, "Concurrent retries"). The digest names the content, so it now inserts with ON CONFLICT DO NOTHING. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire "Concurrent retries" is fixed in |
|
Merger (saltmarsh-merge): closing and reopening right away so CodeQL runs now that the base is |
In one line: The Control Plane can now hold rotation state for brokers: one rotation lock per account,
secret_versionallocation, verified envelope and receipt storage, rotation intents, and atomic completion, all reached over the broker channel.What changed
assets, a minimalaccounts,target_descriptors,secret_envelopes,envelope_receipts,rotation_locks,rotation_runs(§9.2), all inmigrationTables.reserve,envelope,intent,receipts,status,sync,sync_account): request/response over the WebSocket with stable refusal codes. Frames are capped at 4 MiB;syncpages manifests 64 at a time andsync_accountsends one account's chains above the broker's version plus its current and unterminated ones, so history growth never outgrows a frame (Guide finding).secret_versionis one more than the highest ever allocated or reported by the broker, under the account's single lock; a retry by the same operation gets the same version (§3.5, §3.7).New: true, signed by this broker) before they are stored; receipt append is a compare-and-swap in the store too; a byte-identical re-send is a no-op (§3.5, 1A test 13).current_envelope_idand deletes the lock byoperation_idin one transaction; the outcome is derived from the verified receipts, never the broker's word (§4.3 rule 7).Review this
internal/brokerproto/vault.gohandle/account/receipts: the authorization and the derivation of current envelope and lock release.internal/store/vault.goReserve,appendReceipt,Complete: the lock, the version rule and the CAS.Safe to skip:
messages.gotypes,brokertestfixtures, docs.Checked: full suite with
-raceand withGODEBUG=fips140=on, SQLite (k83) and PostgreSQL 17 (k82), exit 0;go vet,gofmt. 11 mutations, each failing its test (Detail). Not checked: a test for the two-queryChainsread racing a writer (guarded, not proven); concurrent PostgreSQL writers on one account (the row lockSELECT … FOR UPDATEis there; no race test yet); CodeQL and reviewers.Decided for you (
docs/DECISIONS.md39–41): a minimalaccountstable (the inventory worker adds columns); outcome derived from receipts only; every channel request re-authorized.You need to: nothing. There is no route yet to upload a target descriptor (inventory work); tests insert them through the store.
§13 checklist: Phase 1A "Envelopes, receipts, CAS append, … current-envelope rule,
secret_versionallocation" (Control Plane side) and "idempotent completion". Stacked on #9.Detail
ErrLockedbranchTestOneLockPerAccountAndVersionsNeverGoDownreportedrequireLockTestReceiptAppendCASInTheStoreTestCompleteReleasesOnlyItsOwnLockTestChannelScopesWorkToTheActiveBrokersPoolTestReceiptAppendIsCompareAndSwapTestChannelScopesWorkToTheActiveBrokersPoolAlso covered:
TestSyncIsPaged(paging and the per-account filter); forked and gap receipts (invalid_receipt_chain), a receipt by a key outside the pool (unknown_signing_key), a user recipient on a managed envelope (invalid_recipient_set), an aborted version never reused.internal/pqcrypto/sealenv.goaddsSeal,OpenDEK,OpenPasswordandWrapToover the existing primitives (no new crypto).Review fixes (25 Nov, Guide "Unbounded frames", "Unbounded reads")
SyncBudget(encoded size, with framing) as well as at 64 manifests and always carry at least one, so every page progresses; the Control Plane refuses a manifest over 512 KiB (cptrust.MaxManifest) at upload, so one manifest always fits a frame (DECISIONS 61).sync_accountandreceiptsread only the chains they need: new store queriesOpenChains,ChainsAfter(…, limit)andChain, SQLite and PostgreSQL;Chainsis now for tests only (DECISIONS 62).TestManifestPagesAreBudgetedMaxManifestcheckTestSubmitRefusesAnOversizedManifestChainsTestAccountSyncAndReceiptsReadOnlyWhatTheyNeed(13 chains read for one page)ChainsLIMITTestChainQueriesReadOnlyTheirSlice(SQLite and PostgreSQL)Review fixes, round 2 (25 Nov: security review, Guide "RPC Stall", "Stale Completion")
0ce6144: addressed in0964e57(sync paging and store limits; DECISIONS 62 rewritten).sync_accountnow pages with afromcursor (replacescontinue), and asyncpage reads at mostSyncPagemanifests (ManifestsPage), which also closes the "Not changed" item below.current_envelope_idonly ever moves to a highersecret_version(DECISIONS 71).TestOpenChainsArePagedWithinTheBudget,TestAccountSyncIsBudgetedTestOpenChainsArePagedWithinTheBudgetTestManifestSyncReadsOnlyOnePageTestChainsAndDescriptorsAreCapped(3 mutations)TestUndrainedPushesNeverBlockResultsTestADelayedDuplicateCompletionChangesNothingThe version guard on
current_envelope_idis a second, independent guard behind the "nothing new" check; no test removes both.Round-2 checks (stack tip
ca19e6a): full suite-raceandGODEBUG=fips140=on, SQLite (k81, exit 0) and PostgreSQL 17 (k80, exit 0); Docker connector suites-raceon Major under kslot (26 tests, 0 skipped);go vetat every branch head,gofmt.Review fixes, round 3 (25 Nov, Guide "State Regression", "Unbounded Pagination")
mutatingrun can becomewrite_outcome_unknown(§4.2). A late or retried status report no longer moves atarget_verified,release_authorizedorabortedrun back (6ba10aa).PoolAccountstakes an ID cursor and a limit (id > ? ORDER BY id LIMIT ?, backed by a new(pool_id, id)index in this PR's unmerged migration). The sync checks each row as it is read, with noGetAccountper candidate, so one page reads aboutSyncAccountsPage+1 rows in one query whileTrust.Viewis held.SyncAccountsPageis now a variable so tests can lower it (6ba10aa).state = 'mutating'guardTestLateUnknownStatusNeverRegressesARun(target_verifiedmoved towrite_outcome_unknown)l.accountagainTestAccountListReadsOnlyOnePage(10 per-account reads)LIMITRound-3 checks (stack tip
a805e71): full suite-raceandGODEBUG=fips140=on, SQLite (k83, exit 0) and PostgreSQL 17 (k83, exit 0); Docker connector suites-raceon Major under kslot (30 tests, 0 skipped, exit 0);go vetand the broker/store tests at every merged branch head;gofmt.Review fixes, round 3b (25 Nov, Guide "Reservation retries", "Unbounded scanning" at
662225f)SyncAccountsPagerows, eligible or not. The reply carriesaccounts_next(the last row scanned), so the next page continues past filtered rows; the broker follows it (Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11). This is a wire change between unmerged PRs (3cc19cf).Reserverefuses (conflict) an operation that already has receipts on the account, so a late retry of a finished reservation takes no version and no lock. The lookup uses a new index onenvelope_receipts(operation_id), in this PR's unmerged migration (3cc19cf).TestAccountListReadsOnlyOnePage(12 rows read for a page of 2)TestRotationRoundTripOnTheControlPlane(retry got version 2)Checks (stack tip
96c38fd): full suite-raceandGODEBUG=fips140=on, SQLite (k83, exit 0) and PostgreSQL 17 (see #16); Docker connector suites-raceon Major under kslot (30 tests, 0 skipped, exit 0);go vetand the broker, store and brokerproto tests at every merged branch head;gofmt.Review fixes, round 3c (25 Nov, Guide "Retry Race" at
306c30f)PutEnvelopeandRecordIntentnow take the account row lock before checking for an existing row. Two identical concurrent retries on PostgreSQL could both miss the row, and the second then failed on the primary key instead of succeeding (98a3a05).TestConcurrentIdenticalRetriesSucceed(PostgreSQL 17: duplicate key onsecret_envelopes_pkeyandrotation_runs_pkey)Checks (stack tip
e8bdff0): see #16 for the full suite;go vetand the broker, brokerproto and store tests (-race) at every merged branch head.Review fixes, round 3d (25 Nov, Guide "Suppressed Error" at
48b1d3c)syncAccountnow returns the descriptor lookup error instead of answering with a state that has no descriptor; the broker retries the sync (d33cf4a).TestAccountSyncNeedsTheDescriptorChecks: see #16 for the full suite at the tip;
go vetand the broker, brokerproto, store and api tests (-race) at every merged branch head.Round 4 (25 Nov): Guide "Unfinishable Rotation",
mainmerged upPutEnvelopenow refuses an envelope larger thanMaxEnvelope(MaxChain− 32 KiB), so the largest stored envelope still has room for itscommit_targetand terminal receipt, and a reservation can always be finished. This is Enrollment and re-enrollment (§3.4, §4.5) #15's fix (8dfcf7d) moved down (db09c8d). The test now fills the envelope with printable bytes, as Enrollment and re-enrollment (§3.4, §4.5) #15's copy does (684c48d): SQLite'sLENGTH()stops at the first NUL, so a zero-filled envelope counted as empty and the test passed even without the fix. Broker-sealed envelopes are a few KiB, so in practice the limit only ever refuses an oversized input.mainand Broker listener, CA and pairing (§4.1) #8's round 4).MaxEnvelope = MaxChainTestTheLargestEnvelopeCanStillBeFinished(k83)Checks: at #8
ec97af5the full suite with-raceandGODEBUG=fips140=onpassed on SQLite (Major under kslot, exit 0) and on PostgreSQL 17 (Major under kslot with its ownpostgres:17-alpinecontainer, exit 0). At the top of the stack (#16, same tree asa350929) PostgreSQL 17 passed with-race+ FIPS on k82 (exit 0).gofmtandgo vet(also-tags docker) are clean at every branch head. The mutation proofs ran on throwaway copies.Round 4b (25 Nov): security review at
684c48d(detail on the private board)6b2f65e. A policy may name at most 32 standing recipients (pqcrypto.MaxStandingRecipients, refused asinvalid_body).MaxEnvelopenow keeps 96 KiB of the 256 KiB chain free, and a signedcommit_targetplus areleasecarrying all 32 X-Wing wraps measures about 66 KB (5,202 + 60,875 bytes). DECISIONS 77.commit_targetplus the largest releaseTestChainRoomFitsTheLargestReleaseTestPolicyStandingRecipientsAreBoundedChecks (round 4b): at #8
f212849and at #16bdb9adf, the full suite with-raceandGODEBUG=fips140=onpassed on SQLite (Major under kslot; every K host was busy) and on PostgreSQL 17 (Major under kslot, ownpostgres:17-alpinecontainer), all exit 0. #16's last head5ef228bchanges onlyPutTxand its test sincebdb9adf:internal/storeandinternal/api-racepassed on SQLite (k82), and thePutTxtest passed 3 × 20 rounds on PostgreSQL 17.gofmtandgo vet(also-tags docker) are clean at every branch head. The mutations ran on throwaway copies.Round 4c (25 Nov): Guide "Concurrent retries" at
f40ee12PutTargetDescriptornow inserts withON CONFLICT DO NOTHING(10c54bb). The digest names the content, so identical stores racing on PostgreSQL are all no-ops, where before one could fail on the primary key.TestConcurrentIdenticalDescriptorStoresSucceed(PostgreSQL 17, own container: 5 of 5 runs fail)Checks (round 4c): at #16
9fb8788, the full suite with-raceandGODEBUG=fips140=onpassed on SQLite (Major under kslot) and on PostgreSQL 17 (Major under kslot, ownpostgres:17-alpinecontainer), both exit 0.gofmtandgo vet(also-tags docker) are clean at every changed branch head. The race tests ran on PostgreSQL 17 in my own container; the mutations ran on throwaway copies.🤖 Generated with Claude Code