Sub topic 7
The cluster as an OIDC identity provider
This chapter assumes you know what a ServiceAccount is, how RBAC authorizes it, and how projected tokens carry an audience and an expiry. It explains why a cloud provider can trust a token that your cluster signed.
Why the cluster acts as an identity provider
A cloud provider has no built-in knowledge of your cluster. It cannot ask the Kubernetes API server "is this Pod really demo/app-reader?" for every request. Instead, the cluster publishes enough public information for the provider to check a token on its own.
This is OpenID Connect (OIDC) discovery. The API server signs service account tokens as JSON Web Tokens (JWTs). It also publishes two documents:
- A discovery document that names the issuer and points to the keys.
- A JSON Web Key Set (JWKS) that holds the public keys matching the private signing key.
A verifier fetches these documents, then checks a token's signature without contacting the cluster again for each token.
What the token claims
A projected token is a JWT with these claims:
| Claim | Meaning | Example |
|---|---|---|
| `iss` | The issuer URL of the cluster | `https://oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED...` |
| `sub` | The identity of the ServiceAccount | `system:serviceaccount:demo:app-reader` |
| `aud` | The intended recipient | `sts.amazonaws.com` |
| `exp` | When the token expires | a Unix timestamp |
The iss claim tells the provider where to find the keys. The sub and aud claims are what trust policies match on. The next chapters cover those policies.
Reading the discovery documents
You can read both documents from the API server:
kubectl get --raw /.well-known/openid-configuration
kubectl get --raw /openid/v1/jwksThe first command returns the issuer, the jwks_uri, and the supported signing algorithms. The second returns the public keys, each with a key ID (kid). Each token header carries a kid so the verifier picks the matching key.
How verification works
The diagram below shows the order of events.
The provider must be able to reach the issuer URL, or already hold a copy of the keys. Managed services handle this for you. EKS, GKE, and AKS each host the documents at a public URL. On a self-managed cluster you must set the issuer yourself, using the API server flag --service-account-issuer, and expose the documents to the provider.
Common errors
- Issuer mismatch. The
issin the token must match the issuer registered with the cloud provider exactly, including the scheme and any trailing path. A change to--service-account-issuerbreaks every existing trust relationship. - Unreachable issuer. If the provider cannot fetch the keys, verification fails even when the token is valid. Private clusters need the documents published somewhere the provider can read.
- Key rotation. The API server rotates signing keys. Providers re-fetch the JWKS, but a stale cache can briefly reject new tokens.
- Unauthenticated discovery access. The discovery endpoints contain only public data. Do not expose anything else from the API server to make them reachable.
Exercise
A token's iss is https://oidc.example.com/cluster-a, but the cloud provider is configured to trust https://oidc.example.com/cluster-a/. Verification fails although the signature is valid. Why, and what do you change?
Show answer
The provider compares the issuer string exactly, and the trailing slash makes the two values different. Register the provider with the exact iss value that appears in the token, without the trailing slash, or change the cluster's --service-account-issuer to match. Prefer changing the provider side, since changing the cluster issuer invalidates all existing trust.