Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 105/ 160
06. Security, RBAC & Governance

Auditing & Debugging RBAC Permissions (kubectl auth can-i)

Debug permission denials with kubectl auth can-i and RBAC inspection.

Intermediatecan-i · RBAC Debug · Audit3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

RBAC debugging is testing a simulated keycard at one specific door and checking the issuer's access ledger when it fails. The simple Kubernetes rule is: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

Think of it like…

RBAC debugging is testing a simulated keycard at one specific door and checking the issuer's access ledger when it fails.

Where you’ve seen it

During an access review, the security engineer runs kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments. Expected evidence: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome. If the run instead shows this symptom, stop and restore the last known state: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.

Words you’ll hear

can-i
For this lesson, can-i is the controlling idea: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.
RBAC Debug
RBAC Debug is the checkpoint; run kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments and inspect the owner chain. A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.
Audit
Audit is the outcome to preserve; the cost is explicit: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.
Verification evidence
The evidence command is kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments. It connects the declaration to this behavior: Debug permission denials with kubectl auth can-i and RBAC inspection.

Visual diagram

Loading interactive diagram

Theory & deep dive

How can-i reaches the intended state

Debug permission denials with kubectl auth can-i and RBAC inspection. Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

The concrete checkpoint is kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments; compare the can-i owner, RBAC Debug state, and Audit outcome instead of treating YAML acceptance as proof.

Verify RBAC Debug, not only object creation

Run kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments after the change and correlate the result with Events and the owning object. Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

Key takeaway: can-i is implemented only when this invariant remains observable: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

RBAC Debug: failure boundary and production cost

A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access. The prerequisite contract is concrete: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation. A safe design limits blast radius, records the last good configuration, and uses kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments as a deterministic rollback checkpoint.

Recover from RBAC Debug drift

Capture the current state with kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.

Key takeaway: Accept the trade-off consciously: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.

How it works, step by step

Step 1 of 4
Identity owner

1. Model the trust boundary

Name the identity, action, resource, and trust boundary before choosing a control: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

can-i contract → owned state
Key numbers at this step
Goal
Debug permission denials with kubectl auth can-i and RBAC inspection.
Owner
can-i

When to use it & trade-offs

What it is

Debug permission denials with kubectl auth can-i and RBAC inspection. Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

Why it matters: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access. The invariant at risk is specific: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome. The quickest fact check before changing the design is kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments.

When to reach for it

  • Use can-i to enforce this invariant: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.
  • Use RBAC Debug evidence from kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments in reviews and incident timelines. Debug permission denials with kubectl auth can-i and RBAC inspection.
  • Choose the hosted security service route only when this cost is justified by governance or scale: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.

When to avoid or be careful

  • Avoid assuming can-i is complete after YAML submission; the required behavior is concrete: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.
  • Avoid treating the next symptom as random; check the owner and state with kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments first: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.
  • Avoid adopting a heavier platform wrapper before measuring its cost: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.

Native, manual, and managed paths for can-i

Admission and least privilege
Best for: Debug permission denials with kubectl auth can-i and RBAC inspection. A concrete incident check is kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments.

Strengths: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

Watch out: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation. Recovery must also recognize this signal: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.

Runtime-only detection
Best for: Quickly testing the RBAC Debug assumption with kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments; the expected invariant is: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

Strengths: kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments gives immediate feedback without first building a platform layer.

Watch out: A manual change can hide drift, and unlike can-i, it does not make this symptom self-documenting: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.

Hosted security service
Best for: Teams that need Audit integrated with guardrails; the evidence path is kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments.

Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.

Watch out: The added platform ownership buys value at this cost: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.

Interview signals & numbers to know

When this topic comes up

  • Interview anchor: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.
  • Trace can-i to Audit through RBAC Debug; the invariant is: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.
  • Recognize the symptom: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.
  • Justify the cost: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.
  • Verify with kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments instead of only inspecting YAML.

Benchmarks & rules of thumb

1 -
decision corresponds to one verb/resource/name combination
2 -
identity forms commonly used in tests: user and ServiceAccount
0 -
can-i bypasses of admission policy are part of the answer

Common mistakes & follow-ups

Common interview mistakes

  • Debugging only the child object misses the can-i owner contract: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome.
  • Ignoring this telltale condition leads to unrelated changes: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access.
  • Repeating kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments without an owner for remediation wastes retry cost. RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.

Likely interviewer follow-ups

  • How would API output and runtime evidence prove this behavior: kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome?
  • Which owner object, logs, and Events would you inspect for this symptom-A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access-?
  • At what threshold would this cost become unacceptable: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation?
Interview tip: Interview sequence: state the invariant, run kubectl auth can-i get secrets -n payments --as system:serviceaccount:payments:api; kubectl describe rolebinding -n payments, name the failure, then justify the cost. Invariant: Kubectl auth can-i performs an authorization decision for a verb, resource, namespace, and optional user or ServiceAccount, while audit logs record the API request and outcome. Failure: A group or impersonated identity can differ from the operator's current credential, and an allow on one non-resource URL or subresource does not grant unrelated API access. Cost: RBAC tests are fast and reversible, but can-i does not prove admission policy, webhook, network, or application-level authorization will permit the operation.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Auditing & Debugging RBAC Permissions (kubectl auth can-i) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Role-Based Access Control (RBAC): Role, ClusterRole, RoleBinding, ClusterRoleBinding
Next topic
Pod Security Standards (Privileged, Baseline, Restricted) & Pod Security Admission (PSA)