Skip to content

fix(wif): prevent credential refresh after cleanup - #1620

Open
abhinavkr26104 wants to merge 2 commits into
anthropics:mainfrom
abhinavkr26104:fix/wif-refresh-cleanup-race
Open

fix(wif): prevent credential refresh after cleanup#1620
abhinavkr26104 wants to merge 2 commits into
anthropics:mainfrom
abhinavkr26104:fix/wif-refresh-cleanup-race

Conversation

@abhinavkr26104

@abhinavkr26104 abhinavkr26104 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • prevent an in-flight WIF refresh from recreating credential material after action cleanup
  • add a regression test for a refresh that resolves after stop()

Audit finding

base-action/src/workload-identity.ts starts asynchronous OIDC refreshes with setInterval. Cleanup previously called clearInterval() and removed RUNNER_TEMP/claude-workload-identity, but did not cancel a refresh already awaiting core.getIDToken().

Reproduction:

  1. Configure workload identity federation.
  2. Let a scheduled refresh enter fetchIdentityToken().
  3. Finish the action while that request is still pending.
  4. The stop() cleanup removes the credential directory.
  5. The pending refresh resolves and writes a new identity token and cache directory.

Expected: after stop(), no identity token or exchanged-credential cache is recreated.

Actual before this change: the asynchronous refresh could recreate credential material after cleanup, leaving secret-bearing files in the runner's per-job temporary directory.

The fix marks the handle stopped before cleanup and checks that state after the awaited token request, before calling setSecret() or writing files.

This is distinct from #1406/#1407, which addressed repeated OIDC exchanges across spawned Claude processes. I found no existing issue or PR covering this post-stop refresh race.

Fixes #1621

Validation

  • bun test test/workload-identity.test.ts -t "does not recreate credentials when a refresh finishes after stop"
  • bun test test/parse-sdk-options.test.ts
  • bun run typecheck (root)
  • bun run typecheck (base-action)
  • bunx prettier --check base-action/src/workload-identity.ts base-action/test/workload-identity.test.ts
  • git diff --check

Full repository test runs were also attempted; the checkout has several pre-existing platform/environment failures on Windows (CRLF-sensitive metadata tests, POSIX symlink/permission assertions, network image fixtures, and base README parsing), documented in the audit handoff.

@abhinavkr26104

Copy link
Copy Markdown
Contributor Author

Updated the branch with current main in ad18f67. The WIF cleanup-race regression still passes, as do the root and base-action TypeScript checks, Prettier on the changed files, and git diff --check. The only failures in the full WIF test file locally are the two pre-existing Windows permission-mode assertions; they are unrelated to this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WIF refresh can recreate credentials after action cleanup

1 participant