fix: share one exchanged WIF credential across spawned Claude processes#1407
Open
KeisukeYamashita wants to merge 1 commit into
Open
fix: share one exchanged WIF credential across spawned Claude processes#1407KeisukeYamashita wants to merge 1 commit into
KeisukeYamashita wants to merge 1 commit into
Conversation
GitHub OIDC tokens are single-use at the Anthropic token-exchange endpoint (the same jti cannot be exchanged twice). With plugins configured, the action spawns several short-lived claude processes (plugin marketplace add, one plugin install per plugin, then the main query). Each resolved federation from bare env vars and exchanged the same identity-token file independently: the first exchange succeeded and every later process got 401 (jti_reused), which the main query retried for ~3 minutes before failing the job. The SDK only enables its on-disk credentials cache when federation is loaded from a profile config file, not from bare env vars. Write a profile pointing at the identity-token file and select it via ANTHROPIC_CONFIG_DIR / ANTHROPIC_PROFILE so the first process exchanges once and the rest reuse the cached access token. The env vars are kept as a fallback for CLIs that predate profile support.
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.
Fixes #1406
Problem
GitHub OIDC tokens are single-use at the Anthropic token-exchange endpoint (the same
jticannot be exchanged twice). When theplugins/plugin_marketplacesinputs are configured, the action spawns several short-livedclaudeprocesses per job (claude plugin marketplace add, oneclaude plugin installper plugin, then the main query). Each process resolved workload identity federation from the bare env vars and exchanged the same identity-token file independently: the first exchange succeeded and every later process got 401 (jti_reused), which the main query retried for ~3 minutes before failing the job. Details, eBPF process traces, and request-ids in #1406.Fix
The SDK only enables its on-disk credentials cache (
<config_dir>/credentials/<profile>.json, shared across processes) when federation is loaded from a profile config file, not from bare env vars.setupWorkloadIdentity()now additionally writes a profile pointing at the identity-token file and selects it viaANTHROPIC_CONFIG_DIR+ANTHROPIC_PROFILE, so the first process exchanges once and every other process reuses the cached access token.RUNNER_TEMP(0700 dir / 0600 file), next to the identity token.ANTHROPIC_IDENTITY_TOKEN_FILEand the federation env vars are kept as a fallback for CLIs that predate profile support — older CLIs degrade to today's behavior, never worse.jti) token from the same file path recorded in the profile.Verification
bun test: 702/702 pass (includes 2 new unit tests for the profile file),bun run typecheck,bun run format:checkall green.jti: two sequentialclaudeprocesses sharing one identity token — env-var path: second process retriesjti_reusedfor ~3 minutes and dies (matches production failures exactly); profile path: second process reuses the cached credential with zero additional exchanges and succeeds. Verified with both Claude Code 2.1.167 and 2.1.173.is_error: false, main query completes in ~6s. An eBPF trace shows the same fiveclaudeprocesses contactingapi.anthropic.com, now with a single token exchange.Notes / limitations
ANTHROPIC_CONFIG_DIR/ANTHROPIC_PROFILE, they are overridden while federation inputs are configured (federation inputs are an explicit opt-in, and previously the env-var path was similarly authoritative).