Repository navigation
Enrollment and re-enrollment (§3.4, §4.5) - #15
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-15, 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 |
|
Security P1 (reservation without enroller authorization): fixed in 8be5940. The reserve request is now an — rowan (Claude Opus 5.5) |
Any session that knew an account ID could reserve its enrollment and hold the lock for 15 minutes, blocking rotation and real enrollment (security review of #15). The reservation request is now signed by an active key of a principal in the current policy's enroller list and must be at most 5 minutes old; otherwise 403 and nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
db061ba to
8be5940
Compare
Any session that knew an account ID could reserve its enrollment and hold the lock for 15 minutes, blocking rotation and real enrollment (security review of #15). The reservation request is now signed by an active key of a principal in the current policy's enroller list and must be at most 5 minutes old; otherwise 403 and nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8be5940 to
7aae6b4
Compare
cbd7d88 to
c8cb8aa
Compare
|
Security P1 (candidate not bound to the transaction's account): fixed in ebec3d8. Both the submit route and the broker now require a user-signed managed candidate with the transaction's scope and the requester as signer, before storage, journaling or decryption. — rowan (Claude Opus 5.5) |
Any session that knew an account ID could reserve its enrollment and hold the lock for 15 minutes, blocking rotation and real enrollment (security review of #15). The reservation request is now signed by an active key of a principal in the current policy's enroller list and must be at most 5 minutes old; otherwise 403 and nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VerifyEnvelope accepts a broker-signed rotation envelope without looking at the enroll transaction, so an enroll over another account's broker-signed envelope at the reserved version would have had the broker open that account's credential and log in with it at this account's target (security review of #15). The Control Plane and the broker now require a user-signed managed candidate whose scope is the transaction's account and whose signer is its requester, before storing, journaling or decrypting anything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7aae6b4 to
ebec3d8
Compare
c8cb8aa to
4344e8b
Compare
Any session that knew an account ID could reserve its enrollment and hold the lock for 15 minutes, blocking rotation and real enrollment (security review of #15). The reservation request is now signed by an active key of a principal in the current policy's enroller list and must be at most 5 minutes old; otherwise 403 and nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ebec3d8 to
d0fee2f
Compare
VerifyEnvelope accepts a broker-signed rotation envelope without looking at the enroll transaction, so an enroll over another account's broker-signed envelope at the reserved version would have had the broker open that account's credential and log in with it at this account's target (security review of #15). The Control Plane and the broker now require a user-signed managed candidate whose scope is the transaction's account and whose signer is its requester, before storing, journaling or decrypting anything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4344e8b to
c3e6a15
Compare
d0fee2f to
29c5c89
Compare
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire PR Reviewer Guide: both items fixed.
|
c3e6a15 to
6c80b8d
Compare
2a98851 to
fb424e1
Compare
6c80b8d to
43d9686
Compare
Control Plane: migration 102 adds enrollment reservations to rotation_locks and an access_transactions table. A reservation moves the account's lock to opid(request_id, 0) with a new version, allowed only with no lock or a quarantined account, and keeps the stuck holder it displaces; after 15 minutes still reserved it expires and the holder is restored, as it is when the enrollment fails. The submit route checks the CLI's enroll transaction and candidate against the manifests, stores the candidate under the reservation and relays both to the broker. Broker: an enrollment is refused before anything is journaled or bound if the transaction (enrollers, replay, versions, candidate digest), the candidate (signer, recipients, escrow) or the account state (an open rotation on a healthy account) fails. Otherwise it journals the attempt, asks the Control Plane to accept the reservation (no acceptance, no bind), burns the request ID with accept_ack, journals the start of the one verification and binds once. Success signs abort (superseded_by_reenrollment) on every unterminated envelope, the stuck run's included, and vault_commit, and lifts quarantine; failure signs abort (enrollment_failed) on the candidate only. A restart never binds a second time and re-sends undelivered receipts. cli.SealEnrollment is the CLI's half; the vault enroll command lands with the session-backed Control Plane client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any session that knew an account ID could reserve its enrollment and hold the lock for 15 minutes, blocking rotation and real enrollment (security review of #15). The reservation request is now signed by an active key of a principal in the current policy's enroller list and must be at most 5 minutes old; otherwise 403 and nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VerifyEnvelope accepts a broker-signed rotation envelope without looking at the enroll transaction, so an enroll over another account's broker-signed envelope at the reserved version would have had the broker open that account's credential and log in with it at this account's target (security review of #15). The Control Plane and the broker now require a user-signed managed candidate whose scope is the transaction's account and whose signer is its requester, before storing, journaling or decrypting anything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Expiry read a reserved row without locking it and then deleted the lock by operation ID. On PostgreSQL an acceptance could commit between the two, and expiry still deleted the now accepted lock and restored the displaced holder, so the broker verified after losing its lock. Expiry is now one conditional DELETE ... WHERE state = 'reserved' AND expires_at <= now RETURNING the displaced holder, which it reinstates only if a row was deleted. PostgreSQL rechecks the WHERE after waiting on an accepting row, so an acceptance that commits first keeps the lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 "Unbounded Batch" is fixed in |
…ssions A reconnect's sync already copies a stuck run's envelope, and enrollCommit appended it again, so two aborts landed at one receipt sequence and the Control Plane refused the batch for good (security review of #15). The stuck envelope is now added only when the copy does not hold that envelope ID. PutTx read, then inserted, so two identical submissions racing on PostgreSQL could see one fail on the primary key and answer 409 (Guide on #15, "Concurrent retries"). It now inserts with ON CONFLICT DO NOTHING and compares the stored bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # docs/DECISIONS.md # internal/broker/export_test.go
access_transactions has two unique indexes, request_id and digest, and PostgreSQL raises a concurrent clash on the one an ON CONFLICT target does not name. The insert now has no target, and a missing request_id row after it (the digest belongs to another request) is ErrConflict. The test runs 20 rounds of 16 submitters behind a start barrier; the old read-then-insert fails it on PostgreSQL every run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Security review at |
After a restart, a sync can already have copied the delivered candidate and its receipts; enrollSend then appended the receipts again and added a second chain for the candidate, which breaks the next chain check (Guide on #15, "Recovery duplication"). The merge now adds a receipt only when its chain lacks those bytes, and the candidate's chain only when no chain has its envelope ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # internal/store/vault_test.go
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire "Recovery duplication" is fixed in |
# Conflicts: # internal/broker/machine.go # internal/broker/schedule.go
main's route registry (#18) removed requireAuthenticated. Reserving and submitting an enrollment need a five-minute step-up (§4.5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # internal/broker/schedule.go
A retried reservation after the enrollment completed took a new version and the lock under the same operation ID (PR Reviewer Guide "Retry Idempotency" on #15). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Guide "Retry Idempotency": fixed in 9318a2e. |
The stored transaction is immutable and names the old version, so a new reservation under the same request could never complete (PR Reviewer Guide "Unusable Retry" on #15). ReserveEnrollment takes the request ID in place of the always-zero reported version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Guide "Unusable Retry": fixed in 8cab7aa. |
In one line: Accounts can now be enrolled and re-enrolled: the only way out of quarantine. The Control Plane reserves and relays; the broker checks everything again, binds exactly once and only after the Control Plane accepted, and commits atomically.
What changed
opid(request_id, 0)with a new version, allowed only with no lock or a quarantined account, keeping the stuck rotation it displaces; stillreservedafter 15 minutes it expires and that holder is restored (§4.5 step 1).acceptednever expires. A failed enrollment restores it too.POST /api/accounts/{id}/enrollments(reserve; the request must be signed by an active key of a principal inenroller_principal_ids, else 403 and no lock — security review),POST …/{request_id}(submit: the CP verifies theenrolltx and candidate, stores the candidate, relays both),GET …/{request_id}(state). All carryTODO(hawthorn §7.5)(fresh step-up).VerifyTxorVerifyEnveloperefuses (outsideenroller_principal_ids, replayedrequest_id, version not above the highest seen, foreign recipients) and an open rotation on a healthy account. Then journals → CPaccept(no accept, no bind) →accept_ack+ burnrequest_id→ verify-start → one bind (§4.5 step 2).superseded_by_reenrollment) on every unterminated envelope (the stuck run's included) plusvault_commit, quarantine lifted; the CP appends them, moves the current envelope and deletes the enrollment lock. Failure: abort (enrollment_failed) on the candidate only (§4.5 steps 3–4).cli.SealEnrollment: the CLI's half (seal to the active broker and escrow, sign candidate andenroll), from the CLI's own verified state.Review this
internal/broker/enroll.goEnroll/acceptEnrollment/recoverEnrollment: the checks before any bind and the never-twice rule.internal/store/vault.goReserveEnrollment/AcceptEnrollment/restore: the lock moves, expiry (in its own transaction, see below) and restore.Checked: full suite
-race+GODEBUG=fips140=onon SQLite and PostgreSQL via kjob (results in the comment below once in), the Docker connector suites at this tip; 10 mutations each failing its test (Detail). A test caught a real bug while writing this: an expiry inside a transaction that then refused was rolled back with it; expiry now commits on its own. Not checked: thekyguard-cli vault enrollcommand (it needs the session-backed Control Plane client of §7.6); lease reset evidence (§4.5 step 3), which lands with checkout leases.Decided for you (
docs/DECISIONS.md52–55): the CP allows a reservation over a held lock only when the broker last reportedquarantined/auth_failed(the broker checks again); the superseding aborts carry the enrollment'soperation_id; CLI command wiring waits for §7.6.You need to: nothing.
§13 checklist: Phase 1A "
enrolltransaction; reservation, acceptance handshake and expiry; enrollment, re-enrollment …" (reset evidence and vault put remain). Acceptance 1 and 4 (except the lease clauses) with a fake target. Stacked on #14.Detail
accepterrorsTestExpiredOrFailedEnrollmentRestoresTheStuckLockTestCrashAfterVerificationStartedFailsTestReEnrollmentAfterQuarantinerequest_idburnedTestEnrollmentRefusedBeforeAnyBindTestEnrollmentAndRotationExcludeEachOtherTestExpiredOrFailedEnrollmentRestoresTheStuckLockTestEnrollmentReservationVerifyEnvelopeTestCandidateWithAForeignRecipientIsRefusedTestEnrollmentRoutes(non-enroller, unsigned, forged)Acceptance 4 end to end (
TestReEnrollmentAfterQuarantine): v1 released, v2 ambiguous and quarantined, password reset at the target, re-enrollment → v3 current,abort(superseded) on v2, v1's two receipts kept, the CP run for v2aborted, lock gone, the next rotation produces v4.Review fixes (25 Nov, Guide "Expiry race", "Receipt retries")
DELETE … WHERE state = 'reserved' AND expires_at <= ? RETURNING …, and gives the lock back only if it deleted a row; an acceptance that commits first keeps its lock (PostgreSQL re-checks the predicate after the row lock).Recover, never verifying again (DECISIONS 68).maxRequestBody), since Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10 moved the manifest cap tocptrust.TestExpiryNeverReleasesAnAcceptanceItRaces(PostgreSQL, deterministic) andTestAcceptRacingExpiry(200 rounds, SQLite and PostgreSQL)TickTestEnrollmentReceiptsRetryOnTheNextTick(one login only)Review fixes, round 2 (25 Nov: security review, Guide "Replica routing")
fb424e1: addressed in8d16e88.Listener.Relay: straight down the channel when this replica holds it, otherwise into a sharedbroker_outboxtable (added to migration 102, unmerged; keyed by UUIDv7 and included in backups and the SQLite-to-PostgreSQL migration), which the replica holding the broker's channel drains every second with oneDELETE … RETURNING, so each push is taken once. A queued push expires with its transaction. The submission now answers 202 either way; the CLI follows the enrollment state (DECISIONS 75). Checkout, possession proofs, leases, manual rotation (§3.4, §3.6) #16's checkout relays use the same path.TestRecoveredEnrollmentFailsWhenTheTargetChangedTestRelayReachesTheBrokerThroughAnyReplicaTestQueuedPushesAreTakenOnceTestEnrollmentRoutesThe pin check compares the current descriptor with both the transaction's and the candidate's sealing policy; each alone blocks the case, so only removing both fails the test.
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 "Stalled Enrollment" at
c51430d)Tickonly re-sent journaled enrollment receipts. An enrollment that stopped earlier (accepted by the Control Plane, then a journal save failed) stayed open with no receipts, blocking rotation and holding the lock until the next reconnect.Ticknow resumes any open enrollment throughrecoverEnrollment, as a restart does: re-send, fail, or verify once, never a second bind.Enrollholdsm.mu, so an open enrollment thatTicksees has always stopped (d765159).serve'sWaitGroup(Broker-local rotation scheduler (§3.4, §4.4) #12 security fix).TestStalledEnrollmentResumesOnTheNextTick(lock still held)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 3d (25 Nov, security review at
03b75f7)8dfcf7d.PutEnveloperefuses an envelope aboveMaxEnvelope(MaxChain− 32 KiB), so every stored envelope leaves room for its terminal receipt. The enrollment submission answers 413 for such a candidate.MaxChainagainTestChainsAndDescriptorsAreCapped(aMaxEnvelope+1 envelope was stored)TestTheLargestEnvelopeCanStillBeFinishedstores an envelope of exactlyMaxEnvelope, then a 16 KiB abort, and checks that the lock is released.Checks: 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 "Unbounded Batch",
mainmerged upenrollSendnow delivers receipts in batches of at mostMaxFrame/4receipt bytes (1.33 MiB after base64, under the 4 MiB frame).vault_commitis last, so the batch that carries it is the one that completes the enrollment and releases the lock. After a failed batch, the next tick re-sends from the start: the Control Plane takes the stored prefix as byte-identical no-ops (§3.5), so progress is kept. The broker still signs every abort and thevault_commitin one journal commit (§4.5).MaxEnvelopechange now arrives from Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10 as well; the conflicts instore/vault.goandvault_test.gokept this branch's side (LockAction).TestReEnrollmentReceiptsAreBatchedChecks: 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 and Guide "Concurrent retries" at
018daf47ae9dc0.enrollCommitadds a stuck run's envelope to the chain copy only when the copy does not already hold that envelope ID.PutTxnow inserts withON CONFLICT (request_id) DO NOTHINGand then compares the stored bytes, so identical submissions racing on PostgreSQL all succeed, and a different transaction under the same request ID is stillErrConflict.TestReEnrollmentAfterSyncCopiedTheStuckEnvelope(k80:invalid_receipt_chain)PutTxTestConcurrentIdenticalTxSubmissionsSucceed(PostgreSQL 17, own container)Checks (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 "Recovery duplication" at
459f7edenrollSendnow merges into the chain copy idempotently (ff3c6ca): a receipt is added only if its chain lacks those bytes, and the candidate's chain only if no chain has its envelope ID. A sync after a restart can therefore have copied either one first.TestRecoveryAfterSyncDoesNotDuplicateChains(invalid_receipt_chain)TestRecoveryAfterSyncDoesNotDuplicateChains(v3 copied twice)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.Round 5 (25 Nov): merge of
mainwith the route registry (#18)main's registry (api: classified route registry and per-action step-up (§7.5, §7.3 rule 6) #18) removedrequireAuthenticated, so this branch no longer built after the merge. The enrollment routes now go throughs.route. Reserving and submitting an enrollment need a step-up within five minutes (§4.5 "fresh step-up"); the status read issessionwith no window (DECISIONS 78,e28bb91).TickandRecoverconflicts with Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11 and Broker-local rotation scheduler (§3.4, §4.4) #12 are resolved: the enrollment resume runs inside the per-accounttick, andRecoverreports undelivered health after the enrollment resume.fresh(StepupWindow)from submitTestBrokerActionsNeedAFreshStepUp(k82)Checks (round 5): the full suite ran at the bottom (#11) and top (#16) of the stack (see #16).
internal/apiandinternal/brokerpassed at this head. The mutation ran on a throwaway copy.Round 5b (26 Nov): Guide "Retry Idempotency" at
9d6837cReserveEnrollmentnow refuses an operation that already has receipts on the account, the same checkReservehas (shared asnotEnded). The route answers 409 "this enrollment already ended" (9318a2e).ReserveEnrollmentTestACompletedEnrollmentIsNotReservedAgainChecks:
go vet,internal/storeandinternal/apipassed at this head (k82); the full suite ran at the top (#16). The mutation ran on a throwaway copy.Round 5c (26 Nov): Guide "Unusable Retry" at
9318a2eReserveEnrollmentnow takes the request ID (in place of thereportedversion, which every caller passed as 0) and refuses with 409 once a transaction is stored for it (8cab7aa).main(through Linux SSH connector, tested against OpenSSH + linux-pam (§4.4) #14) is merged in.TestASubmittedEnrollmentIsNotReservedAgainAfterExpiryChecks (round 5c): at
86daca7,go vetand the full suite with-raceandGODEBUG=fips140=onpassed on SQLite and on PostgreSQL 17 (both on Major, every K host busy; PostgreSQL in my ownpostgres:17-alpinecontainer under kslot), exit 0. The mutation ran on a throwaway copy.🤖 Generated with Claude Code