Authenticate Kubernetes workloads with workload identity federation
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
adminrole in your Limrun organization. kubectlaccess 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:
kubectl get --raw /.well-known/openid-configurationCopy 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 thatjwks_urianswers an anonymouscurlbefore 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-uriflag at it. If the API server itself is reachable from the internet, you can instead let anonymous users read the discovery endpoints by binding thesystem:service-account-issuer-discoveryClusterRole tosystem: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.
-
Open console.limrun.com, go to Settings, then Workload identity federation, and click the + button next to Identity providers.
-
In Issuer, choose Kubernetes.
-
Enter a provider name, paste
issueras the Issuer URL andjwks_urias the JWKS URL. -
Keep Token audience as
limrun. The pod mounts its token with this audience. -
In Provider condition (CEL), name the service account:
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. -
Click Create provider. Limrun fetches the keys before it saves the provider, so a key URL it cannot reach fails here.
Create a binding
- In the provider's card, click the + button next to Bindings.
- Enter a name and a Claim condition (CEL), such as
assertion.sub == 'system:serviceaccount:builds:ci'. Kubernetes also adds akubernetes.ioclaim with the namespace, service account, and pod. Its name contains a dot, so read it by index, for exampleassertion['kubernetes.io'].namespace == 'builds'. - Enter the permissions the workload needs, one per line, such as
xcode:*:all. - 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:
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: tokenaudience 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.
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
expirationSecondsas 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.
See Kubernetes service account token projection for the Kubernetes side.
Let pods call Limrun with their service account token instead of a stored API key.
Was this guide helpful?