ExamPilot Global home

CKS lab · Verify least-privilege workload access

A service account needs only list access to Pods in one namespace.

ExamPilot graduation owl

Initial conditions

Create a disposable namespace lab. Your admin identity needs impersonation permission for the checks.

Objective

Grant the narrow Role and verify access in positive and negative cases.

Hint

Use a RoleBinding rather than a ClusterRoleBinding.

Solution commands

kubectl -n lab create serviceaccount reporter
kubectl -n lab create role pod-lister --verb=list --resource=pods
kubectl -n lab create rolebinding pod-lister --role=pod-lister --serviceaccount=lab:reporter

Validate the result

kubectl auth can-i list pods -n lab --as=system:serviceaccount:lab:reporter
kubectl auth can-i get secrets -n lab --as=system:serviceaccount:lab:reporter
kubectl auth can-i list pods -n default --as=system:serviceaccount:lab:reporter

In a clean cluster the checks should yield yes, no, no. Review all bindings if another grant overrides the expected result.

Common mistakes

Adding wildcard resources grants more than the workload needs.

Free official documentation · Verified 26 November 2026

Use your own disposable Kubernetes environment.