Software factory / Start
Use Anthropic with no stored key
An Anthropic API key that you save on the forge works until you rotate it. With Workload Identity Federation, the forge stores no Anthropic key: for each run, it trades a signed 5-minute token with Anthropic for a short-lived API token.
5 min read
You set up the Anthropic side once, in the Claude Console. Then you give the forge three ids, and none of them is a secret. To stop the forge, you archive the rule in the Console.
You need:
- Admin access to the repository, or to be an owner of the organization.
- The admin role in your Anthropic organization.
Note
The steps in the Claude Console follow Anthropic's guide to Workload Identity Federation. If the Console looks different, follow that guide with the values of this page.
1. Add the forge as an issuer
In the Claude Console, open Workload identity and select Connect workload. Pick Custom OIDC, and give these values:
- Issuer URL:
https://source.tanstack.com/oidc - Keys: by discovery. Anthropic reads the public keys of the forge from
https://source.tanstack.com/oidc/.well-known/openid-configuration.
Note
The issuer URL is the address of the site, then /oidc. On another deployment of TanStack Source, use its address.
2. Make a rule for your repository
In the same wizard, make a service account and a federation rule. The rule decides which tokens Anthropic accepts. For the repository acme/api:
| Field | Value |
|---|---|
| Subject | repo:acme/api:factory, with no * |
| Audience | source-factory:anthropic |
Claim kind | factory |
Claim repository_id | The id of your repository |
| Workspace | One workspace |
| OAuth scope | workspace:developer |
| Token lifetime | 600 seconds |
With the Admin API, the same rule is:
{
"name": "source-factory-api",
"issuer_id": "fdis_...",
"match": {
"subject_prefix": "repo:acme/api:factory",
"audience": "source-factory:anthropic",
"claims": { "kind": "factory", "repository_id": "..." }
},
"target": { "type": "service_account", "service_account_id": "svac_..." },
"workspace_id": "wrkspc_...",
"oauth_scope": "workspace:developer",
"token_lifetime_seconds": 600
}
The forge shows these values for your repository, with its id. Open Provider keys (step 4), pick Anthropic and Workload Identity Federation, and read What the rule must match.
For every repository of an organization, use the subject repo:acme/* and the claims kind factory and repository_owner_id. The Software factory tab of the organization shows them.
Important
Always match the audience source-factory:anthropic. Only the factory gets it: the forge refuses this audience to every CI job. A rule with another audience, or with none, can also take the token of a CI job, which runs the code of your repository.
Important
Always match an id: repository_id, or repository_owner_id for an organization. The subject has names, and after a rename another repository can take the old name. An id never moves to another repository.
3. Copy the ids
From the Console, copy:
- The id of the rule. It starts with
fdrl_. - The id of your Anthropic organization, a UUID from the Organization page.
- The id of the workspace (
wrkspc_...), only when the rule covers more than one workspace.
4. Save the federation on the forge
- On a repository, open Agents, then Provider keys.
- On an organization, open the Software factory tab, then Provider keys.
Pick the provider Anthropic. In Sign in with, pick Workload Identity Federation, with no stored key. Paste the ids, and click Save federation.
Or use src:
src factory set-key anthropic --federation-rule fdrl_01ABC --organization 00000000-0000-0000-0000-000000000000
src factory set-key anthropic --org acme --federation-rule fdrl_01ABC --organization 00000000-0000-0000-0000-000000000000
Add --workspace wrkspc_... when the rule covers more than one workspace.
The forge checks the federation before it saves it: it trades one token with Anthropic.
- Anthropic refuses the rule: nothing is saved. The page says
Anthropic refused the federation rule fdrl_.... Anthropic gives the same answer for every refusal. The reason is in the Claude Console: Workload identity, then the authentication history. - Anthropic does not take the ids: nothing is saved. The page says
Anthropic did not take the federation rule fdrl_.... Check the rule id, the organization id and the workspace id. - Anthropic does not answer: the federation is saved, with the warning
Could not check the federation now. It is saved; the first run will tell if it works.This is for a timeout, a rate limit and a server error of Anthropic.
A federation replaces the Anthropic key of the same repository or organization, and a key replaces the federation.
When the forge can not read a saved federation, the list says so in place of the rule id (unreadable in src factory keys). Save the federation again, or delete it.
5. Pick an Anthropic model
Open the settings of the agent, and pick the provider Anthropic and a model. See Pick a model.
Done
The agent runs on your Anthropic account, and the forge holds no Anthropic key. Provider keys shows Anthropic with the id of the rule. src factory keys shows it too.
What works, and what does not
- A federation works for the provider Anthropic. A Claude model of Workers AI (
anthropic/...in the Workers AI list) is paid by the forge and uses no key and no federation. - The PR chat and the architecture chat use the federation too, when their model is an Anthropic model.
- A repository's federation or key wins over its organization's.
- An API token lives at most 10 minutes. The forge gets a new one during a long run.
- The tokens stay on the forge. The sandbox of an agent, the run log and the answers of REST and MCP never get one.
- The forge sends no key to rotate. To stop access, archive the rule in the Claude Console. To remove the federation here, delete it in Provider keys, or run
src factory delete-key anthropic.
The token that the forge signs
Anthropic checks this token against your rule. The forge signs it with RS256, with the same key as the OIDC tokens of CI jobs.
| Claim | Value |
|---|---|
iss | https://source.tanstack.com/oidc |
aud | source-factory:anthropic. No CI job gets this audience. |
sub | repo:<owner>/<repo>:factory |
kind | factory |
repository | <owner>/<repo> |
repository_id | The id of the repository on the forge. |
repository_owner | The user or organization that owns the repository. |
repository_owner_id | The id of that owner on the forge. |
iat, nbf, exp | The token is good for 5 minutes. |
jti | A random id, new for each token. Anthropic takes each token once. |
The subject has the names of the owner and the repository. After you rename or move a repository, change the subject of the rule. The ids stay the same.