Authentication and service accounts
Who is making the request?
A bookstore operator and a catalog application both need to talk to Kubernetes, but they should not share credentials. Authentication establishes a principal from a request. Authorization decides whether that principal may perform an operation. Admission then evaluates applicable writes. A successful login is not permission to change every resource.
request -> identity -> permission decision -> applicable admission -> storageHuman identities and kubeconfig
Human users are normally represented by identities supplied through an external authentication system rather than ordinary User API objects. A client certificate can map its subject to a username and groups when the cluster trusts its signer. With configured OIDC, a signed identity token is validated against the issuer, audience and other required claims. A kubeconfig context selects a cluster, user configuration and optionally a namespace; its name is not proof of the authenticated identity. Inspect only a known lab configuration and never print tokens or private keys.
context: book-lab-readercluster: disposable-book-labuser configuration: fixture-humannamespace: book-lab# Illustrative summary, not a kubeconfig fileWorkload identity and token lifecycle
A ServiceAccount is a namespaced API object. The catalog-reader account in book-lab is distinct from an identically named account in another namespace. Modern clusters normally use short-lived projected credentials obtained via TokenRequest; kubelet refreshes projected tokens and applications must reread the file when needed. Audience and expiry constrain use, and object binding can limit validity. A decoded token is not proof that its signature or claims are valid. Do not copy tokens into environment logs or Git.
principal: system:serviceaccount:book-lab:catalog-readercredential: projected token (not displayed)audience: configured API audienceexpiration: time-limitedDisable automatic credentials when unnecessary
The following static site does not use the Kubernetes API. The Pod explicitly opts out of automatic credential mounting. The ServiceAccount still exists and may have permissions, but this Pod does not automatically receive its API token. Pod-level automount configuration overrides the account setting. This does not block explicit projected volumes or other credential sources. The image is intentionally non-deployable.
apiVersion: v1kind: ServiceAccountmetadata: name: catalog-reader namespace: book-lab---apiVersion: v1kind: Podmetadata: name: static-catalog namespace: book-labspec: serviceAccountName: catalog-reader automountServiceAccountToken: false containers: - name: catalog image: registry.example.invalid/catalog:fixture resources: requests: {cpu: 50m, memory: 32Mi} limits: {cpu: 100m, memory: 64Mi}Common mistake: sharing an operator credential
An application should have a dedicated identity and only its required permissions. Do not give it the operator kubeconfig. An expired token can lead to authentication failure, whereas a valid identity with insufficient access can be refused by authorization. Anonymous handling depends on cluster configuration. Practice with identity-cases.json, and distinguish credential lifecycle from permission policy.
Invalid credential: investigate authenticationValid identity, missing grant: investigate authorizationNo token required: avoid automatic mountingCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Authentication and service accounts — knowledge check
Interpret synthetic identity and permission evidence.
What does authentication establish?
Which identity is namespaced?
What normally refreshes a projected ServiceAccount token?
What does automountServiceAccountToken: false do on a Pod?
What proves a decoded JWT is authentic?