Workload identity federation is in Private Preview. To turn it on for your organization, Contact us.
How workload identity federation works
Tokens from an identity provider whose claims match a trust rule act as that rule’s service account.
When a workload runs:
- The workload requests an OpenID Connect (OIDC) token from its platform.
- The workload sends that token and a trust rule ID to
POST /v1/auth/token. - Baseten checks the token’s signature, issuer, expiration, audience, and claims against the trust rule, then returns an access token for the rule’s service account.
- The workload calls Baseten with the access token until it expires, then exchanges a new platform token.
Prerequisites
- The Organization Admin role to add an identity provider, and the Team Admin or Organization Admin role to create service accounts and trust rules. For more information, see Roles and permissions.
- To set up through the Management API, an API key that belongs to a user with those roles. The workloads you set up don’t need an API key.
Add an identity provider
Add the platform your workload runs on as an identity provider. Baseten supports these providers:
Use the Baseten provider to let a model running on Baseten call Baseten as a service account. The model sends its runtime OIDC token as the platform token, so set the trust rule’s audience to
oidc.baseten.co.
GitHub Actions, Google Cloud, and Baseten have one issuer, so add each of them once. For the other providers, add one identity provider for each account, tenant, or cluster issuer.
To add an identity provider:
- UI
- Management API
- Sign in to your workspace at app.baseten.co and open Organization settings, then choose the Workload identity tab.
- Choose Add identity provider.
- For Provider, select your platform.
- If the provider asks for an Issuer URL, enter your account’s, tenant’s, or cluster’s issuer.
- For Name, enter a name that’s unique in your organization, and optionally add a Description.
- Choose Add identity provider.
Create a service account
A service account carries the permissions a workload gets. Give each workload its own service account with the smallest permission set it needs:
To create a service account:
- UI
- Management API
- Sign in to your workspace at app.baseten.co. For a team account, open the team’s settings page. For an API key management account, open Organization settings.
- Choose the Members tab, then under Service accounts, choose Create service account.
- For Name, enter a name that’s unique in your organization, such as
models-ci, and optionally add a Description. - For Permissions, select the permission the workload needs.
- Under Model access or Model API access, choose the models, environments, or Model APIs the account can use.
- Choose Create service account.
Create a trust rule
A trust rule names one identity provider and one service account. It accepts a token when the token’saud matches the rule’s audience and the rule’s condition evaluates to true.
Write the condition
Write the condition as a Common Expression Language (CEL) expression over the token’sclaims. It can use has, size, startsWith, endsWith, contains, and int.
Baseten rejects a condition that doesn’t pin the token’s subject at least this narrowly, in a top-level && clause with ==, in, or startsWith:
For example, this condition accepts tokens only from workflow runs on the
main branch of acme/models. Find the owner’s numeric ID in any GitHub Actions token’s repository_owner_id claim, or run gh api users/acme --jq .id.
<identity_provider_id> with the provider’s ID. The check validates the condition and audience; it doesn’t test a token. Run the following command:
"valid": true, or an error that explains what to change.
To create a trust rule:
Set the audience to the value your workload requests its platform token for. The examples on this page use https://api.baseten.co. For the Baseten provider, use oidc.baseten.co, the audience of a model’s runtime token. Set the maximum token lifetime between 60 and 3,600 seconds; choose the shortest that covers the work done with one token, such as one deploy job.
- UI
- Management API
- Sign in to your workspace at app.baseten.co and open Organization settings, then choose the Workload identity tab and select the identity provider.
- Choose Create trust rule.
- For Name, enter a name that’s unique in your organization, and optionally add a Description.
- For Identity provider, select the provider. You can’t change it later.
- For Service account, select the account the tokens act as.
- For Condition, enter the CEL expression.
- For Audience, keep
https://api.baseten.coor enter the audience your workload requests. - For Max token lifetime, set the longest token the rule issues. The default is 1 hour.
- Choose Create trust rule.
Exchange a token and call Baseten
Get a platform token
Request the platform token with the audience your trust rule expects:Exchange the token
The exchange request authenticates with the platform token, so it doesn’t need an API key. To exchange a platform token for a Baseten access token: Replace<platform_token> with the platform token and <trust_rule_id> with the rule’s ID. In this request, audience is the trust rule’s ID, not the audience inside the platform token. access_token_lifetime_seconds is optional, can’t exceed the rule’s maximum, and defaults to it. Run the following command:
Response
<access_token> with the token from the response. Run the following command:
Deploy from GitHub Actions
This workflow deploys a model when you push tomain, using the trust rule from the condition example. It stores the trust rule ID, which isn’t a secret, as a repository variable in place of an API key.
To deploy a model from GitHub Actions:
-
In your repository, add a variable named
BASETEN_TRUST_RULE_IDwith the trust rule’s ID. For more information, see GitHub’s variables documentation. -
Add the following workflow as
.github/workflows/deploy.yml:.github/workflows/deploy.yml -
Push a commit to
main. The run succeeds when the Push the model step finishes, because--waitfails the step if the deployment doesn’t become active.
id-token: write lets the job request a GitHub token; it grants no write access to the repository. The ::add-mask:: command keeps the access token out of the job log, and the Baseten CLI reads it from BASETEN_API_KEY. The Truss push GitHub Action doesn’t support workload identity federation. For other deploy options, see CI/CD.
Refresh tokens in long-running applications
A long-running application needs a new access token before the current one expires. This Python helper caches the access token and exchanges a fresh platform token when 80% of the token’s lifetime has passed.baseten_token.py
/var/run/secrets/baseten/token, call a Model API through the OpenAI SDK:
client.with_options(api_key=token.get()) for each request so the client always sends a current token. The workload identity classes in the Anthropic and OpenAI SDKs exchange tokens with those providers, not with Baseten, so use this helper instead.
Stop creating API keys
After every workload authenticates with workload identity federation, stop new API keys from being created and revoke the keys your workloads used. Turning off key creation doesn’t affect existing keys; they keep working until they expire or you revoke them. To stop using API keys after you move to workload identity federation:- Turn off API key creation for personal keys, team and API key management keys, or both.
- In the audit log, confirm that no workload has used a key since you moved to workload identity federation.
- Revoke keys across the organization that your workloads used.
Token lifetimes and limits
Access tokens use the same rate limits as API keys.
Troubleshoot token exchange
Every rejected exchange returns HTTP 400 with"error": "invalid_grant", whatever the cause, so the response doesn’t reveal which check failed. Check each condition in order:
- The request’s
audienceis the trust rule’s ID, not the platform token’s audience. - The platform token’s
issmatches the rule’s identity provider. For a provider with its own issuer, the issuer URL must match exactly, including any trailing slash. - The platform token’s
audequals the rule’s audience. - The token’s claims satisfy the condition. Decode the token on your own machine to compare its
suband other claims; don’t paste it into an online decoder. - The platform token hasn’t expired and isn’t older than its platform’s limit.
- The rule’s service account is enabled. If it’s disabled, re-enable it, or update the service account with
"disabled": false.
invalid_request error means the request body is malformed, and unsupported_grant_type means grant_type isn’t the token exchange grant. To confirm the rule itself is valid, verify the trust rule.