Skip to content

Enrollment and re-enrollment (§3.4, §4.5) - #15

Merged
Yoshiofthewire merged 36 commits into
mainfrom
kyguard/broker-enroll
Nov 26, 2026
Merged

Yoshiofthewire merged 36 commits into
mainfrom
kyguard/broker-enroll

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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

  • Control Plane (migration 102): 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, keeping the stuck rotation it displaces; still reserved after 15 minutes it expires and that holder is restored (§4.5 step 1). accepted never expires. A failed enrollment restores it too.
  • Routes POST /api/accounts/{id}/enrollments (reserve; the request must be signed by an active key of a principal in enroller_principal_ids, else 403 and no lock — security review), POST …/{request_id} (submit: the CP verifies the enroll tx and candidate, stores the candidate, relays both), GET …/{request_id} (state). All carry TODO(hawthorn §7.5) (fresh step-up).
  • Broker: refuses before journaling or touching the target anything VerifyTx or VerifyEnvelope refuses (outside enroller_principal_ids, replayed request_id, version not above the highest seen, foreign recipients) and an open rotation on a healthy account. Then journals → CP accept (no accept, no bind) → accept_ack + burn request_id → verify-start → one bind (§4.5 step 2).
  • Success: in one journal write, abort (superseded_by_reenrollment) on every unterminated envelope (the stuck run's included) plus vault_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).
  • A restart never binds twice and re-sends undelivered receipts. An open enrollment blocks rotation.
  • cli.SealEnrollment: the CLI's half (seal to the active broker and escrow, sign candidate and enroll), from the CLI's own verified state.

Review this

  • internal/broker/enroll.go Enroll/acceptEnrollment/recoverEnrollment: the checks before any bind and the never-twice rule.
  • internal/store/vault.go ReserveEnrollment/AcceptEnrollment/restore: the lock moves, expiry (in its own transaction, see below) and restore.

Checked: full suite -race + GODEBUG=fips140=on on 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: the kyguard-cli vault enroll command (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.md 52–55): the CP allows a reservation over a held lock only when the broker last reported quarantined/auth_failed (the broker checks again); the superseding aborts carry the enrollment's operation_id; CLI command wiring waits for §7.6.

You need to: nothing.

§13 checklist: Phase 1A "enroll transaction; 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
Property Mutation Failing test
No bind without the CP's acceptance ignore accept errors TestExpiredOrFailedEnrollmentRestoresTheStuckLock
No second bind after a crash mid-verify verify again on restart TestCrashAfterVerificationStartedFails
Unterminated envelopes are superseded skip them TestReEnrollmentAfterQuarantine
request_id burned don't burn TestEnrollmentRefusedBeforeAnyBind
No enrollment over a healthy open rotation drop the check TestEnrollmentAndRotationExcludeEachOther
An open enrollment blocks rotation drop the check same
Failure restores the stuck lock delete instead TestExpiredOrFailedEnrollmentRestoresTheStuckLock
CP: no reservation over a healthy rotation drop the check TestEnrollmentReservation
CP: an expired reservation cannot be accepted skip the expiry same
Candidate verified before any bind skip VerifyEnvelope TestCandidateWithAForeignRecipientIsRefused
Only an enroller may reserve skip the list / the signature / the whole check TestEnrollmentRoutes (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 v2 aborted, lock gone, the next rotation produces v4.

Review fixes (25 Nov, Guide "Expiry race", "Receipt retries")

  • Expiry is one conditional statement, 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).
  • Journaled enrollment receipts the Control Plane has not acknowledged are re-sent by every scheduler tick as well as by Recover, never verifying again (DECISIONS 68).
  • Request bodies of the enrollment routes keep their 512 KiB cap under their own name (maxRequestBody), since Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10 moved the manifest cap to cptrust.
Property Mutation Failing test
Expiry never releases an accepted reservation old read-then-restore TestExpiryNeverReleasesAnAcceptanceItRaces (PostgreSQL, deterministic) and TestAcceptRacingExpiry (200 rounds, SQLite and PostgreSQL)
Undelivered enrollment receipts retried while connected no re-send in Tick TestEnrollmentReceiptsRetryOnTheNextTick (one login only)

Review fixes, round 2 (25 Nov: security review, Guide "Replica routing")

  • Security review at fb424e1: addressed in 8d16e88.
  • Guide "Replica routing": pushes to a broker go through Listener.Relay: straight down the channel when this replica holds it, otherwise into a shared broker_outbox table (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 one DELETE … 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.
Property Mutation Failing test
Enrollment target pin (security) drop the pin check TestRecoveredEnrollmentFailsWhenTheTargetChanged
Queued push reaches the broker via another replica no drain loop TestRelayReachesTheBrokerThroughAnyReplica
A push is taken once select instead of delete TestQueuedPushesAreTakenOnce
Expired pushes dropped keep expired rows same
Submission queues when the channel is elsewhere return the local send error TestEnrollmentRoutes

The 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 -race and GODEBUG=fips140=on, SQLite (k81, exit 0) and PostgreSQL 17 (k80, exit 0); Docker connector suites -race on Major under kslot (26 tests, 0 skipped); go vet at every branch head, gofmt.

Review fixes, round 3 (25 Nov, Guide "Stalled Enrollment" at c51430d)

  • Tick only 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. Tick now resumes any open enrollment through recoverEnrollment, as a restart does: re-send, fail, or verify once, never a second bind. Enroll holds m.mu, so an open enrollment that Tick sees has always stopped (d765159).
  • Enrollment goroutines now start through serve's WaitGroup (Broker-local rotation scheduler (§3.4, §4.4) #12 security fix).
Property Mutation Failing test
A stalled enrollment resumes on the next tick only re-send receipts (the old condition) TestStalledEnrollmentResumesOnTheNextTick (lock still held)

Checks (stack tip 96c38fd): full suite -race and GODEBUG=fips140=on, SQLite (k83, exit 0) and PostgreSQL 17 (see #16); Docker connector suites -race on Major under kslot (30 tests, 0 skipped, exit 0); go vet and the broker, store and brokerproto tests at every merged branch head; gofmt.

Review fixes, round 3d (25 Nov, security review at 03b75f7)

  • Security P2 (detail on the private board): addressed in 8dfcf7d. PutEnvelope refuses an envelope above MaxEnvelope (MaxChain − 32 KiB), so every stored envelope leaves room for its terminal receipt. The enrollment submission answers 413 for such a candidate.
Property Mutation Failing test
A stored envelope can always be finished cap envelopes at MaxChain again TestChainsAndDescriptorsAreCapped (a MaxEnvelope+1 envelope was stored)

TestTheLargestEnvelopeCanStillBeFinished stores an envelope of exactly MaxEnvelope, then a 16 KiB abort, and checks that the lock is released.

Checks: see #16 for the full suite at the tip; go vet and the broker, brokerproto, store and api tests (-race) at every merged branch head.

Round 4 (25 Nov): Guide "Unbounded Batch", main merged up

  • enrollSend now delivers receipts in batches of at most MaxFrame/4 receipt bytes (1.33 MiB after base64, under the 4 MiB frame). vault_commit is 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 the vault_commit in one journal commit (§4.5).
  • Merged up from Linux SSH connector, tested against OpenSSH + linux-pam (§4.4) #14. The MaxEnvelope change now arrives from Control Plane rotation storage and broker channel requests (§3.5, §4.3) #10 as well; the conflicts in store/vault.go and vault_test.go kept this branch's side (LockAction).
Property Mutation Failing test
No receipt request exceeds the batch budget, and a failed batch resumes to completion one batch for everything TestReEnrollmentReceiptsAreBatched

Checks: at #8 ec97af5 the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot, exit 0) and on PostgreSQL 17 (Major under kslot with its own postgres:17-alpine container, exit 0). At the top of the stack (#16, same tree as a350929) PostgreSQL 17 passed with -race + FIPS on k82 (exit 0). gofmt and go 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 018daf4

  • Security P2 (detail on the private board): addressed in 7ae9dc0. enrollCommit adds a stuck run's envelope to the chain copy only when the copy does not already hold that envelope ID.
  • Concurrent retries: PutTx now inserts with ON CONFLICT (request_id) DO NOTHING and then compares the stored bytes, so identical submissions racing on PostgreSQL all succeed, and a different transaction under the same request ID is still ErrConflict.
Property Mutation Failing test
Re-enrollment completes after a reconnect's sync copied the stuck envelope no dedupe TestReEnrollmentAfterSyncCopiedTheStuckEnvelope (k80: invalid_receipt_chain)
Identical concurrent submissions succeed on PostgreSQL the old read-then-insert PutTx TestConcurrentIdenticalTxSubmissionsSucceed (PostgreSQL 17, own container)

Checks (round 4b): at #8 f212849 and at #16 bdb9adf, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot; every K host was busy) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), all exit 0. #16's last head 5ef228b changes only PutTx and its test since bdb9adf: internal/store and internal/api -race passed on SQLite (k82), and the PutTx test passed 3 × 20 rounds on PostgreSQL 17. gofmt and go vet (also -tags docker) are clean at every branch head. The mutations ran on throwaway copies.

Round 4c (25 Nov): Guide "Recovery duplication" at 459f7ed

  • enrollSend now 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.
Property Mutation Failing test
No duplicate receipt after Sync, then Recover always append receipts TestRecoveryAfterSyncDoesNotDuplicateChains (invalid_receipt_chain)
No duplicate candidate chain always add the candidate TestRecoveryAfterSyncDoesNotDuplicateChains (v3 copied twice)

Checks (round 4c): at #16 9fb8788, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), both exit 0. gofmt and go 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 main with the route registry (#18)

Property Mutation Failing test
Enrollment reserve and submit need a fresh step-up drop fresh(StepupWindow) from submit TestBrokerActionsNeedAFreshStepUp (k82)

Checks (round 5): the full suite ran at the bottom (#11) and top (#16) of the stack (see #16). internal/api and internal/broker passed at this head. The mutation ran on a throwaway copy.

Round 5b (26 Nov): Guide "Retry Idempotency" at 9d6837c

  • A retried reservation after its enrollment completed took a new version and the lock again under the same operation ID. ReserveEnrollment now refuses an operation that already has receipts on the account, the same check Reserve has (shared as notEnded). The route answers 409 "this enrollment already ended" (9318a2e).
Property Mutation Failing test
A completed enrollment is not reserved again; no version or lock is taken drop the check in ReserveEnrollment TestACompletedEnrollmentIsNotReservedAgain

Checks: go vet, internal/store and internal/api passed 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 9318a2e

  • A reservation whose transaction was already submitted, and which then expired, could be reserved again under the same request. The stored transaction is immutable and names the old version, so the new reservation could never complete and held the lock until it expired. ReserveEnrollment now takes the request ID (in place of the reported version, 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.
Property Mutation Failing test
A submitted, expired enrollment is not reserved again under its request drop the stored-transaction check TestASubmittedEnrollmentIsNotReservedAgainAfterExpiry

Checks (round 5c): at 86daca7, go vet and the full suite with -race and GODEBUG=fips140=on passed on SQLite and on PostgreSQL 17 (both on Major, every K host busy; PostgreSQL in my own postgres:17-alpine container under kslot), exit 0. The mutation ran on a throwaway copy.

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail 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

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security P1 (reservation without enroller authorization): fixed in 8be5940. The reserve request is now an EnrollReservation signed by an active key of a principal in the current policy's enroller_principal_ids (≤ 5 min old); anything else is 403 before ReserveEnrollment runs. TestEnrollmentRoutes covers a non-enroller, an unsigned request and a forged signature (alice's principal and key ID, bob's signature): each 403 with the lock and highest_secret_version unchanged; each guard was mutated and the test failed. Fresh step-up stays with the route registry (TODO(hawthorn §7.5)).

— rowan (Claude Opus 5.5)

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Correction: after a renumbering amend, the reservation fix is 7aae6b4 (was 8be5940).

— rowan (Claude Opus 5.5)

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

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. TestAnotherAccountsEnvelopeIsNotACandidate (broker-signed envelope of a same-pool account at the reserved version, valid enroll over its digest) is refused with no login; TestEnrollmentRoutes covers the route (422). Both fail with the check removed. The stack was rebased onto #14's fixes; the reservation fix is now 9db6a19.

— rowan (Claude Opus 5.5)

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

PR Reviewer Guide: both items fixed.

  • Expiry race (c72b4f0): expiry is one conditional DELETE … WHERE state = 'reserved' AND expires_at <= ? RETURNING, and it restores the displaced lock only if it deleted a row. TestExpiryNeverReleasesAnAcceptanceItRaces (PostgreSQL) and TestAcceptRacingExpiry cover it.
  • Receipt retries (8a4711d): every scheduler tick re-sends journaled, unacknowledged enrollment receipts without a second bind (TestEnrollmentReceiptsRetryOnTheNextTick).

@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/broker-enroll branch 2 times, most recently from 2a98851 to fb424e1 Compare November 25, 2026 12:56
Yoshiofthewire and others added 4 commits November 25, 2026 08:44
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>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
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>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

"Unbounded Batch" is fixed in 22881c6. Receipts go out in batches of at most MaxFrame/4 bytes, with vault_commit last. A retry re-sends the stored prefix, which the Control Plane takes as byte-identical no-ops, so a failed batch resumes and the enrollment still completes in the batch that carries vault_commit. TestReEnrollmentReceiptsAreBatched fails when everything is sent in one batch.

Yoshiofthewire and others added 3 commits November 25, 2026 16:03
…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>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Security review at 018daf4: addressed in 7ae9dc0. "Concurrent retries" is fixed in 7ae9dc0 and 459f7ed. PutTx inserts with ON CONFLICT DO NOTHING and then compares the stored bytes. TestConcurrentIdenticalTxSubmissionsSucceed (16 submitters behind a barrier, 20 rounds) fails on PostgreSQL 17 every run with the old read-then-insert, and passes with the fix.

Yoshiofthewire and others added 2 commits November 25, 2026 17:09
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
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

"Recovery duplication" is fixed in ff3c6ca. The merge into the chain copy is idempotent, by receipt bytes and by envelope ID. TestRecoveryAfterSyncDoesNotDuplicateChains runs Sync, then Recover, after a lost receipts reply; it fails if either check is removed.

@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/connector-ssh to main November 26, 2026 01:45
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>
Yoshiofthewire added a commit that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Guide "Retry Idempotency": fixed in 9318a2e. ReserveEnrollment now refuses an operation that already has receipts on the account, the same check Reserve has. The route answers 409 and takes no version and no lock. TestACompletedEnrollmentIsNotReservedAgain fails without it.

Yoshiofthewire and others added 2 commits November 25, 2026 21:31
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>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Guide "Unusable Retry": fixed in 8cab7aa. ReserveEnrollment now takes the request ID and refuses with 409 once a transaction is stored for it, so a submitted, expired enrollment can't be reserved again under the same request. The client starts a new enrollment instead. TestASubmittedEnrollmentIsNotReservedAgainAfterExpiry fails without it.

@Yoshiofthewire
Yoshiofthewire merged commit 10d516c into main Nov 26, 2026
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant