Auditing & Debugging RBAC Permissions (kubectl auth can-i)
Debug permission denials with kubectl auth can-i and RBAC inspection.
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 paymentsand 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
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.
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.
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.
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.
How it works, step by step
Step 1 of 41. 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.
- 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 paymentsin 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 paymentsfirst: 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
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.
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.
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 paymentswithout 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?
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
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.