⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Kubernetes Interview Questions Scenario 97 of 207 in Kubernetes
Senior DevOps / SRE [L2] Kubernetes Advanced Scenarios Production Scenario [L2]
🎯 Target Role / Context: Kubernetes Scenario #87 (L2) · Advanced Scenarios

Q: How do you check if a service account has permission to create pods?

kubectl auth can-i create pods --as=system:serviceaccount:<namespace>:<sa-name>

#Kubernetes #Advanced Scenarios #L2 #Container Orchestration #K8s
🎙️ Candidate Opening & Architectural Context
"<strong>To check if a service account has permission to create pods, run <code>kubectl auth can-i create pods --as=system:serviceaccount:&lt;namespace&gt;:&lt;name&gt; -n &lt;namespace&gt;</code>.</strong> The command asks the API server's authorizer and returns <code>yes</code> or <code>no</code> without creating anything. Interviewers ask this to see whether you can debug <code>403 Forbidden</code> errors systematically: verify the identity, test the verb and resource, trace the RoleBinding, and know that Pod creation can also be blocked by admission (Pod Security, quotas), which is a different layer from RBAC."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: <strong>To check if a service account has permission to create pods, run <code>kubectl auth can-i create pods --as=system:serviceaccount:&lt;namespace&gt;:&lt;name&gt; -n &lt;namespace&gt;</code>.</strong> The command asks the API server's authorizer and returns <code>yes</code> or <code>no</code> without creating anything. Interviewers ask this to see whether you can debug <code>403 Forbidden</code> errors systematically: verify the identity, test the verb and resource, trace the RoleBinding, and know that Pod creation can also be blocked by admission (Pod Security, quotas), which is a different layer from RBAC.

1️⃣

Mental model: identity, verb, resource, scope

RBAC is additive allow-only. A request is permitted if any binding grants the verb on the resource in that namespace.

  • Identity: a service account is the user system:serviceaccount:<ns>:<name>, plus the groups system:serviceaccounts and system:serviceaccounts:<ns>.
  • Verb and resource: creating a pod is verb create on resource pods in the core API group (empty string). Controllers like Deployments create pods through the controller-manager's identity, not your service account.
  • Scope: a Role plus RoleBinding applies in one namespace, whereas a ClusterRole bound with a ClusterRoleBinding applies everywhere. A ClusterRole bound via RoleBinding is limited to that namespace.
  • Default: a new service account has no permissions beyond those given to the system:authenticated and discovery groups.
  • Aggregated roles: built-in ClusterRoles such as edit and admin include create on pods, and they can be extended through aggregation labels, so a service account may gain permission indirectly through a role you never edited.
2️⃣

Hands-on: check if a service account has permission to create pods

Use impersonation with kubectl auth can-i. Your own user needs the impersonate permission for serviceaccounts, which cluster admins have.

# Can the SA create pods in 'prod'?
kubectl auth can-i create pods \
  --as=system:serviceaccount:prod:deployer -n prod
# yes / no

# Everything the SA may do in that namespace
kubectl auth can-i --list \
  --as=system:serviceaccount:prod:deployer -n prod

# Check the related subresource used for exec
kubectl auth can-i create pods/exec \
  --as=system:serviceaccount:prod:deployer -n prod

# Check yourself or from inside a pod using the mounted token
kubectl auth can-i create pods -n prod
  • Basic test: run the command with --as and the namespace.
  • Explain the result: add -v=6 for the API calls, or ask for the full permission list with --list to see everything allowed in that namespace.
  • Cluster-wide: use -A or --all-namespaces, or omit -n for a cluster-scoped resource check.
  • Exit status: the command exits 0 for yes and 1 for no, so it fits shell checks and CI.
  • Impersonation rights: if --as returns forbidden, your own user lacks the impersonate verb on serviceaccounts. Test from inside a pod using that service account's token instead, which is the most realistic check.
Advertisement
3️⃣

Trace why the answer is yes or no

If the result surprises you, locate the binding and the role rules that grant or deny it.

# Dry-run a real create as the service account (includes admission)
kubectl run probe --image=registry.k8s.io/pause:3.9 \
  --as=system:serviceaccount:prod:deployer -n prod --dry-run=server

# Grant it if missing
kubectl -n prod create role pod-creator --verb=create --resource=pods
kubectl -n prod create rolebinding deployer-pod-creator \
  --role=pod-creator --serviceaccount=prod:deployer
  • Find bindings: list RoleBindings and ClusterRoleBindings and filter for the service account subject, for example with kubectl get rolebinding,clusterrolebinding -A -o wide and a grep on the name.
  • Read the role: kubectl describe role or clusterrole and look for pods with create. Remember apiGroups: [""] for pods.
  • Wrong subject namespace: a binding subject must name the service account's namespace. A common mistake is omitting it, so the binding silently matches nothing.
  • Real-request test: kubectl auth can-i evaluates RBAC only. For an end-to-end check, run a server-side dry-run create as the service account.
  • Reverse lookup: use a plugin such as kubectl-who-can with kubectl who-can create pods -n prod to list every subject allowed, which is useful during access reviews and incident response.
4️⃣

Failure modes: allowed by RBAC, still rejected

A yes from RBAC does not guarantee pod creation. Other layers evaluate the request after authorization.

  • Pod Security Admission: a namespace labelled pod-security.kubernetes.io/enforce: restricted rejects privileged or root pods regardless of RBAC.
  • Quota and limits: ResourceQuota or LimitRange violations return 403 style errors with the quota name in the message.
  • Webhooks and policy engines: Kyverno, OPA Gatekeeper or custom webhooks can deny pods that RBAC allowed.
  • Other subresources: creating pods does not cover pods/exec, pods/portforward or serviceaccounts/token, which need their own rules.
  • Authorization modes: RBAC may not be the only authorizer. Webhook authorizers or cloud IAM integrations can add or deny access, so remember that can-i reports the combined decision of the configured authorizers.
Pro Tip: Read the exact 403 message. RBAC denials say <code>User ... cannot create resource "pods"</code>, while admission denials name the policy, quota or webhook.
5️⃣

Production practice: least privilege and auditing

Treat pod-creation rights as high privilege, because anyone who can create pods can often mount secrets or escalate.

  • Scope narrowly: prefer namespaced Roles, and avoid wildcard verbs. Use resourceNames where possible.
  • Automate checks: run kubectl auth can-i assertions in CI after applying RBAC manifests, and fail if privileged accounts gain create on pods unexpectedly.
  • Audit tools: kubectl-who-can or rakkess plugins answer the reverse question of who can create pods.
  • Short-lived tokens: rely on projected, time-bound service account tokens, and disable automounting with automountServiceAccountToken: false for pods that never call the API.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: kubectl auth can-i tests RBAC only; follow it with a server-side dry-run as the service account to catch Pod Security, quota and webhook denials too."
⚡ 60-Second Elevator Pitch Talking Points
  • Use kubectl auth can-i create pods with --as=system:serviceaccount:namespace:name to ask the API server's authorizer directly.
  • If the answer is unexpected I trace RoleBindings and ClusterRoleBindings for that subject, then confirm end to end with a server-side dry-run create.
  • I automate can-i assertions in CI and keep pod-create rights narrowly scoped, since create pods is effectively a privileged permission.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Testing with your own admin credentials You get yes because you are cluster-admin, which says nothing about the service account.
  2. Forgetting the namespace in the binding subject The RoleBinding then references a service account that does not match, and access is silently denied.
  3. Treating can-i yes as proof pods will be created Pod Security Admission, quotas and webhooks can still reject the request.
  4. Granting create on pods broadly to fix a 403 Pod creation can be used to mount secrets and escalate, so over-granting is a security risk.
Advertisement
📥 FREE DOWNLOAD · 101-PAGE COMPANION HANDBOOK
Studying for Kubernetes & SRE Technical Rounds?
Download the complete 100-question PDF field guide covering all 11 core modules with offline diagnostic runbooks.
📥 Download PDF (Free) Read Online Guide →
Want more Kubernetes scenarios?
Explore our complete collection of scenario-based Kubernetes interview runbooks.
Browse All Kubernetes Questions →