The era of pasting long-lived API keys into GitHub Secrets for AI coding agents is ending, though not without significant configuration traps. Anthropic and OpenAI have both documented support for workload identity federation (WIF) in their GitHub Actions workflows, allowing CI jobs to exchange short-lived OIDC tokens for model access without storing static credentials. This shift addresses a critical security vulnerability: a CI job that processes external text, such as pull request descriptions or issue comments, is a prime target for prompt injection attacks if it holds a permanent key with spending authority.
The Mechanics of Keyless Authentication
The federation process replaces a stored secret with a signed statement about the job's runtime environment. When a workflow has the id-token: write permission, GitHub mints an OIDC token valid for roughly five minutes. The model provider validates this token against a predefined federation rule. If the rule matches, the provider issues a short-lived access token. Anthropicβs documentation specifies that the token lifetime defaults to 3,600 seconds but is capped by the remaining life of the initial OIDC token, effectively limiting exposure to about ten minutes. Crucially, these federated tokens retain full workspace access, meaning security relies entirely on the precision of the federation rule rather than the duration of the token.
The Fork Trap and Rule Precision
The most dangerous aspect of this migration is the federation rule configuration. Anthropic explicitly warns that a subject prefix of repo:your-org/* without a ref constraint matches pull request runs from forks. In this scenario, any contributor who can open a pull request could potentially obtain a federated token and spend your API quota. To mitigate this, rules must be pinned to specific repositories or protected branches, such as refs/heads/main. For jobs that need to review forked code, a separate, cheaper authentication path or a mandatory human approval step is required, as the federation token should not be granted to untrusted external inputs by default.
Provider Support and Migration Pitfalls
Support for WIF varies across the ecosystem. The Claude Code Action and Claude API fully support the exchange, requiring only the federation rule ID and organization ID in the workflow configuration. OpenAIβs API also supports this via OIDC, but the Codex GitHub Action still primarily documents the use of a static OPENAI_API_KEY, with Codex federation currently in beta and requiring manual enablement. A subtle but critical pitfall exists in SDK migration: if an environment variable like ANTHROPIC_API_KEY is still present, it takes precedence over the federation settings. This can cause workflows to silently revert to using the old, long-lived key even after federation is configured, negating the security benefits.
Key Takeaways
- Workload Identity Federation (WIF) replaces long-lived API keys with short-lived OIDC tokens in GitHub Actions, significantly reducing the attack surface for prompt injection and credential leaks.
- The federation rule is the new security boundary; a loose rule (e.g., repo:your-org/* without ref constraints) allows any forked pull request to obtain a token and spend your API quota.
- Provider support is uneven: Anthropic and OpenAI APIs support WIF, but the Codex GitHub Action still relies on static keys, and Codex federation is only available in beta.
- Migration requires careful verification: stale environment variables like ANTHROPIC_API_KEY can silently override federation settings, so developers must confirm which credential is active before removing the key.
The Bottom Line
Removing the key is the right move, but the federation rule is the new secret you must protect with equal paranoia. If you don't lock down your rules to protected branches, you've just swapped a static leak for an unlimited spend risk from any open pull request.