Example Documentation: ServiceAccount API Access
Goal
Limit API access from Pods using ServiceAccounts, token mounts and RBAC.
What Is Done
The lab creates a Pod without an automatically mounted token and a Job with a ServiceAccount, Role and RoleBinding for reading Pods.
Typical Commands
kubectl apply -f manifests/
kubectl auth can-i list pods --as=system:serviceaccount:api-access-lab:pod-reader -n api-access-lab
kubectl logs -n api-access-lab job/api-reader
kubectl describe pod -n api-access-lab no-token
Validate Success
pod-readercan list Pods.- The Job can show Pods in the namespace.
- Pod
no-tokenhas no automatically mounted ServiceAccount token.
Common Mistakes
automountServiceAccountToken: falseis forgotten.- The RoleBinding references the wrong namespace.
kubectl auth can-iis checked without--as.