fix(pki): add per-order lock and processing status to ACME order finalize#31993
Open
goingforstudying-ctrl wants to merge 16 commits into
Open
fix(pki): add per-order lock and processing status to ACME order finalize#31993goingforstudying-ctrl wants to merge 16 commits into
goingforstudying-ctrl wants to merge 16 commits into
Conversation
|
@goingforstudying-ctrl is attempting to deploy a commit to the HashiCorp Team on Vercel. A member of the Team first needs to authorize it. |
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 14, 2026
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 16, 2026
3156c88 to
25d6e65
Compare
327ae88 to
4b554a5
Compare
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 17, 2026
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 17, 2026
4b554a5 to
781f872
Compare
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 17, 2026
781f872 to
6f4e88f
Compare
6f4e88f to
88c5dd8
Compare
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 18, 2026
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 18, 2026
88c5dd8 to
a78aab1
Compare
2d0229f to
c96b950
Compare
c96b950 to
137190c
Compare
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 22, 2026
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 22, 2026
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 24, 2026
358c754 to
ccb4b50
Compare
goingforstudying-ctrl
added a commit
to goingforstudying-ctrl/vault
that referenced
this pull request
Jun 24, 2026
Prevent concurrent finalize requests on the same ACME order from double-issuing certificates by: 1. Adding a per-order striped lock (locksutil) around the entire read → check → issue → save sequence. 2. Persisting an intermediate ACMEOrderProcessing status before certificate issuance as defense-in-depth, so that even if a request bypasses the lock (e.g. different lock stripe on another cluster node), the status gate at the top of the handler will reject it. Fixes hashicorpGH-31987
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into GH-31987 while reading through the PKI ACME handler — two concurrent finalize requests on the same order can both pass the readiness gate and both issue distinct certificates, but the order can only track one serial number, so the other cert is orphaned from all order-keyed lookups.
The root cause is that
acmeFinalizeOrderHandlerdoes a plainStorage.Get→ status check → issue →Storage.Putwith no serialization between the read and the write.This PR adds two layers of protection:
Per-order striped lock (
locksutil) around the entire handler body. This serializes concurrent finalize calls for the same order ID so only one can enter the critical section at a time.Intermediate "processing" status as defense-in-depth. After the lock is acquired and validations pass, the order is immediately saved with
ACMEOrderProcessingstatus before any certificate is issued. If a second request somehow reaches the handler despite the lock (e.g. across cluster nodes on different lock stripes), theorder.Status != ACMEOrderReadygate will reject it withErrOrderNotReady.The
computeOrderStatushelper already treatsACMEOrderProcessingas a non-terminal status, so the intermediate save doesn't change the authorization-recheck behavior for any codepath that recomputes status after the fact.I went with
locksutilover a plainsync.Mutexmap because it's the idiomatic pattern in this codebase (used by the database backend, approle, cert auth, and others). Downside is the 256-stripe hash means two different order IDs will occasionally contend on the same underlyingRWMutex, but in practice the critical section is brief — just the CSR parsing + cert issuance — and the processing-status gate ensures correctness even when the lock doesn't perfectly isolate.Not sure about the
AcmeAccountStatusValidconstant I used in the test setup — I picked it from the existing account status values, but let me know if there's a better constant for "active account" in test contexts.Closes #31987