{{ message }}
Repository navigation
fix(cli): delete the minted GCP key when the credentials upload panics - #2233
Merged
Merged
Conversation
The deferred cleanup in uploadGCPCredentialsFile only deleted the remote key when err was non-nil; during a panic the named err is still nil, so the local file was removed while the key stayed active in GCP. Track completion and treat a non-completed nil-error exit as an abort: delete the key, report the outcome on stderr (the return value is lost) and let the panic keep propagating. Also assert that a failed local removal after a successful upload does not delete the stored key remotely. Refs #2117 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
This was referenced Oct 16, 2026
Member
Author
This was referenced Oct 16, 2026
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.

Refs #2117. This PR covers items 1 and 2. Item 3 (the second Ctrl-C during the remote delete) and item 4 (reporting a possibly orphaned key when CreateKey is interrupted) follow in separate PRs.
Summary
err != nil. A panic leaves the namederrat nil, so the delete was skipped.doneflag is now set just before the success return. The defer treatserr == nil && !doneas aborted, sets a synthetic error ("upload aborted before completion"), and runs the remote delete and local removal.gclouddelete command if the remote delete failed.recover, so the panic still propagates. A normal error return prints nothing extra.RemovalFailureReportednow assertsdeleteCalledis false. Without it, a change that deleted a successfully stored key when only the local unlink failed passed every test.Evidence (local, macOS,
GOTOOLCHAIN=go1.26.9,gcpKeyProvisionerfakes, no GCP calls)TestWriteServiceAccountKey_PanicDeletesRemoteKeyfails (deleteCalledfalse), and_PanicReportsFailedRemoteDeletefails (stderr empty instead of the gcloud command). With the fix, both pass.assert.Panicskeeps the test binary alive.RemovalFailureReported.done = truefailsMintedKeyRemovedAfterSuccessandRemovalFailureReported.PanicReportsFailedRemoteDelete.make build,go vet ./...andgo test -race ./cmd/...pass.scripts/test-git-secrets-allowlist.shpasses 44/44.🤖 Generated with Claude Code