Repository navigation
fix: retry transient Cloud KMS failures with backoff - #12
Conversation
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2153108604
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case <-ctx.Done(): | ||
| return v, attemptsError(attempt, err) |
There was a problem hiding this comment.
Return the context error when backoff is canceled
When the parent context is canceled or reaches its deadline while waiting between retries, this branch returns the previous transient KMS error instead of ctx.Err(). Consequently, callers cannot detect cancellation with errors.Is(err, context.Canceled) or errors.Is(err, context.DeadlineExceeded); return or wrap the context error here while retaining any useful attempt context.
AGENTS.md reference: AGENTS.md:L118-L119
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 442ebb1. When the context ends, either right after a failed attempt or while waiting before a retry, retryKMS now wraps both ctx.Err() and the last KMS error, so errors.Is works for context.Canceled/DeadlineExceeded and the logs still show the cause. Added TestRetryKMSReturnsContextErrorDuringBackoff, and the existing cancellation test now checks errors.Is(err, context.Canceled).
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Updates the gpgkms tool dependency from v0.2.0 to v0.2.1 (`c4dfbf6`, coder/gpgkms#12). ## What changes in v0.2.1 - Cloud KMS calls (`GetPublicKey` and `AsymmetricSign`) are now tried up to 5 times, waiting 1s, 2s, 4s and 8s in between, when they fail with a transient error. That covers KMS 5xx/408/429, network errors, per-request timeouts, and failures to fetch workload identity credentials. - Other KMS 4xx errors (permission denied, not found) still fail immediately. If the job is cancelled, gpgkms stops retrying and returns the context error. - Every KMS signature is still checked locally before it is used. This fixes [PLE-146](https://linear.app/codercom/issue/PLE-146). In that run, every gpgkms call failed with `credentials: status code 503: upstream connect error …` and the build failed. ## Does the signing key change? No. Key derivation is unchanged: gpgkms's golden and compat tests pass unchanged at v0.2.1. ## Not covered In the same run, darwin_amd64 failed in `kmsp11` (rcodesign's PKCS#11 library, `Error occurred when fetching oauth2 token`), not in gpgkms. This PR does not add retries there. ## Validation - `go get -tool github.com/coder/gpgkms/cmd/gpgkms@v0.2.1`, then `go mod tidy` (only gpgkms lines change), `go mod tidy -diff` and `go mod verify`. - `go tool github.com/coder/gpgkms/cmd/gpgkms` builds and runs. - The real KMS signing path runs in the next `build` workflow. --- _Opened by Xum on behalf of @deansheather._
Fixes PLE-146.
What and why
A coder/coder build failed because every
gpgkmscall hit a transient 503 while fetching workload identity credentials:The generated
cloudkms/v1REST client does not retry, so one blip failed the whole run.GetPublicKeyandAsymmetricSignnow go throughretryKMS:*googleapi.Error. That covers network errors, per-attempt timeouts and credential fetch failures, which the auth library returns as plainfmt.Errorfstrings with no type to match on;failed N attempts: ….Retrying
AsymmetricSignis safe: signing the same digest has no side effects, and every returned signature is still checked locally.The darwin failure in the same run came from
kmsp11(rcodesign), not gpgkms, so this PR does not fix it.Can the exported public key or fingerprint change?
No. Key derivation and signature construction are unchanged; the golden and compat tests pass unchanged.
Validation
gofmt -l .(clean),go vet ./...go test -race -shuffle=on -count=1 ./.... New fake-KMS tests cover recovery from transient errors, giving up after 5 attempts, no retries on 400/403/404, and stopping when the context is cancelled. A table test coversretryable.go mod tidy -diff(root andtools/),go mod verify