KCNA ยท Kubernetes security
What is a ServiceAccount and how does a Pod use it?
Pod identity, token projection, default service account, granting a Pod API access.
Key points
- ServiceAccount: namespaced identity for processes in Pods.
- None named: the Pod gets the namespace's default one, with only basic API discovery permissions.
- Since v1.22: short-lived, auto-rotating token via the TokenRequest API as a projected volume.
- To call the API: create a dedicated ServiceAccount, bind a Role, set serviceAccountName.
- No API access needed: set automountServiceAccountToken to false.
Source: https://kubernetes.io/docs/concepts/security/service-accounts/
Practice questions
Which ServiceAccount does a Pod use if its spec does not set serviceAccountName?
- The default ServiceAccount of its namespace
- The cluster-admin ServiceAccount
- The kube-system ServiceAccount
- None, the Pod has no identity
Show answer
Answer: A. The default ServiceAccount of its namespace
Every namespace has a default ServiceAccount, and Pods without an explicit one use it.
Which steps let a Pod list Pods in its own namespace using least privilege?
- Create a dedicated ServiceAccount
- Add permissions to the shared default ServiceAccount
- Bind a Role allowing get and list on pods to it
- Set serviceAccountName in the Pod spec
- Embed a user password in the container image
Show answer
Answer: A. Create a dedicated ServiceAccount, C. Bind a Role allowing get and list on pods to it, D. Set serviceAccountName in the Pod spec
Create a dedicated ServiceAccount, grant it a narrow Role through a RoleBinding, and reference it from the Pod. The default account should not be given extra rights.
True or false: in current Kubernetes versions, Pods get a never-expiring token stored in a Secret by default.
Show answer
Answer: False
False. Pods receive a short-lived, rotating token via projected volume (TokenRequest). Long-lived Secret tokens are only created if you explicitly ask for them.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
