Authentication, users and service accounts
How the API server decides who is calling: client certificates, tokens, OIDC, why there is no User object, and short-lived, bound service account tokens.
The Kubernetes API and object modelkubectl, kubeconfig and contexts
Authentication, users and service accounts
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Every request is authenticated first. The result is just a username, a UID, groups and extra fields. Kubernetes stores no User objects and has no user database.
- Client certificates map CN to the username and each O to a group. Any certificate signed by the cluster CA is accepted until it expires, and there is no revocation.
- Humans should log in through OIDC (an AuthenticationConfiguration, GA since 1.34) or the cloud's authenticator, not shared certificates.
- A ServiceAccount is a real namespaced object, the identity for workloads: system:serviceaccount:<namespace>:<name>, in groups system:serviceaccounts and system:serviceaccounts:<namespace>.
- Service account tokens are short-lived JWTs from the TokenRequest API, scoped to an audience and optionally bound to a Pod. Delete the Pod and the token stops working. Long-lived token Secrets aren't created any more.
- Unauthenticated requests become system:anonymous. Authentication proves identity only. What that identity may do is RBAC's job.
Who is asking?
Every action in a cluster is an HTTPS request to the API server: a person running kubectl, a CI job deploying, a controller reconciling, a Pod reading a ConfigMap. Before the server can decide whether to allow a request, it has to know who sent it. That is authentication, the first stage of every request, before authorization and admission.
Kubernetes makes an unusual choice here: it doesn’t manage users. There is no User object, no password table, no kubectl create user. The API server trusts external sources of identity, such as a certificate authority, an OIDC identity provider or a cloud IAM system, and turns what they vouch for into a few strings. Workloads are the exception. Their identities, ServiceAccounts, are real API objects.
What authentication produces
Each authenticator that recognises a credential produces the same small record. kubectl auth whoami shows it. For a client certificate I minted against the lab cluster’s CA, with subject CN=jane, O=dev, O=oncall:
ATTRIBUTE VALUE
Username jane
Groups [dev oncall system:authenticated]
Extra: authentication.kubernetes.io/credential-id [X509SHA256=caceeed89fdd...]
That’s the whole identity: a username, groups, sometimes a UID, and “extra” key-value pairs. Everything downstream, RBAC, audit logs and admission, works from these strings. Jane exists nowhere in the cluster. She could immediately do nothing:
Error from server (Forbidden): pods is forbidden: User "jane" cannot list resource "pods" in API group "" in the namespace "default"
Note the status: Forbidden (403), not Unauthorized (401). She was authenticated fine and simply has no permissions. A self-signed certificate claiming CN=admin, O=system:masters got the other answer, 401 Unauthorized, and the API server logged x509: certificate signed by unknown authority. A request with no credentials at all wasn’t rejected outright. It became system:anonymous, which RBAC then refused, while /livez answered ok, because default RBAC lets anyone read the health endpoints.
The authenticators
The API server runs several at once and takes the first that accepts a request:
- X.509 client certificates. CN becomes the username, each O a group. Simple and widely used for components and break-glass admin access. The catch: there’s no revocation. A leaked certificate works until it expires, and one with
O=system:mastersbypasses authorization completely. Keep those offline. - OIDC tokens. The API server validates JWTs from an identity provider such as Okta, Entra ID, Keycloak or Dex, and maps claims to username and groups. Since 1.34 the structured AuthenticationConfiguration file is GA: several issuers, CEL expressions for claim mapping and validation, and reload without restarting the API server. This is the right way for people to log in, because disabling someone in the IdP ends their access.
- Webhook token authentication. The API server asks an external service whether a token is valid. Managed clusters use this or similar to map cloud IAM identities, such as AWS IAM in EKS or Google accounts in GKE.
- Service account tokens. Covered below.
- Authenticating proxy. A front proxy authenticates and passes identity headers, trusted only from a known client certificate.
ServiceAccounts: identities for workloads
Software in Pods needs an identity too, and it can’t log in to an IdP. A ServiceAccount is a namespaced object whose only job is to be that identity:
$ kubectl -n ci create serviceaccount build-bot
serviceaccount/build-bot created
$ kubectl -n ci get secrets
No resources found in ci namespace.
No Secret appeared. Until 1.24, creating a ServiceAccount also created a long-lived token Secret that never expired. Those leaked into Git repos and CI logs everywhere. Now tokens come from the TokenRequest API, on demand and short-lived:
{
"aud": ["https://kubernetes.default.svc"],
"exp": 1795893284,
"iat": 1795889684,
"iss": "https://kubernetes.default.svc",
"kubernetes.io": {
"namespace": "ci",
"serviceaccount": {"name": "build-bot", "uid": "0d0a1719-6e0c-4b34-a570-35fa769a12e4"}
},
"sub": "system:serviceaccount:ci:build-bot"
}
That is the decoded payload of kubectl -n ci create token build-bot --duration=1h: one hour from iat to exp, an audience, and a subject in the fixed format system:serviceaccount:<namespace>:<name>. whoami with that token shows the groups every service account gets: system:serviceaccounts, system:serviceaccounts:ci and system:authenticated. RBAC can grant to one account, to all accounts in a namespace, or to all of them.
Bound tokens
A Pod using serviceAccountName: build-bot gets a token through a projected volume at /var/run/secrets/kubernetes.io/serviceaccount, which the kubelet refreshes before expiry. The lab API server added it automatically: {"serviceAccountToken":{"expirationSeconds":3607,"path":"token"}}. Tokens can also be bound to an object. A token created with --bound-object-kind=Pod --bound-object-name=builder2 carried the Pod’s name and UID, and (since 1.32, GA) the node it runs on, in its claims and in whoami’s extra fields.
Binding makes stolen tokens die with their Pod. I force-deleted the Pod and kept using its token:
after +1s: Username system:serviceaccount:ci:build-bot
after +5s: Username system:serviceaccount:ci:build-bot
after +12s: error: You must be logged in to the server (Unauthorized)
The API server logged service account token has been invalidated. The few seconds of grace come from its authentication cache, which keeps successful token checks for 10 seconds (TokenSuccessCacheTTL in the source).
Audiences stop replay across systems. A token made with --audience=vault was rejected by the API server: token audiences ["vault"] is invalid for the target audiences ["https://kubernetes.default.svc"]. Workload identity federation (AWS IRSA and Pod Identity, GKE and Azure workload identity, SPIFFE) builds on exactly this: the cluster publishes its token-signing keys at its OIDC discovery endpoint, and a cloud trusts tokens minted for its audience.
Practical rules
- Give each workload its own ServiceAccount. The
defaultone in every namespace ends up shared by everything. - Set
automountServiceAccountToken: falseon Pods that never call the API. - People use OIDC or cloud IAM. Certificates are for components and sealed-away break-glass access.
- Never create long-lived token Secrets for CI. Use
kubectl create tokenor the CI platform’s OIDC federation.
About the video
The embed is Kubesimplify’s “CKS Certification - Kubernetes Authentication and RBAC”, October 2024, 19 minutes. Its chapters cover the security model, how authentication works, credentials in kubeconfig, a demo creating a user from a certificate, RBAC, and service-account scenarios. The RBAC part previews the next lesson. I judged it from chapters and description only, since transcripts couldn’t be fetched. English was judged from its “English (US) original” audio track. The Cloud Native Summit Munich talk in deeper goes into structured authentication configuration and CEL claim mapping, recorded while it was still beta.
What was run: every output above is real, from a local Kubernetes v1.37.3 API server whose nodes run no containers. That includes the minted certificate and its whoami, the 403 and 401 responses, anonymous access, the token payload, the projected volume, the Pod-bound token invalidated after its Pod was deleted, and the audience rejection. The 10-second cache is from pkg/kubeapiserver/options/authentication.go. OIDC and webhook authentication weren’t configured. They are written from the authentication docs, and the 1.34 GA date is from the feature-gate reference, checked 2026-11-28.
Where this fits
Authentication says who. Next, what they may do: RBAC.
Check yourself
An engineer leaves and their client certificate, signed by the cluster CA with O=system:masters, is still on their laptop. What can you do?
Very little short of rotating the cluster CA. Kubernetes has no certificate revocation, and system:masters bypasses RBAC entirely. That's why human access should go through OIDC or a cloud identity, where disabling the account ends access.
What does the API server conclude about a request carrying a certificate with CN=jane, O=dev, O=oncall?
If a trusted CA signed it, the user is jane in groups dev, oncall and system:authenticated. Nothing checks that jane exists anywhere. RBAC then decides what those names may do.
Why is a token from kubectl create token rejected when sent to Vault configured for audience vault, and vice versa?
The token's aud claim names who it is for. The API server only accepts its own audiences (here https://kubernetes.default.svc), and a well-configured external service only accepts tokens minted for it, so a token stolen from one system can't be replayed against another.
A Pod's token is copied out before the Pod is deleted. How long does it keep working?
For a Pod-bound token, until the API server notices the Pod is gone, about 10 seconds given its authentication cache, after which it is rejected as invalidated. Otherwise it would last until its expiry, which the kubelet keeps short and rotates.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.