> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useautumn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Workload Identity

> Call Autumn from your cloud without storing an API key

Workload identity lets a service in your cloud call Autumn without an API key. Your platform already knows which workload is running and can sign a short-lived token that proves it. Autumn checks that token against a rule you set up, then gives back an Autumn access token that works in place of a secret key.

There's no secret to store, rotate or leak. Each token is scoped to one environment, carries only the permissions you pick, and expires on its own.

It works with:

* GitHub Actions
* GitLab CI
* Google Cloud (Cloud Run, Compute Engine, GKE, Cloud Functions)
* AWS (ECS, Lambda, EC2 and anything else that runs as an IAM role)
* Azure managed identities
* Vercel
* Kubernetes on EKS, GKE and AKS
* Any other issuer that publishes OIDC discovery

## How it works

```mermaid theme={null}
sequenceDiagram
    participant W as Your workload
    participant P as Your platform
    participant A as Autumn
    W->>P: Ask for an OIDC token for your Autumn audience
    P-->>W: Signed JWT (expires in minutes)
    W->>A: POST /v1/auth.exchange_token
    A->>A: Verify the signature, then match a trust rule
    A-->>W: am_wit_... access token
    W->>A: Call the API with Authorization: Bearer am_wit_...
```

1. You add a **trust rule** in the dashboard. It names the platform and the exact workload, like a GitHub repository ID or an IAM role ARN.
2. At runtime, the workload asks its platform for an OIDC token issued for your Autumn audience.
3. The workload sends that token to `/v1/auth.exchange_token`. Autumn fetches the issuer's public keys, checks the signature, expiry and audience, and looks for a rule that matches.
4. Autumn returns an access token starting with `am_wit_`. Use it as a Bearer token until it expires, then exchange again.

## Your audience

Every environment has its own audience:

```
https://api.useautumn.com/workload/<org_id>/sandbox
https://api.useautumn.com/workload/<org_id>/live
```

Copy yours from **Settings → Workload Identity**. Sandbox and live have separate audiences and separate rules, so a token minted for sandbox can never reach live data. The snippets below read it from an `AUTUMN_AUDIENCE` variable.

The workload asks its platform for a token with this audience. Azure is the exception: its tokens carry your own app registration as the audience, so Azure workloads send the Autumn audience in the exchange request instead. See [Azure](#azure).

## Create a trust rule

Open **Settings → Workload Identity** in the environment you want the workload to use, and click **Add trust rule**.

![The Workload Identity settings page with three trust rules and the environment's audience](https://mintcdn.com/autumn-b9b4c0fb/ROEXCfKuJHVz--6U/images/workload-identity/rules.png?fit=max\&auto=format\&n=ROEXCfKuJHVz--6U\&q=85\&s=145b93c8943c4a3d29e4878ddbd2939b)

**1. Pick where it runs**

Choose the platform. This decides which issuer Autumn trusts and which claim identifies the workload.

**2. Identify the workload**

Paste the workload's ID, like a repository ID or an IAM role ARN, and the issuer if the platform needs one. Each platform pins a claim that can't be reused by someone else:

| Platform | Claim | Example |
| - | - | - |
| GitHub Actions | `repository_id` | `712345678` |
| GitLab CI | `job_project_id` | `48213377` |
| Google Cloud | `sub` (service account unique ID) | `104729384756201938475` |
| AWS | `sub` (IAM role ARN) | `arn:aws:iam::123456789012:role/usage-worker` |
| Azure | `oid` (managed identity object ID) | `9b1d4e2a-7c3f-4e21-a0c2-5d8e1f9b40c2` |
| Vercel | `project_id` | `prj_8xK2mQ4vN1` |
| Kubernetes | `sub` | `system:serviceaccount:billing:usage-worker` |
| Other OIDC | `sub` | `workload-123` |

The value has to match exactly. Wildcards aren't supported. Use [conditions](#conditions) to narrow a rule further.

![The Add trust rule sheet with GitHub Actions selected and a repository ID filled in](https://mintcdn.com/autumn-b9b4c0fb/ROEXCfKuJHVz--6U/images/workload-identity/add-rule.png?fit=max\&auto=format\&n=ROEXCfKuJHVz--6U\&q=85\&s=d26fabc7ddf5626a8a85032e9e0aa2c8)

**3. Add conditions (optional)**

Under **Only when**, limit the rule to some runs of the workload, like production deploys from `main`. See [Conditions](#conditions).

**4. Choose permissions and lifetime**

Pick what the workload can do and how long each access token lasts. See [Permissions and lifetime](#permissions-and-lifetime).

Nothing secret is stored in a rule. If the issuer isn't one Autumn knows, it fetches `<issuer>/.well-known/openid-configuration` when you save, so the issuer has to be a public HTTPS URL.

## Set up your platform

Each section shows how to get a platform token for your audience and what to put in the rule. They all end with the same [exchange request](#exchange-the-token).

### GitHub Actions

**Rule:** the repository ID. Find it with `gh api repos/<owner>/<repo> --jq .id`. The issuer is `https://token.actions.githubusercontent.com`. If your enterprise uses a unique issuer, use `https://token.actions.githubusercontent.com/<enterprise-slug>`.

The job needs `id-token: write` permission to request a token:

```yaml .github/workflows/sync.yml theme={null}
name: Sync usage
on:
  push:
    branches: [main]

permissions:
  id-token: write
  contents: read

jobs:
  sync:
    runs-on: ubuntu-latest
    environment: production
    env:
      AUTUMN_AUDIENCE: https://api.useautumn.com/workload/org_XXXXXXXX/live
    steps:
      - name: Get an Autumn token
        run: |
          OIDC_TOKEN=$(curl -sS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
            "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$AUTUMN_AUDIENCE" | jq -r .value)

          AUTUMN_TOKEN=$(curl -sS https://api.useautumn.com/v1/auth.exchange_token \
            --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
            --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
            --data-urlencode "subject_token=$OIDC_TOKEN" | jq -r .access_token)

          echo "::add-mask::$AUTUMN_TOKEN"
          echo "AUTUMN_TOKEN=$AUTUMN_TOKEN" >> "$GITHUB_ENV"

      - run: ./scripts/sync-usage.sh # reads $AUTUMN_TOKEN
```

To accept only production deploys from `main`, add the conditions `environment` is `production` and `ref` is `refs/heads/main`.

### GitLab CI

**Rule:** the project ID, from the project's overview page under **⋮ → Copy project ID**. Autumn matches it against the `job_project_id` claim, which needs GitLab 18.4 or later. The issuer is `https://gitlab.com`. On a self-managed instance, use your instance URL, like `https://gitlab.example.com`. It has to be reachable from the internet over HTTPS.

Request the token with `id_tokens`:

```yaml .gitlab-ci.yml theme={null}
sync-usage:
  image: alpine:3.22
  variables:
    AUTUMN_AUDIENCE: https://api.useautumn.com/workload/org_XXXXXXXX/live
  id_tokens:
    AUTUMN_ID_TOKEN:
      aud: https://api.useautumn.com/workload/org_XXXXXXXX/live
  script:
    - apk add --no-cache curl jq
    - |
      AUTUMN_TOKEN=$(curl -sS https://api.useautumn.com/v1/auth.exchange_token \
        --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
        --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
        --data-urlencode "subject_token=$AUTUMN_ID_TOKEN" | jq -r .access_token)
    - ./scripts/sync-usage.sh
```

Useful conditions: `ref_protected` is `true`, `environment` is `production` or `ref` is `main`.

### Google Cloud

**Rule:** the service account's numeric unique ID, not its email:

```bash theme={null}
gcloud iam service-accounts describe usage-worker@my-project.iam.gserviceaccount.com \
  --format='value(uniqueId)'
```

The issuer is always `https://accounts.google.com`.

On Cloud Run, Compute Engine, Cloud Functions and GKE with Workload Identity Federation for GKE, ask the metadata server for an identity token:

```bash theme={null}
OIDC_TOKEN=$(curl -sS -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience=$AUTUMN_AUDIENCE")
```

> [!WARNING]
>
> If you never attached a service account, the workload runs as the project's default compute account, which every workload in the project shares. Create a dedicated service account for this workload and put its ID in the rule.

### AWS

AWS signs tokens for external services through IAM outbound identity federation.

1. Turn it on once per account:

   ```bash theme={null}
   aws iam enable-outbound-web-identity-federation
   ```

2. Read your account's issuer and paste it into the rule:

   ```bash theme={null}
   aws iam get-outbound-web-identity-federation-info
   ```

3. Allow the workload's role to request tokens for your audience:

   ```json theme={null}
   {
     "Version": "2012-10-17",
     "Statement": [
       {
         "Effect": "Allow",
         "Action": "sts:GetWebIdentityToken",
         "Resource": "*",
         "Condition": {
           "ForAllValues:StringEquals": {
             "sts:IdentityTokenAudience": "https://api.useautumn.com/workload/org_XXXXXXXX/live"
           }
         }
       }
     ]
   }
   ```

4. Request a token from a regional STS endpoint. The global endpoint doesn't serve this API:

   ```bash theme={null}
   OIDC_TOKEN=$(aws sts get-web-identity-token \
     --region us-east-1 \
     --audience "$AUTUMN_AUDIENCE" \
     --signing-algorithm ES384 \
     --query WebIdentityToken --output text)
   ```

**Rule:** the IAM role ARN the task, function or instance runs as, like `arn:aws:iam::123456789012:role/usage-worker`. Find it with `aws iam get-role --role-name usage-worker --query Role.Arn --output text`. If several workloads share a role, give this one its own role first.

### Azure

Azure managed identities can only get tokens for an app registration in your tenant, so the setup has an extra step.

1. In **Microsoft Entra ID → App registrations**, create a registration, for example `autumn-workloads`, with no redirect URI.

2. Open **Expose an API**, click **Add** next to **Application ID URI**, and save the suggested `api://<app-id>`.

3. In the rule, set **Audience** to that URI. If your tokens carry the app's client ID instead (always the case for v2 tokens), use the client ID.

4. Set **Workload** to the managed identity's object (principal) ID:

   ```bash theme={null}
   az identity show -n usage-worker -g my-resource-group --query principalId -o tsv
   ```

5. Set the issuer to match the token's `iss` claim. Tokens are v1 unless the app registration's manifest sets `requestedAccessTokenVersion` to 2:

   | Token version | Issuer |
   | - | - |
   | v1 (default) | `https://sts.windows.net/<tenant-id>/` |
   | v2 | `https://login.microsoftonline.com/<tenant-id>/v2.0` |

Request a token for the app registration. On a VM, use the instance metadata service:

```bash theme={null}
OIDC_TOKEN=$(curl -sS -H "Metadata: true" \
  "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=api://<app-id>" \
  | jq -r .access_token)
```

On App Service, Functions and Container Apps, use the identity endpoint instead:

```bash theme={null}
OIDC_TOKEN=$(curl -sS -H "X-IDENTITY-HEADER: $IDENTITY_HEADER" \
  "$IDENTITY_ENDPOINT?api-version=2019-08-01&resource=api://<app-id>" | jq -r .access_token)
```

For a user-assigned identity, add `&client_id=<identity-client-id>` to either URL.

The token's audience is your app, not Autumn, so **send your Autumn audience as the `audience` parameter** when you exchange it. That tells Autumn which organization and environment to check.

### Vercel

1. Make sure OIDC federation is on for the project, under **Project → Settings → Security**.
2. **Rule:** the issuer is `https://oidc.vercel.com/<team-slug>` and the workload is the project ID (`prj_...`) from **Project → Settings → General**. Renaming the team changes the issuer, so update the rule if you do.

Vercel's default audience is `https://vercel.com/<team-slug>`, which Autumn rejects. Request your Autumn audience with `@vercel/oidc` 4.0 or later:

```ts app/api/sync/route.ts theme={null}
import { getVercelOidcToken } from "@vercel/oidc";

const exchange = async () => {
  const subjectToken = await getVercelOidcToken({
    audience: process.env.AUTUMN_AUDIENCE!,
  });
  const res = await fetch("https://api.useautumn.com/v1/auth.exchange_token", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
      subject_token_type: "urn:ietf:params:oauth:token-type:jwt",
      subject_token: subjectToken,
    }),
  });
  const { access_token } = await res.json();
  return access_token as string;
};
```

A token with a custom audience always uses the team issuer, even if the team is set to the global issuer. To keep preview deployments out, add the condition `environment` is `production`.

### Kubernetes

The kubelet can mount a service account token with your Autumn audience into the pod. The default mounted token is for the Kubernetes API, so Autumn rejects it.

**Rule:** the issuer is your cluster's OIDC issuer and the workload is `system:serviceaccount:<namespace>:<name>`.

| Cluster | Issuer | Find it with |
| - | - | - |
| EKS | `https://oidc.eks.<region>.amazonaws.com/id/<id>` | `aws eks describe-cluster --name <cluster> --query cluster.identity.oidc.issuer --output text` |
| GKE | `https://container.googleapis.com/v1/projects/<project>/locations/<location>/clusters/<cluster>` | Fill in your project, location and cluster name |
| AKS | `https://<region>.oic.prod-aks.azure.com/<tenant>/<guid>/` | `az aks show -n <cluster> -g <resource-group> --query oidcIssuerProfile.issuerUrl -o tsv` |

The issuer has to be reachable from the internet over HTTPS. AKS clusters before 1.34 need `--enable-oidc-issuer`.

Mount the token with a projected volume:

```yaml deployment.yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: usage-worker
  namespace: billing
spec:
  selector:
    matchLabels: { app: usage-worker }
  template:
    metadata:
      labels: { app: usage-worker }
    spec:
      serviceAccountName: usage-worker
      containers:
        - name: worker
          image: ghcr.io/acme/usage-worker:latest
          volumeMounts:
            - name: autumn-token
              mountPath: /var/run/secrets/autumn
              readOnly: true
      volumes:
        - name: autumn-token
          projected:
            sources:
              - serviceAccountToken:
                  audience: https://api.useautumn.com/workload/org_XXXXXXXX/live
                  expirationSeconds: 3600
                  path: token
```

Read `/var/run/secrets/autumn/token` each time you exchange. The kubelet rotates the file before the token expires, so a copy read at startup goes stale.

Pods without a service account run as the namespace's `default` account, which every pod there shares. Create a dedicated one. To stop a deleted and recreated account with the same name from matching, add the condition `kubernetes.io › serviceaccount › uid` is the account's UID:

```bash theme={null}
kubectl get sa usage-worker -n billing -o jsonpath='{.metadata.uid}'
```

### Other OIDC issuers

Choose **Other OIDC** for any issuer that publishes `/.well-known/openid-configuration` and a JWKS over public HTTPS. The rule matches the token's `sub` claim exactly. Tokens must be signed with an asymmetric algorithm (RS, PS or ES families, or EdDSA) and include `exp` and `iat`.

## Exchange the token

Send the platform token to `POST https://api.useautumn.com/v1/auth.exchange_token`. No API key is needed. The endpoint follows [RFC 8693](https://datatracker.ietf.org/doc/html/rfc8693) and accepts a form body or JSON.

| Parameter | Required | Value |
| - | - | - |
| `grant_type` | Yes | `urn:ietf:params:oauth:grant-type:token-exchange` |
| `subject_token_type` | Yes | `urn:ietf:params:oauth:token-type:jwt` (`...:id_token` also works) |
| `subject_token` | Yes | The platform token |
| `audience` | Azure only | Your Autumn audience, when the token's `aud` is your own app |

```bash Form theme={null}
curl https://api.useautumn.com/v1/auth.exchange_token \
  --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
  --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
  --data-urlencode "subject_token=$OIDC_TOKEN"
```

```bash JSON theme={null}
curl https://api.useautumn.com/v1/auth.exchange_token \
  --header 'Content-Type: application/json' \
  --data '{
    "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
    "subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
    "subject_token": "'"$OIDC_TOKEN"'"
  }'
```

```bash Azure theme={null}
curl https://api.useautumn.com/v1/auth.exchange_token \
  --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
  --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
  --data-urlencode "subject_token=$OIDC_TOKEN" \
  --data-urlencode "audience=$AUTUMN_AUDIENCE"
```

A successful exchange returns:

```json theme={null}
{
  "access_token": "<your access token, starting with am_wit_>",
  "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "balances:write customers:write"
}
```

`expires_in` is in seconds and comes from the rule's lifetime. `scope` lists the scopes the matching rule grants, separated by spaces.

The exchange is stateless. You can exchange the same platform token as many times as you like until it expires, so there's nothing to coordinate between replicas.

## Call Autumn with the token

Use the access token anywhere you'd use a secret key:

```bash theme={null}
curl --request POST \
  --url https://api.useautumn.com/v1/track \
  --header "Authorization: Bearer $AUTUMN_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{ "customer_id": "user_123", "feature_id": "messages", "value": 1 }'
```

The token works only in the rule's environment and only for the rule's scopes. Keep it in memory and reuse it. Get a fresh platform token and exchange again shortly before `expires_in` runs out, or when a call returns 401.

## Conditions

Conditions narrow a rule to some runs of a workload. Every condition has to match, on top of the issuer and workload ID. They can only make a rule stricter.

![The Only when section with two conditions: environment is production and ref is refs/heads/main](https://mintcdn.com/autumn-b9b4c0fb/ROEXCfKuJHVz--6U/images/workload-identity/conditions.png?fit=max\&auto=format\&n=ROEXCfKuJHVz--6U\&q=85\&s=2807ea22e4d0a5fd2d4470bf217766f9)

Each condition checks one claim in the platform token:

| Operator | Matches when the claim |
| - | - |
| **is** | Equals the value |
| **is not** | Doesn't equal the value |
| **is one of** | Equals any value in a comma-separated list, like `main, release` |
| **starts with** | Starts with the value, like `refs/tags/` |
| **ends with** | Ends with the value |

* A claim that's missing from the token never matches, not even **is not**. A condition can't pass because a claim is absent.
* Nested claims are a list of keys, shown as `kubernetes.io › serviceaccount › uid`. Dots inside a key stay part of that key.
* Numbers and booleans are compared as text, so `ref_protected` is `true` works.
* A rule can have up to 10 conditions.

Some common ones:

| Platform | Condition | Effect |
| - | - | - |
| GitHub Actions | `environment` is `production` | Only jobs that deploy to the production environment |
| GitHub Actions | `ref` is `refs/heads/main` | Only runs on `main` |
| GitHub Actions | `ref` starts with `refs/tags/` | Only tag builds |
| GitLab CI | `ref_protected` is `true` | Only protected branches and tags |
| Vercel | `environment` is `production` | No preview or development deployments |
| Kubernetes | `kubernetes.io › serviceaccount › uid` is the UID | Only this exact service account, not a recreated one |
| Kubernetes | `kubernetes.io › namespace` is `billing` | Only pods in one namespace |

## Permissions and lifetime

Pick a preset, or click **Edit** to choose exact scopes:

| Preset | Grants |
| - | - |
| Ledgering | Check access and track usage |
| Manage customers | Ledgering, plus create, update and delete customers |
| Manage customers & billing | The above, plus attach plans and handle billing |
| Manage catalog | Create and update plans, features and rewards |
| Read only | Read everything, change nothing |
| Administrator | Read and write everything |

A rule can't grant scopes you don't have yourself.

The lifetime is how long each access token lasts: 15 minutes, 1 hour, 6 hours or 12 hours. Shorter is safer. The workload just exchanges again when a token expires.

## Edit or revoke a rule

Click a rule to see its details and the exchanges it served in the last 7 days.

![The detail sheet for the deploy-bot rule, showing its issuer, workload, permissions, lifetime and conditions](https://mintcdn.com/autumn-b9b4c0fb/ROEXCfKuJHVz--6U/images/workload-identity/rule-detail.png?fit=max\&auto=format\&n=ROEXCfKuJHVz--6U\&q=85\&s=1b2513d58017c91224955a4cf4e7c860)

You can change a rule's name, conditions, permissions and lifetime. To change the platform, issuer or workload, create a new rule.

Editing or deleting a rule revokes every access token it issued within a few seconds. Calls with those tokens return 401, and workloads pick up the new settings at their next exchange. If your organization uses [approval rules](https://docs.useautumn.com/documentation/approval-rules.md), changes that widen a rule, like adding scopes or removing a condition, may need approval.

## Troubleshooting

A rejected exchange returns 401 with code `invalid_grant`. Read `details.reason` to see why:

```json theme={null}
{
  "message": "Workload token rejected: no_matching_rule",
  "code": "invalid_grant",
  "details": { "reason": "no_matching_rule" }
}
```

Branch on `details.reason`, not on the message text, which may change.

| `details.reason` | What it means |
| - | - |
| `malformed_token` | The subject token isn't a JWT, or has no `iss` claim |
| `unsupported_algorithm` | The token isn't signed with an asymmetric algorithm. HS256 and unsigned tokens are refused |
| `token_expired` | The platform token has expired. Request a new one right before you exchange |
| `claims_invalid` | The token is missing `exp` or `iat`, or a time claim is invalid |
| `audience_parameter_invalid` | The token's audience isn't an Autumn audience and no valid `audience` parameter was sent. Check you requested the right audience, or send `audience` for Azure |
| `no_rules_for_audience` | There are no rules in the organization and environment the audience names. Check the org ID and `sandbox` or `live` |
| `no_rule_for_issuer` | No rule trusts the token's `iss`. Compare it with the rule's issuer character for character, including any trailing slash |
| `audience_mismatch` | The token's `aud` doesn't match. For Azure, check the rule's audience against the token's `aud` |
| `signature_invalid` | The signature didn't verify against the issuer's published keys |
| `issuer_url_invalid` | The issuer isn't a valid URL |
| `issuer_url_not_allowed` | The issuer isn't public HTTPS, or resolves to a private address |
| `issuer_unreachable` | Autumn couldn't reach the issuer to fetch its keys |
| `issuer_response_invalid` | The issuer's discovery document or key set isn't valid |
| `no_matching_rule` | The token verified, but no rule matched its workload claim or conditions. Check the workload ID and every condition |

When you call the API with an access token, two more 401 messages can come back:

* **Invalid or expired workload token**: the access token has expired or is malformed. Exchange again.
* **Workload token revoked**: its rule was edited or deleted. Exchange again to get a token under the current rule.

Exchanges are rate limited per client IP and per organization. Over the limit, the endpoint returns 429 with code `rate_limit_exceeded`. A workload only needs to exchange about once per token lifetime, so normal traffic stays well below it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.