Repository navigation
fix(runner): delete the previous refresh-token secret on rotation - #7052
Conversation
persistRefreshToken generated a unique secret name every refresh/restart and never removed the secret referenced by the previous CachedRefreshTokenRef, so OAUTH_REFRESH_TOKEN secrets accumulated. Capture the old ref from stored state, save the new one, then best-effort delete the old secret; a delete failure only warns. Add a mock-based regression asserting the delete.
Codex Review SummaryThis 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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7052 +/- ##
==========================================
+ Coverage 80.64% 82.56% +1.92%
==========================================
Files 858 940 +82
Lines 87646 96657 +9011
==========================================
+ Hits 70682 79805 +9123
+ Misses 16959 16847 -112
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
left a comment
There was a problem hiding this comment.
See the inline comments.
|
Thanks for the detailed finding — it was correct. I added |
ChrisJBurns
left a comment
There was a problem hiding this comment.
-
Possibly important · correctness · pre-existing — Secret stored before a SaveState failure is left orphaned, with no cleanup on the error path (
pkg/runner/runner.go:1034)If SetSecret succeeds but updatedConfig.SaveState fails, the function returns an error and leaves the newly stored
secretNamein the provider with nothing referencing it. The live config keeps the previous ref, so nothing will ever delete the new secret. Since this PR is about stopping OAUTH_REFRESH_TOKEN_* orphans, this error path is a remaining source of them.Recommendation: On SaveState failure, best-effort
DeleteSecret(ctx, secretName)whensecretName != previousSecretName, and log the failure. Also extend TestRunner_PersistRefreshToken_SaveStateFailurePreservesLiveConfig to assert the previous secret is not deleted.
Signed-off-by: Chen Yufeiyang <[email protected]>
|
Addressed the review finding on the SaveState error path. Verification: base-red 1 failed (gomock missing |
Signed-off-by: Chen Yufeiyang <[email protected]>
|
/retest |
Summary
OAUTH_REFRESH_TOKEN_<workload>_<timestamp>_<rand>secret on every refresh/restart and never deleted the secret referenced by the previousCachedRefreshTokenRef, so the workload namespace accumulated one secret per token rotation.Fixes #3886
Type of change
Test plan
go test ./pkg/runner -count=1passes)task test-e2e)go vet ./pkg/runnerandgofmtclean)The new
TestRunner_PersistRefreshTokenDeletesPreviousSecretseeds stored state with an old ref, runspersistRefreshTokenagainst the mock provider, and asserts the new secret is written, state is saved, and the old secret is deleted. Before the fix the test fails on the missingDeleteSecretcall; after the fix it passes. Delete failure is only logged, so a provider that cannot delete does not block the new token.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
pkg/runner/runner.gopkg/runner/persist_refresh_token_test.goDoes this introduce a user-facing change?
No. The visible token behaviour is unchanged; only the stale secret is removed.
Implementation plan
Approved implementation plan
persistRefreshTokenflow and the stored state contract.CachedRefreshTokenRefbefore overwriting, and delete it only after the new secret and state are saved.go test ./pkg/runner.Special notes for reviewers
The previous ref is read from the stored workload state rather than kept in memory across restarts, so the cleanup also works for the restart path. The delete is deliberately after
SaveState: if saving the new reference fails, the old secret is still the one the stored state points at.