Workload identity federation can replace stored model keys in GitHub Actions. How it works, the rule to get right, and a key audit script.
This article was first published on Medium. The canonical URL is https://medium.com/@r3dtuxedo/your-ci-doesnt-need-a-model-api-key-anymore-mostly-bcf464e7fa4b.
TL;DR
- A model API key in CI sits in the same job that reads outside text: pull requests, issues, comments. Anthropic's own docs for its GitHub Action say to avoid "storing a long-lived secret entirely" by using workload identity federation.
- How it works: the job gets a GitHub OIDC token (about 5 minutes), swaps it for a short-lived model token, and your rule decides which repo, branch or environment may do that.
- The catch is the rule. Anthropic warns that
repo:your-org/*without a branch limit also matches pull-request runs from forks, so "anyone who can open a pull request" could get a token.- Status on 28 Nov: Claude Code Action and the Claude API support it. OpenAI documents it for the API with GitHub Actions. Codex federation is in beta and must be enabled. The Codex GitHub Action docs still show a stored
OPENAI_API_KEY.
A coding agent in CI is a strange mix. It needs a credential that can spend money and read your prompts. It also reads text written by strangers: the pull request description, the issue it was asked to triage, the comment that said @claude.
You can harden the second part with sandboxes and permissions. This article is about the first: the key. The best way to protect a secret in CI is not to have one.
A key that never gets stored can't be copied out of storage.
Why the key in CI is the one to remove
Three things make this secret special.
It is long-lived. A normal API key works until someone deletes it. Anthropic's docs make the point even about cleanup: "If you delete a secret, the credential it held stays valid." You must delete the key in the Console too.
It is shared. Anthropic's GitHub Action docs suggest that a secret used across repositories should be an API key from the Console, since an OAuth token "is tied to the subscription of the person who ran claude setup-token". Organization-level secrets mean one leaked value reaches every repo.
And stolen keys get tried fast. Dragos spent five months, from July to November 2026, sending about two million prompts with canary credentials to AI services, then watching where those secrets surfaced. In its write-up, the bait AWS keys were tested "in some cases within a few hours" of being sent. Those were AWS keys leaked through AI routers, not model keys from CI, so treat it as a sign of how quickly an exposed secret is used, not as proof about CI.
What federation changes
Workload identity federation replaces "a secret that proves who you are" with "a signed statement about where this job runs". GitHub can mint an OIDC token for each workflow job that has the id-token: write permission. The model provider checks that token and, if your rule matches, hands back a short-lived access token.

What replaces the stored key, step by step.
The numbers from Anthropic's WIF docs: the rule sets token_lifetime_seconds between 60 and 86,400, default 3,600, and the wizard prefills 600. The minted token's life is "the lesser of" the rule's value and "twice the remaining lifetime of the IdP JWT you presented". GitHub's token lasts roughly 5 minutes, so by that rule the Anthropic token should not outlive about 10 minutes. The default scope, workspace:developer, "grants the same access as a workspace API key", so a token is not weaker while it exists. It is just short-lived.
Claude Code Action: four inputs
The GitHub Actions docs describe it in a few lines. Instead of anthropic_api_key, you set:
permissions: id-token: write steps: - uses: anthropics/claude-code-action@v1 with: anthropic_federation_rule_id: fdrl_xxxx anthropic_organization_id: 00000000-0000-0000-0000-000000000000 anthropic_service_account_id: svac_xxxx # optional if the rule targets one The IDs are identifiers, not secrets. Anthropic's example workflow says they "can live directly in the workflow file or in repository variables". id-token: write is required for the exchange.
The Console side takes about three objects: an issuer (GitHub's https://token.actions.githubusercontent.com, using discovery mode), a service account, and a federation rule. A wizard under Workload identity creates them. Anthropic's Terraform provider (beta, 3 Dec 2026) can now manage the issuer, service account and rule as well as the Console wizard.
One trap in the SDK migration guide deserves its own paragraph. The credential order puts ANTHROPIC_API_KEY above the federation settings. So if the old key is still injected anywhere, the key wins and federation silently isn't used. The guide's steps are: set up federation in parallel, check which credential wins with ant auth status, then unset the key everywhere it is injected, and check again.
The part that decides your risk: the rule
The federation rule is where you say which jobs are allowed. It matches on the token's sub claim and others. Anthropic's GitHub Actions page puts the warning plainly: "A subject_prefix of repo:your-org/* alone matches every repository in your organization, and without a ref constraint it also matches pull_request runs triggered from forks. Anyone who can open a pull request against a matching repository could obtain a federated Anthropic token."

The rule is the new secret. Make it narrow.
The docs give four ways to narrow it: pin to one repository, pin to a protected branch with a ref claim, pin the owner with repository_owner as defence in depth, and for deploy jobs match an environment and gate that environment with required reviewers.
This changes one design question for agent workflows. A job that reviews pull requests from forks should probably not hold a federation token that can spend your quota at all. If the rule only matches refs/heads/main, a fork's pull_request run will not match, and the job needs a different, cheaper path, or a human approval step first.
The cloud route
If your models run on Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry, the Claude action page says that "with all three providers, you authenticate through OIDC identity federation instead of a Claude API key, so you store no static cloud credentials in your repository." That moves the secret problem to your cloud's IAM, which you can scope per repository and role, and which has the usual audit trail.
What about OpenAI and everyone else?
This is where "mostly" comes in. Here is where each tool stands on 28 November, from the docs.
| Tool | Keyless from GitHub Actions? | Detail |
|---|---|---|
| Claude Code Action | Yes | Federation rule, org and service-account IDs, id-token: write |
| Claude API (SDK) | Yes | SDK reads ANTHROPIC_IDENTITY_TOKEN_FILE and refreshes the token |
| OpenAI API | Yes, documented | OIDC token swapped for a short-lived token, "without storing a long-lived API key in GitHub secrets" |
| Codex (managed ChatGPT workspace) | Beta, must be enabled | Uses OPENAI_IDENTITY_TOKEN_FILE. Request access from OpenAI |
| Codex GitHub Action | Docs still show a secret | Examples use openai-api-key: ${{ secrets.OPENAI_API_KEY }}. I found no documented federation path |
| OpenCode GitHub integration | Not for the model key | Its OIDC use is for a GitHub App token. A keyless model login is not in the docs I read |
| Claude subscription token | No | CLAUDE_CODE_OAUTH_TOKEN is a long-lived token tied to a person |
OpenAI's workload identity federation guide lists GitHub Actions among its identity providers, and its GitHub Actions page says the exchange "lets workflows authenticate to the OpenAI API without storing a long-lived API key in GitHub secrets". For Codex, it says the feature "is in beta and must be enabled for your workspace". It also warns of a similar precedence trap: "The presence of either variable selects WIF ahead of API keys, access tokens, and stored logins", so a process can pick up federation when you expected a key.
There was a rumour of keyless login for OpenCode's own console, posted on X. I could not confirm it in OpenCode's documentation, so I left it out of the table.
Where you still need a key, and how to shrink it
If you use the Codex GitHub Action today, you probably still need a key. Treat it as the dangerous thing it is:
- Use a project key just for that workflow, with a spend limit, not your main key.
- Keep the action's
safety-strategyondrop-sudo. OpenAI's docs say it "removes sudo before running Codex" and "protects secrets in memory", and warn that read-only alone is not enough to protect secrets. - Do not feed it text from outside contributors without a review step.
- Rotate on suspicion. The docs say: "Rotate keys immediately if you suspect the proxy logs or action output exposed secret material."
- Where you can, move the work to a path that supports federation: the OpenAI API directly, or Codex with federation once it's enabled for your workspace.
And a plain one for subscription users: a CLAUDE_CODE_OAUTH_TOKEN is long-lived and tied to a person. For a team, an API key through federation is better than a person's token in a repo.
Find the keys you have
I wrote a read-only script, ci_key_audit.py, that scans .github/workflows for stored model keys and tells you three things per workflow: which keys it references, whether id-token: write is already set, and whether the workflow reacts to pull requests, issues or comments. I tested it on three made-up workflow files, a Claude one, a Codex one and an unrelated build. It listed the first two and ignored the third. It cannot see organization or environment secrets, so check those in GitHub settings too.
https://gist.github.com/br4vesirrobin/b539de3dbb0c4213762b77bf56697bea
Start with one workflow, the one that reads the most outside text. Set up federation in parallel, confirm which credential wins, then unset the key everywhere and delete it in the Console.
What I could not back
- I did not set up federation end to end. I read the docs and the example workflow, and I did not run a job.
- I did not verify that Codex federation works with
openai/codex-action. The action's docs still show only a key. - The OpenCode keyless-login claim is unconfirmed. I did not use it.
- The Dragos finding is about AWS keys sent to AI routers. I use it only to show how fast leaked secrets get tested.
- I did not use the MCP Python SDK OAuth advisory (GHSA-qx49-fqc8-xw99) in this article. It concerns OAuth credentials going to a server-chosen authorization server, which is a different problem.
- The audit script is a text scan. It misses secrets set outside workflow files.
Sources
- Anthropic, Claude Code GitHub Actions, Workload Identity Federation, Use WIF with GitHub Actions and the example workflow. Read 28 Nov 2026.
- Anthropic, Manage Claude platform with Terraform (beta, 3 Dec 2026). Read 5 Dec 2026.
- OpenAI, Workload identity federation, GitHub Actions identity provider guide and Codex GitHub Action. Read 28 Nov 2026.
- OpenCode docs, GitHub. Read 28 Nov 2026.
- Dragos, AI Supply Chain Security: What Canary Tokens Found (Nov 2026).



