ServiceAccounts & Projected Bound Tokens
Give workloads identity with ServiceAccounts and short-lived projected tokens.
In plain words
A ServiceAccount is a robot's badge, and a bound token is a temporary lobby pass valid only for that robot, room, and visit. The simple Kubernetes rule is: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
Think of it like…
A ServiceAccount is a robot's badge, and a bound token is a temporary lobby pass valid only for that robot, room, and visit.
Where you’ve seen it
During an access review, the security engineer runs kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m. Expected evidence: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime. If the run instead shows this symptom, stop and restore the last known state: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API.
Words you’ll hear
- ServiceAccount
- For this lesson, ServiceAccount is the controlling idea: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Bound Tokens
- Bound Tokens is the checkpoint; run
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10mand inspect the owner chain. Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API. - Workload Identity
- Workload Identity is the outcome to preserve; the cost is explicit: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.
- Verification evidence
- The evidence command is
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m. It connects the declaration to this behavior: Give workloads identity with ServiceAccounts and short-lived projected tokens.
Visual diagram
Theory & deep dive
How ServiceAccount reaches the intended state
Give workloads identity with ServiceAccounts and short-lived projected tokens. A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
The concrete checkpoint is kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m; compare the ServiceAccount owner, Bound Tokens state, and Workload Identity outcome instead of treating YAML acceptance as proof.
Run kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m after the change and correlate the result with Events and the owning object. A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
Bound Tokens: failure boundary and production cost
Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API. The prerequisite contract is concrete: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy. A safe design limits blast radius, records the last good configuration, and uses kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m as a deterministic rollback checkpoint.
Capture the current state with kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API.
How it works, step by step
Step 1 of 41. Model the trust boundary
Name the identity, action, resource, and trust boundary before choosing a control: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Goal
- Give workloads identity with ServiceAccounts and short-lived projected tokens.
- Owner
- ServiceAccount
When to use it & trade-offs
What it is
Give workloads identity with ServiceAccounts and short-lived projected tokens. A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
Why it matters: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API. The invariant at risk is specific: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime. The quickest fact check before changing the design is kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m.
When to reach for it
- Use ServiceAccount to enforce this invariant: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Use Bound Tokens evidence from
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10min reviews and incident timelines. Give workloads identity with ServiceAccounts and short-lived projected tokens. - Choose the hosted security service route only when this cost is justified by governance or scale: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.
When to avoid or be careful
- Avoid assuming ServiceAccount is complete after YAML submission; the required behavior is concrete: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10mfirst: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API. - Avoid adopting a heavier platform wrapper before measuring its cost: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.
Native, manual, and managed paths for ServiceAccount
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m.Strengths: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
Watch out: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy. Recovery must also recognize this signal: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API.
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m; the expected invariant is: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.Strengths: kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike ServiceAccount, it does not make this symptom self-documenting: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API.
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
Watch out: The added platform ownership buys value at this cost: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Trace ServiceAccount to Workload Identity through Bound Tokens; the invariant is: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Recognize the symptom: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API.
- Justify the cost: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.
- Verify with kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m instead of only inspecting YAML.
Benchmarks & rules of thumb
- 3
- bound-token dimensions: audience, expiry, and Pod identity
- 10m
- example short-lived token for inspection
- 0
- legacy token Secret rotation after automatic pod expiry should be assumed
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the ServiceAccount owner contract: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime.
- Ignoring this telltale condition leads to unrelated changes: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API.
- Repeating
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10mwithout an owner for remediation wastes retry cost. Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime?
- Which owner object, logs, and Events would you inspect for this symptom-Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API-?
- At what threshold would this cost become unacceptable: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy?
kubectl get serviceaccount api -o yaml; kubectl create token api --audience=api.example --duration=10m, name the failure, then justify the cost. Invariant: A ServiceAccount identifies a workload, and projected bound tokens encode audience, expiry, and Pod binding so rotation can invalidate a token with its Pod lifetime. Failure: Kubelet token mounting or a legacy auto-generated long-lived Secret can expose cluster credentials, and a token audience intended for a cloud provider will not authenticate to the Kubernetes API. Cost: Bound tokens reduce credential persistence, but applications must refresh mounted files and each external exchange needs an explicit audience and trust policy.Knowledge check
Put it into practice
Practice related interview Q&A
Apply ServiceAccounts & Projected Bound Tokens with generative AI interview Q&A and hands-on practice.