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 →
- Set
automountServiceAccountToken: falseon thedefaultservice account in each namespace and on pod specs that do not call the API. - Create dedicated service accounts for workloads that need API access, with minimal Roles.
- Rely on projected, time-bound tokens (default since 1.22) rather than legacy Secret-based tokens.
- 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.
More on Kubernetes Security
What are the 4Cs of cloud native security?BeginnerWhat happens to a request between `kubectl apply` and etcd from a security point of view?IntermediateExplain Role, ClusterRole, RoleBinding and ClusterRoleBinding.BeginnerHow do you check what a user or service account is allowed to do?BeginnerWhich RBAC permissions are effectively cluster-admin in disguise?AdvancedHow do service account tokens work now, and what is `automountServiceAccountToken`?Intermediate