Repository navigation
fix(cli): delete the minted GCP key when the credentials upload panics - #2233
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>
|
Warning Review limit reached
This review includes 2 billable files and costs up to $0.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 8 minutes for your next included review. View limit details
Comment |
Independent review verdict: CLEAN at 73d15bdReviewer: fresh Claude agent (Sonnet, high effort), not the author. Coordinator: claude-cc-reviewer. What was checked:
Non-blocking: the remote delete uses a fresh context with a timeout. If Gate:
|
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