Interview Prep/DevSecOps/Kubernetes Security

How do you stop pods from getting a service account token they never use?

BeginnerScenarioKubernetes Security
Answer

Situation read → By default every pod gets a token for its service account. If the app is compromised, that token talks to the API.

What I'd do →

  1. Set automountServiceAccountToken: false on the default service account in each namespace and on pod specs that do not call the API.
  2. Create dedicated service accounts for workloads that need API access, with minimal Roles.
  3. Rely on projected, time-bound tokens (default since 1.22) rather than legacy Secret-based tokens.
  4. Audit for leftover legacy token Secrets: kubectl get secrets -A --field-selector type=kubernetes.io/service-account-token.

Why → Most apps never talk to the Kubernetes API; giving them a token only helps an attacker.

Interview tip → Mention the default service account; it often has extra permissions someone added.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Kubernetes Security