---
title: "Authenticate Kubernetes workloads with workload identity federation"
description: "Let pods call Limrun with their service account token instead of a stored API key."
sidebar:
  label: "Kubernetes"
  order: 5
---

A pod can mount a service account token for the audience `limrun` and exchange it for a short-lived Limrun access token. The kubelet rotates the token file, and the CLI and SDKs read it again whenever they renew, so no Limrun API key is stored in the cluster.

## Before you start

You need:

- The `admin` role in your Limrun organization.
- `kubectl` access to the cluster, and permission to edit the workload's pod spec.
- The namespace and service account the workload runs as.

## Find your cluster's issuer and keys

Limrun verifies tokens against your cluster's public signing keys, so it needs the issuer and the key set's URL. Print both from the cluster's discovery document:

```bash
kubectl get --raw /.well-known/openid-configuration
```

Copy `issuer` and `jwks_uri` exactly. The key path differs by platform; on EKS, for example, it is `/keys` under the issuer.

Limrun must be able to fetch `jwks_uri` from the internet without credentials:

- **EKS** serves each cluster's discovery document and keys publicly and anonymously.
- **GKE** serves the cluster's keys from `container.googleapis.com`. Check that `jwks_uri` answers an anonymous `curl` before you continue.
- **Other clusters** often serve the keys only through the API server. Publish them at a public HTTPS URL and point the API server's `--service-account-jwks-uri` flag at it. If the API server itself is reachable from the internet, you can instead let anonymous users read the discovery endpoints by binding the `system:service-account-issuer-discovery` ClusterRole to `system:unauthenticated`.

## Create the provider

Your cluster signs tokens for every pod in it, so the provider condition limits trust to the workloads that should reach Limrun.

1. Open [console.limrun.com](https://console.limrun.com), go to **Settings**, then **Workload identity federation**, and click the **+** button next to **Identity providers**.
2. In **Issuer**, choose **Kubernetes**.
3. Enter a provider name, paste `issuer` as the **Issuer URL** and `jwks_uri` as the **JWKS URL**.
4. Keep **Token audience** as `limrun`. The pod mounts its token with this audience.
5. In **Provider condition (CEL)**, name the service account:

   ```text
   assertion.sub == 'system:serviceaccount:NAMESPACE:SERVICE_ACCOUNT'
   ```

   To trust every service account in one namespace and choose among them in bindings, use `assertion.sub.startsWith('system:serviceaccount:NAMESPACE:')` instead.
6. Click **Create provider**. Limrun fetches the keys before it saves the provider, so a key URL it cannot reach fails here.

## Create a binding

1. In the provider's card, click the **+** button next to **Bindings**.
2. Enter a name and a **Claim condition (CEL)**, such as `assertion.sub == 'system:serviceaccount:builds:ci'`. Kubernetes also adds a `kubernetes.io` claim with the namespace, service account, and pod. Its name contains a dot, so read it by index, for example `assertion['kubernetes.io'].namespace == 'builds'`.
3. Enter the permissions the workload needs, one per line, such as `xcode:*:all`.
4. Click **Create binding**, expand **Setup**, and copy the binding ID.

## Mount the token in the pod

Add a projected service account token with the audience `limrun`, and point the workload at it:

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: limrun-client
  namespace: builds
spec:
  serviceAccountName: ci
  containers:
    - name: client
      image: node:22
      command: ["sh", "-c", "npm install --global lim && lim whoami && sleep infinity"]
      env:
        - name: LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE
          value: /var/run/secrets/limrun/token
        - name: LIMRUN_WORKLOAD_IDENTITY_BINDING_ID
          value: binding_REPLACE_WITH_BINDING_ID
      volumeMounts:
        - name: limrun-token
          mountPath: /var/run/secrets/limrun
          readOnly: true
  volumes:
    - name: limrun-token
      projected:
        sources:
          - serviceAccountToken:
              audience: limrun
              expirationSeconds: 3600
              path: token
```

`audience` must match the provider's audience. `expirationSeconds` must be at least 600; the kubelet replaces the file once the token is 80% through its lifetime. Mount the volume as a directory, not with `subPath`, because a `subPath` mount never sees the rotated file. The pod's logs show `lim whoami` printing your organization and the binding's permissions. The SDKs read the same environment variables.

## Give each service account its own folder

One binding can serve every service account in a namespace and still keep their resources apart. Its permissions name a folder after the service account that presents the token, read from the `kubernetes.io` claim. See [Name targets from claims](/access/workload-identity-federation#name-targets-from-claims) for the syntax.

Create the provider with the namespace-wide condition from step 5, `assertion.sub.startsWith('system:serviceaccount:builds:')`. Then create one binding with the claim condition `assertion['kubernetes.io'].namespace == 'builds'` and these permissions:

```text
asset:name/k8s/${assertion['kubernetes.io'].serviceaccount.name}/*:all
android:name/k8s/${assertion['kubernetes.io'].serviceaccount.name}/*:all
```

Saving the binding requires `asset:*:all` and `android:*:all`. Service account names are lowercase, so they are valid in instance names without changes.

Run each workload with the pod spec above, changing only `serviceAccountName`. Both pods use the same binding ID. Each one's `lim whoami` lists its own folder:

| Service account | Permissions after the exchange |
| --- | --- |
| `checkout-ci` | `asset:name/k8s/checkout-ci/*:all`, `android:name/k8s/checkout-ci/*:all` |
| `payments-ci` | `asset:name/k8s/payments-ci/*:all`, `android:name/k8s/payments-ci/*:all` |

The pod running as `checkout-ci` can create and read assets under `k8s/checkout-ci/`. Creating an asset under `k8s/payments-ci/` returns HTTP `403`, and the same holds the other way around. The token holds exactly one Android folder, so `lim android create` names new emulators inside `k8s/checkout-ci/` without a name flag, and `--reuse-if-exists` finds only the instances in that folder.

A new service account in the namespace gets its own folder from the same binding, with no change in Limrun.

## Things to know

- **Avoid the default service account token.** The token Kubernetes mounts by default carries the API server's audience, so it is also a credential for your cluster. You can still use it by setting the provider's audience to match, but Limrun then receives a token your API server accepts.
- **Tokens outlive their pods.** Limrun verifies tokens offline, so a token from a deleted pod works until it expires. Keep `expirationSeconds` as short as your workload allows.
- **Clusters that rotate keys.** EKS rotates its signing key every seven days. Limrun refreshes stored keys about every 48 minutes; see [Signing key refresh](/access/workload-identity-federation#signing-key-refresh).

See [Kubernetes service account token projection](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#launch-a-pod-using-service-account-token-projection) for the Kubernetes side.
