Sub topic 8
Exchanging a Kubernetes token for cloud credentials
This chapter assumes you know what a ServiceAccount is, how RBAC works, and that a projected token is a signed, audience-bound JWT. It also assumes you have seen the cluster's OIDC discovery documents. Here you will see how a cloud provider turns that token into cloud credentials.
The problem federation solves
A Pod often needs to call a cloud API, such as reading an object from storage. The old answer was to create a long-lived access key and store it in a Secret. That key can leak, it rarely gets rotated, and it works from anywhere.
Workload identity federation removes the key. The cloud provider trusts the cluster to vouch for the Pod. The Pod presents a short-lived token that the cluster signed, and the provider returns short-lived cloud credentials in exchange.
The exchange step by step
- You register the cluster's OIDC issuer URL with the cloud provider as a trusted identity provider.
- The kubelet projects a service account token into the Pod. The token has a cloud-specific audience, such as
sts.amazonaws.com. - The workload, usually through a cloud SDK, sends that token to the provider's security token service.
- The provider fetches the cluster's public signing keys from the discovery endpoint and verifies the signature.
- The provider checks the claims against a trust policy you wrote: issuer, audience, and subject.
- If all checks pass, the provider returns temporary credentials. The SDK uses them for API calls and refreshes them before they expire.
Which claims matter
The provider reads three claims from the token. Your trust policy decides what values it accepts.
| Claim | Meaning | Example |
|---|---|---|
| `iss` | The cluster's issuer URL | `https://oidc.eks.us-east-1.amazonaws.com/id/EXAMPLE` |
| `aud` | Who the token is meant for | `sts.amazonaws.com` |
| `sub` | The identity of the workload | `system:serviceaccount:demo:app-reader` |
The sub claim always has the form system:serviceaccount:<namespace>:<name>. The aud claim stops a token minted for one service from being replayed at another. You can inspect these claims on a token you request yourself:
TOKEN=$(kubectl create token app-reader -n demo --audience=sts.amazonaws.com)
echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null | head -c 600; echoRun this only on a test token. A bearer token is a credential until it expires, so do not paste real tokens into tickets or chat.
Why the cloud never contacts your cluster directly
The provider only needs the public keys, so it does not need network access into your cluster. It reads the issuer's discovery document and key set. For private clusters, the keys can be published at a public URL, as long as the issuer URL in the tokens matches the registered one. If the issuer in the token does not match the registered issuer exactly, the exchange fails.
What stays the same across providers
The mechanics differ in names and setup. EKS, GKE, and AKS all follow the same pattern: trust the issuer, mint an audience-bound token, verify claims, and return short-lived credentials. The following chapters show each provider's configuration.
Exercise
A Pod presents a valid, unexpired token to a cloud provider's token service, but the exchange is rejected. The issuer is registered and the signature is valid. Name two claims you would check next, and say what you would compare each against.
Show answer
Check aud against the audience the provider expects (for example sts.amazonaws.com), and check sub against the subject in the trust policy, which must match system:serviceaccount:<namespace>:<name> for the Pod's ServiceAccount. A wrong audience or a subject for a different namespace or ServiceAccount causes rejection even when the signature is valid.