Bitzu

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

Single choice

Which ServiceAccount does a Pod use if its spec does not set serviceAccountName?

  1. The default ServiceAccount of its namespace
  2. The cluster-admin ServiceAccount
  3. The kube-system ServiceAccount
  4. 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.

Select all that apply

Which steps let a Pod list Pods in its own namespace using least privilege?

  1. Create a dedicated ServiceAccount
  2. Add permissions to the shared default ServiceAccount
  3. Bind a Role allowing get and list on pods to it
  4. Set serviceAccountName in the Pod spec
  5. 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

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.

Download on the App StoreGet it on Google Play

More KCNA topics in this module