Description
Pods using the same serviceAccountName in a namespace share API permissions even when they receive separate Pod-bound tokens. Replicas of one application can share an account if they need the same access.
Potential impact
When workloads need different permissions, either can use grants intended for the other. A token exposed by one Pod puts the shared account’s resources at risk, and requests can be difficult to attribute.
Remediation
Assign separate ServiceAccounts to workloads with different access requirements. Check each account’s role bindings and verify it can perform only the operations it needs.
Examples
Both Pods run in the same namespace. Create the referenced accounts and role bindings first.
Before
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
serviceAccountName: service1
containers:
- name: mycontainer
image: redis
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
spec:
serviceAccountName: service1
containers:
- name: envars-test-container
image: nginx
After
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
serviceAccountName: service1
containers:
- name: mycontainer
image: redis
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
spec:
serviceAccountName: service2
containers:
- name: envars-test-container
image: nginx
Explanation:
- Before: Both
pod1andpod2use the permissions ofservice1. - After:
pod2now usesservice2. Give each account bindings that reflect its Pod’s needs.