, , , , ,

Kubernetes RBAC Explained: Users, Groups, Roles, Bindings and CSRs

Posted by

–

Kubernetes RBAC infographic explaining users, groups, roles, role bindings, and certificate signing requests, with access control workflow and practical examples.

Introduction

A Kubernetes cluster may run hundreds of applications, but not every person or application should have access to every resource.

Developers may need to view Pods. DevOps engineers may need to update Deployments. Monitoring tools may need to read selected metrics-related resources. Cluster administrators need broader permissions to manage infrastructure.

Giving everyone administrator access creates unnecessary security risks.

Kubernetes solves this problem through Role-Based Access Control (RBAC). RBAC decides who can perform which actions on which Kubernetes resources.

To understand Kubernetes RBAC, you need to understand five important concepts:

  1. Users represent authenticated human or external identities.
  2. Groups collect identities with similar access requirements.
  3. Roles and ClusterRoles define permissions.
  4. RoleBindings and ClusterRoleBindings assign those permissions.
  5. CertificateSigningRequests (CSRs) can help provision client certificates for authentication.

This guide explains how these parts work together. It includes YAML examples, practical commands, a ServiceAccount example, and a certificate-based user access workflow.

The examples use the stable. rbac.authorization.k8s.io/v1 API and follow the current Kubernetes v1.37 documentation. Always check your own cluster version and authentication configuration.

1. What Is Kubernetes RBAC?

RBAC stands for Role-Based Access Control.

It is a Kubernetes authorization mechanism. It determines whether an authenticated identity can perform a requested operation on a resource.

Think of RBAC through three questions:

QuestionMeaningExample
WHO?Which identity needs access?alice, team-dev, app-reader
WHAT?Which action is allowed?get, list, watch, create
WHERE?Which resource and scope?Pods in development, Deployments, ConfigMaps

For example, a developer may need permission to list Pods in the development namespace but should not read Secrets or modify cluster-wide resources.

RBAC lets an administrator define this permission without giving the developer full cluster access.

How RBAC authorization works

A typical Kubernetes API request follows this process:

  1. A person or application sends a request to the Kubernetes API server.
  2. Kubernetes authenticates the request and identifies its username and groups.
  3. The API server determines which resource and operation the request involves.
  4. The configured authorization mechanisms evaluate the request.
  5. RBAC checks whether applicable permissions have been granted through Roles and bindings.
  6. The request is allowed or denied according to the authorization decision.

A successful authentication does not automatically grant permission to operate.

A user may authenticate successfully and still receive a 403 Forbidden response because the required permission is missing.

Kubernetes also supports authentication and authorization mechanisms beyond client certificates and RBAC. The actual identity may come from an OIDC provider, an authentication webhook, a client certificate, or another configured authenticator.

Official documentation: Kubernetes Authentication and Using RBAC Authorization.

2. Understand Users in Kubernetes

A Kubernetes human user is an authenticated identity, not a normal Kubernetes API object.

This distinction is important.

Kubernetes does not provide a regular API resource called User for creating human accounts. Normal user identities are managed outside Kubernetes.

An organisation may use:

  • Client certificates.
  • OpenID Connect (OIDC).
  • An authentication proxy.
  • An authentication webhook.
  • Another supported identity integration.

The authenticator supplies an identity to the API server.

That identity can contain a username, UID, groups, and additional attributes.

Example user identities

User identityPossible purpose
aliceDeveloper
bobCluster operator
jane@example.comEnterprise identity
ci-deployerExternal automation identity

These are example identity strings. They are not automatically created Kubernetes users.

For example, an external OIDC provider may authenticate alice@example.com. Kubernetes can then use that username in RBAC bindings.

Can you create a Kubernetes user with kubectl?

No standard command such as this exists:

kubectl create user alice

Instead, you configure authentication using an appropriate identity provider or client certificate.

Then RBAC permissions can be assigned to the identity that the authenticator supplies.

3. Understand Groups in Kubernetes

Groups allow administrators to assign permissions to several identities together.

For example, an organisation may have:

  • team-dev
  • team-qa
  • team-ops
  • platform-admins

Rather than creating separate RoleBindings for every developer, an administrator can grant a permission to the team-dev group.

When a developer authenticates, the authentication system supplies their group membership.

Kubernetes then evaluates the group against the subjects in RBAC bindings.

Example group-based access

Suppose Alice and Bob belong to team-dev.

The administrator creates a Role that allows reading Pods. A RoleBinding grants this permission to the group.

Both users receive the permission when their authenticated identities include team-dev.

If another developer joins that group through the organisation’s identity system, they can receive the same access without a separate individual RoleBinding.

The group’s membership must come from the configured authentication system. Creating a Group subject in a RoleBinding does not create an identity group or add users to it.

Built-in Kubernetes groups

Kubernetes also uses special groups.

GroupMeaning
system:authenticatedAuthenticated request identities
system:unauthenticatedAnonymous request identities, when enabled
system:serviceaccountsServiceAccounts across the cluster
system:serviceaccounts:developmentServiceAccounts in the development namespace
system:mastersHighly privileged group with unrestricted superuser access

Avoid assigning normal users to system:masters. Kubernetes documentation warns that members of this group bypass RBAC checks.

4. Understand ServiceAccounts

ServiceAccounts are different from ordinary human users.

A ServiceAccount is a Kubernetes API object. It represents an identity that an application or workload can use when communicating with the Kubernetes API.

For example, a monitoring application may need to read selected resources. Instead of using an administrator’s credentials, you create a dedicated ServiceAccount and assign the required permissions.

The username format for a ServiceAccount is:

system:serviceaccount:<namespace>:<serviceaccount-name>Code language: HTML, XML (xml)

For example:

system:serviceaccount:development:app-readerCode language: CSS (css)

ServiceAccounts also belong to these groups:

system:serviceaccounts
system:serviceaccounts:developmentCode language: CSS (css)

Create a ServiceAccount

kubectl create namespace development

kubectl create serviceaccount app-reader \
  -n developmentCode language: PHP (php)

Verify it:

kubectl get serviceaccounts -n developmentCode language: JavaScript (javascript)

Creating a ServiceAccount does not automatically give it broad permissions. Grant only the access required by the application.

5. Understand Kubernetes RBAC Objects

Kubernetes RBAC uses four main API objects:

  • Role
  • ClusterRole
  • RoleBinding
  • ClusterRoleBinding

The first two define permissions. The other two assign permissions to users, groups, or ServiceAccounts.

Role

A Role defines permissions within one namespace.

For example, you can create a Role that allows developers to list and read Pods in development.

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: development
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]Code language: JavaScript (javascript)

Apply it:

kubectl apply -f pod-reader-role.yamlCode language: CSS (css)

Verify it:

kubectl describe role pod-reader \
  -n development

The Role does not grant access to anyone by itself. You need a RoleBinding.

ClusterRole

A ClusterRole defines permissions at cluster scope.

It can be used for several purposes:

  1. Access to cluster-scoped resources.
  2. Reusable permissions for namespaced resources.
  3. Access to namespaced resources across all namespaces when bound cluster-wide.

For example, Nodes are cluster-scoped resources. A Role cannot grant cluster-wide access to them.

Create a ClusterRole for reading Nodes:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: node-reader
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]Code language: JavaScript (javascript)

Apply it:

kubectl apply -f node-reader.yamlCode language: CSS (css)

Verify it:

kubectl describe clusterrole node-reader

A ClusterRole is reusable. It can also be referenced by a RoleBinding when you want its permissions to apply only within one namespace.

RoleBinding

A RoleBinding assigns a Role or ClusterRole to one or more subjects within a namespace.

For example, bind the pod-reader Role to Alice.

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: alice-pod-reader
  namespace: development
subjects:
  - kind: User
    name: alice
    apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Apply it:

kubectl apply -f alice-rolebinding.yamlCode language: CSS (css)

Now the authenticated user alice can read Pods within development, assuming no other policies or authorization conditions are changing the result.

A RoleBinding can also reference a ClusterRole. The permissions are then limited to the namespace containing that RoleBinding.

This is useful when you want to reuse one permission definition in several namespaces.

ClusterRoleBinding

A ClusterRoleBinding assigns a ClusterRole to subjects across the cluster.

For example, bind the node-reader ClusterRole to a group:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: team-ops-node-reader
subjects:
  - kind: Group
    name: team-ops
    apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: node-reader
  apiGroup: rbac.authorization.k8s.io

Apply it:

kubectl apply -f team-ops-node-reader.yamlCode language: CSS (css)

Members of team-ops can now read Nodes across the cluster, subject to the configured authorization policy.

The difference between the four objects

ObjectScopePurpose
RoleOne namespaceDefines namespace permissions
ClusterRoleCluster-level objectDefines reusable or cluster-level permissions
RoleBindingOne namespaceAssigns a Role or ClusterRole within that namespace
ClusterRoleBindingCluster-wideAssigns a ClusterRole across the cluster

Remember this rule:

A RoleBinding controls the namespace in which permissions apply. A ClusterRoleBinding grants the referenced ClusterRole’s permissions cluster-wide.

Official reference: Kubernetes RBAC API objects.

6. Understand RBAC Verbs, API Groups, and Resources

A Role rule uses three important fields:

  • apiGroups
  • resources
  • verbs

These fields determine which API operations are permitted.

Common Kubernetes verbs

VerbMeaning
getRead an individual object
listRead a collection of objects
watchReceive updates as objects change
createCreate an object
updateReplace an existing object
patchPartially modify an object
deleteDelete an object
deletecollectionDelete a collection of objects

Avoid granting * as a verb or resource wildcard unless there is a clearly justified need. Wildcards can include resources and actions introduced in the future.

Common Kubernetes API groups

ResourceAPI group
Pods""
Services""
ConfigMaps""
Secrets""
Deploymentsapps
ReplicaSetsapps
Jobsbatch
CronJobsbatch
Ingressesnetworking.k8s.io

The empty string represents the core Kubernetes API group.

To inspect resources on your own cluster, run:

kubectl api-resources -o wide

To inspect RBAC API resources:

kubectl api-resources \
  --api-group=rbac.authorization.k8s.io

Example: Read Deployments

rules:
  - apiGroups: ["apps"]
    resources: ["deployments"]
    verbs: ["get", "list", "watch"]Code language: CSS (css)

Example: Read Pod logs

Pod logs are a subresource. Permission to read Pods does not automatically mean permission to read their logs.

rules:
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get"]Code language: CSS (css)

This distinction is important when designing access for developers and support teams.

Example: Restrict access to one ConfigMap

The resourceNames field can restrict certain requests to a named object.

rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["app-config"]
    verbs: ["get"]Code language: CSS (css)

There are limitations. For example, resourceNames cannot restrict top-level create or deletecollection requests by object name.

7. Understand the Built-In Kubernetes Roles

Kubernetes includes predefined ClusterRoles for common access requirements.

Built-in roleGeneral purposeImportant consideration
cluster-adminFull administrative accessExtremely powerful
adminNamespace administrationCan manage most namespace resources and RBAC within its scope
editRead/write access to most namespace resourcesCan access Secrets and run Pods as ServiceAccounts in that namespace
viewRead-only access to most namespace resourcesDoes not allow reading Secrets

These built-in roles can be useful for basic access arrangements, but they are not always precise enough for production requirements.

For example, edit may sound like a reasonable developer role. However, its ability to access Secrets and run Pods as namespace ServiceAccounts can expose additional API privileges.

Use a custom Role when the built-in permissions are broader than necessary.

8. How CertificateSigningRequests (CSRs) Work

A CertificateSigningRequest is a Kubernetes API resource used to request an X.509 certificate from a configured signer.

It is useful when an organisation wants to issue client certificates for Kubernetes API access.

The CSR process is important because a client certificate can establish an authenticated user identity. RBAC can then assign permissions to that identity.

However, a CSR does not directly create a Kubernetes user or grant RBAC permissions.

These are separate operations:

  • Authentication establishes the identity.
  • RBAC determines the permissions.
  • Certificate issuance provides a credential that an authenticator may trust.

CSR request lifecycle

A typical client certificate workflow looks like this:

  1. Generate a private key.
  2. Create a certificate signing request.
  3. Submit a Kubernetes CertificateSigningRequest object.
  4. Inspect the requested identity and signer.
  5. Approve or reject the request.
  6. The configured signer issues the certificate if its requirements are satisfied.
  7. Configure the client certificate in kubeconfig.
  8. Create the required RBAC bindings.
  9. Test the authenticated identity and permissions.

The CSR API has been stable since Kubernetes v1.19. The certificates.k8s.io/v1 API requires spec.signerName.

Official reference: Kubernetes Certificates and Certificate Signing Requests.

9. Practical Lab: Give a Group Permission to Read Pods

This lab shows how a Role and RoleBinding work together.

Use a disposable cluster and an administrator identity that is permitted to create namespaces and RBAC objects.

Step 1: Create a namespace

kubectl create namespace rbac-labCode language: PHP (php)

Verify it:

kubectl get namespacesCode language: JavaScript (javascript)

Step 2: Create a Role

Create a file named pod-reader.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: rbac-lab
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]Code language: JavaScript (javascript)

Apply it:

kubectl apply -f pod-reader.yamlCode language: CSS (css)

Step 3: Bind the Role to a group

Create team-dev-binding.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: team-dev-pod-reader
  namespace: rbac-lab
subjects:
  - kind: Group
    name: team-dev
    apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Apply it:

kubectl apply -f team-dev-binding.yamlCode language: CSS (css)

The group receives permission to read Pods in rbac-lab.

This does not create the group. Your authentication system must supply team-dev as part of the authenticated identity.

Step 4: Test the permissions

Use impersonation to simulate an identity in the group:

kubectl auth can-i list pods \
  -n rbac-lab \
  --as=alice \
  --as-group=team-devCode language: PHP (php)

Expected result in a clean lab: yes.

Test access to Secrets:

kubectl auth can-i get secrets \
  -n rbac-lab \
  --as=alice \
  --as-group=team-devCode language: PHP (php)

Expected result in a clean lab: no.

Test access to Pods in another namespace:

kubectl auth can-i list pods \
  -n default \
  --as=alice \
  --as-group=team-devCode language: PHP (php)

Expected result in a clean lab: no.

These results assume no additional permissions have been granted to the test identity.

Important: --as and --as-group use Kubernetes impersonation. The administrator running these commands must have the relevant impersonation permissions. These commands test authorization; they do not authenticate as a real user.

10. Practical Lab: Give a ServiceAccount Limited Access

Now create a ServiceAccount that can read ConfigMaps in rbac-lab.

Create the ServiceAccount:

kubectl create serviceaccount app-reader \
  -n rbac-lab

Create a ConfigMap:

kubectl create configmap app-config \
  --from-literal=mode=training \
  -n rbac-labCode language: JavaScript (javascript)

Create the Role:

kubectl create role configmap-reader \
  --verb=get,list \
  --resource=configmaps \
  -n rbac-labCode language: JavaScript (javascript)

Bind the Role to the ServiceAccount:

kubectl create rolebinding app-config-reader \
  --role=configmap-reader \
  --serviceaccount=rbac-lab:app-reader \
  -n rbac-lab

Test access:

kubectl auth can-i get configmaps \
  -n rbac-lab \
  --as=system:serviceaccount:rbac-lab:app-readerCode language: JavaScript (javascript)

Expected result in a clean lab: yes.

Test access to Secrets:

kubectl auth can-i get secrets \
  -n rbac-lab \
  --as=system:serviceaccount:rbac-lab:app-readerCode language: JavaScript (javascript)

Expected result: no.

Again, impersonation permissions are required for these tests.

The ServiceAccount does not need access to Pods, Secrets, Deployments, or other resources unless the application actually requires them.

11. Practical Lab: Create a Human User Certificate

This lab shows how a client certificate can provide a username and group for Kubernetes authentication.

It requires:

  • openssl
  • kubectl
  • A Kubernetes cluster with an appropriate client certificate signer.
  • An API server configured to trust the issuing CA for client authentication.
  • Administrator permissions to create and approve the required CSR.

Some managed clusters do not expose or configure the built-in client certificate signing workflow for customer use. Check your cluster provider’s documentation before starting.

Step 1: Generate a private key

Run these commands on a trusted workstation in a private directory.

umask 077

openssl genrsa \
  -out alice.key \
  3072Code language: CSS (css)

The private key must remain private. Do not upload it to GitHub, email it, or place it in a shared folder.

Step 2: Generate a certificate request

openssl req -new \
  -key alice.key \
  -out alice.csr \
  -subj "/CN=alice/O=team-dev"Code language: JavaScript (javascript)

Inspect the request:

openssl req \
  -in alice.csr \
  -noout \
  -subjectCode language: CSS (css)

For Kubernetes X.509 client certificate authentication:

  • CN=alice provides the username alice.
  • O=team-dev provides the group team-dev.

This mapping applies to the X.509 authentication mechanism. Other authentication systems may provide usernames and groups differently.

Step 3: Create the Kubernetes CSR object

Encode the request:

CSR_B64="$(base64 < alice.csr | tr -d '\n')"Code language: JavaScript (javascript)

Create the Kubernetes CSR manifest:

cat > alice-csr.yaml <<EOF
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: alice-team-dev
spec:
  request: ${CSR_B64}
  signerName: kubernetes.io/kube-apiserver-client
  expirationSeconds: 86400
  usages:
    - digital signature
    - key encipherment
    - client auth
EOF

Apply it:

kubectl apply -f alice-csr.yamlCode language: CSS (css)

Inspect it:

kubectl get csrCode language: JavaScript (javascript)
kubectl describe csr alice-team-dev

The CSR is cluster-scoped. Do not add a namespace to its manifest.

Step 4: Review and approve the CSR

Before approval, inspect the requested subject, signer, usages, and requested lifetime.

kubectl get csr alice-team-dev -o yamlCode language: JavaScript (javascript)

Do not automatically approve every CSR.

An approved client certificate may allow its holder to authenticate as the requested identity. This can become a serious security issue if the requested username or group is privileged.

After an authorised administrator has reviewed the request:

kubectl certificate approve alice-team-dev

Approval does not guarantee a certificate will be issued. The configured signer must also be available and able to complete the signing process.

Watch the CSR:

kubectl get csr alice-team-dev -wCode language: JavaScript (javascript)

Step 5: Retrieve the issued certificate

When the signer issues the certificate, it appears in .status.certificate.

On Linux:

kubectl get csr alice-team-dev \
  -o jsonpath='{.status.certificate}' \
  | base64 -d > alice.crtCode language: JavaScript (javascript)

Inspect the certificate:

openssl x509 -in alice.crt \
  -noout \
  -subject \
  -issuer \
  -datesCode language: CSS (css)

Confirm the username, group, issuer, and validity period.

If the CSR is approved but .status.certificate remains empty, check the configured signer and controller-manager logs. Approval and signing are separate steps.

Step 6: Configure kubeconfig

Get the current cluster entry:

CLUSTER="$(kubectl config view --minify \
  -o jsonpath='{.contexts[0].context.cluster}')"Code language: JavaScript (javascript)

Add Alice’s credentials:

kubectl config set-credentials alice \
  --client-certificate=alice.crt \
  --client-key=alice.key \
  --embed-certs=trueCode language: JavaScript (javascript)

Create a separate context:

kubectl config set-context alice-rbac-lab \
  --cluster="$CLUSTER" \
  --user=alice \
  --namespace=rbac-labCode language: PHP (php)

This adds the new context without switching the active context.

Check the identity:

kubectl --context=alice-rbac-lab auth whoami

The expected identity should include:

  • Username: alice
  • Group: team-dev
  • Group: system:authenticated

Step 7: Bind the group and test access

Create a RoleBinding for team-dev:

kubectl create rolebinding team-dev-read \
  --role=pod-reader \
  --group=team-dev \
  -n rbac-lab

Test access using Alice’s actual certificate context:

kubectl --context=alice-rbac-lab \
  get podsCode language: JavaScript (javascript)

The request should be authorised within rbac-lab.

Now test access to Secrets:

kubectl --context=alice-rbac-lab \
  get secretsCode language: JavaScript (javascript)

In the clean lab, this should return Forbidden.

This is the important relationship:

The certificate authenticates Alice and provides the group. The RoleBinding grants the group its Pod permissions.

A client certificate does not automatically grant those permissions.

12. Understand CSR Permissions

CertificateSigningRequests have their own permission requirements.

Creating or retrieving a CSR is different from approving it or signing it.

The Kubernetes documentation describes separate permissions for these operations.

OperationResourceRequired verb
Create CSRcertificatesigningrequestscreate
Inspect CSRcertificatesigningrequestsget, list, watch
Approve CSRcertificatesigningrequests/approvalupdate
Authorise approval for a signersignersapprove
Update signing resultcertificatesigningrequests/statusupdate
Authorise signing for a signersignerssign

The signer permissions should be restricted by resourceNames where possible.

For example, an approval role can be scoped to one signer:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: client-csr-approver
rules:
  - apiGroups: ["certificates.k8s.io"]
    resources: ["certificatesigningrequests"]
    verbs: ["get", "list", "watch"]

  - apiGroups: ["certificates.k8s.io"]
    resources: ["certificatesigningrequests/approval"]
    verbs: ["update"]

  - apiGroups: ["certificates.k8s.io"]
    resources: ["signers"]
    resourceNames:
      - kubernetes.io/kube-apiserver-client
    verbs: ["approve"]Code language: JavaScript (javascript)

This is an example permission definition. You must still decide which trusted administrators or controllers should receive it.

Do not grant CSR approval or signer permissions broadly.

Kubernetes explicitly warns that approving CSRs is a trust decision. The requested subject and signer must be checked before approval.

References:

13. Important RBAC Security Risks

RBAC is a security control, but incorrect permissions can create privilege escalation paths.

Risk 1: Granting wildcard permissions

For example:

verbs: ["*"]
resources: ["*"]Code language: CSS (css)

This can grant access to current and future API resources.

Better approach: Define only the verbs and resources needed.

Risk 2: Giving developers broad Secret access

Secrets can contain credentials, tokens, certificates, and application configuration.

Reading a Secret may expose credentials that provide access to other Kubernetes resources.

Better approach: Avoid granting Secret access unless the role genuinely requires it. Restrict access by namespace and, where practical, by resource name.

Risk 3: Giving edit to every developer

The built-in edit role can access Secrets and run Pods as ServiceAccounts in its namespace. This can expose permissions beyond the apparent scope of ordinary application editing.

Better approach: Use a custom Role when developers need narrower access.

Risk 4: Granting cluster-admin unnecessarily

cluster-admin allows superuser operations across the cluster.

Better approach: Use scoped roles for everyday operations and reserve cluster-admin for trusted administrative tasks.

Risk 5: Granting bind, escalate, or impersonate

These verbs are especially sensitive:

  • bind can allow users to attach roles with permissions they do not already possess.
  • escalate can bypass built-in protections when creating or changing roles.
  • impersonate allows a user to act as another identity.

Grant these only to trusted operators with a defined need.

Risk 6: Forgetting namespace boundaries

A ClusterRoleBinding gives the referenced ClusterRole access across the cluster.

A RoleBinding using a ClusterRole applies that permission only in the RoleBinding’s namespace.

Better approach: Prefer RoleBindings when permissions only need to apply within one namespace.

Risk 7: Treating a missing permission as a deny rule

Kubernetes RBAC rules are additive. They do not contain explicit deny rules.

A RoleBinding can add permissions. Removing a binding removes that grant, but another binding may still grant the same permission.

Better approach: Review all applicable bindings and any other configured authorizers when investigating unexpected access.

14. Useful Kubernetes RBAC Commands

PurposeCommand
Show current contextkubectl config current-context
Show authenticated identitykubectl auth whoami
List namespaceskubectl get namespaces
List Roleskubectl get roles -A
List RoleBindingskubectl get rolebindings -A
List ClusterRoleskubectl get clusterroles
List ClusterRoleBindingskubectl get clusterrolebindings
Describe a Rolekubectl describe role pod-reader -n rbac-lab
Test permissionkubectl auth can-i list pods -n rbac-lab
Test as another userkubectl auth can-i list pods -n rbac-lab --as=alice
List CSRskubectl get csr
Inspect a CSRkubectl describe csr alice-team-dev

The impersonation examples require the appropriate administrative permissions.

15. RBAC Troubleshooting Checklist

When a user receives an access error, investigate the identity and authorization separately.

Step 1: Check authentication

kubectl auth whoami

Confirm that the username and groups are correct.

If authentication fails, review the certificate, token, identity provider, kubeconfig, or authentication integration.

Step 2: Check the requested permission

kubectl auth can-i list pods -n rbac-labCode language: PHP (php)

Test the exact verb, resource, and namespace involved.

Step 3: Inspect the Role

kubectl get roles -n rbac-lab
kubectl describe role pod-reader -n rbac-labCode language: JavaScript (javascript)

Confirm the API group, resource, and verbs.

Step 4: Inspect the binding

kubectl get rolebindings -n rbac-lab
kubectl describe rolebinding team-dev-pod-reader -n rbac-labCode language: JavaScript (javascript)

Check the subject name and subject type.

A group name must match the authenticated group exactly. Names are case-sensitive.

Step 5: Check the namespace

A RoleBinding grants access only within its own namespace.

Check whether the request uses the expected namespace.

Step 6: Check for other permissions

An unexpected yes result may come from another RoleBinding, ClusterRoleBinding, or configured authorization mechanism.

Do not assume that a single Role explains every permission.

16. Clean Up the RBAC Lab

After completing the exercises, remove the test namespace:

kubectl delete namespace rbac-labCode language: JavaScript (javascript)

Remove the local training credentials and certificate files when they are no longer needed:

rm -f alice.key alice.csr alice.crt
rm -f alice-csr.yamlCode language: CSS (css)

Do not delete credentials that are used for another purpose. Confirm the files belong to the lab before removing them.

Frequently Asked Questions

Can I create a Kubernetes user using kubectl?

No. Kubernetes does not provide a normal User API resource. Human identities are supplied through authentication systems such as client certificates, OIDC, or authentication webhooks.

What is the difference between a User and a ServiceAccount?

A normal User identity is managed outside Kubernetes. A ServiceAccount is a Kubernetes API object designed for workloads and applications.

What is the difference between a Role and a ClusterRole?

A Role defines permissions within one namespace. A ClusterRole is not namespaced and can define permissions for cluster-scoped resources or reusable permissions for namespaced resources.

What is the difference between a RoleBinding and a ClusterRoleBinding?

A RoleBinding grants permissions within one namespace. A ClusterRoleBinding grants the referenced ClusterRole permissions across the cluster.

Does a Role automatically give users access?

No. A Role defines permissions. A RoleBinding or ClusterRoleBinding must assign those permissions to a subject.

Can a RoleBinding reference a ClusterRole?

Yes. The ClusterRole’s permissions then apply only within the RoleBinding’s namespace.

What is a Kubernetes CSR?

A CertificateSigningRequest is a cluster-scoped API object used to request an X.509 certificate from a configured signer. It may require review and approval before signing.

Does approving a CSR automatically issue a certificate?

No. Approval and signing are separate stages. A configured signer must issue the certificate.

Does a CSR automatically create a Kubernetes user?

No. A signed client certificate can authenticate an identity. RBAC bindings then determine what that identity can do.

Why is kubectl auth can-i useful?

It checks whether the current identity, or an impersonated identity when permitted, can perform a specified Kubernetes API operation.

Final Thoughts

Kubernetes RBAC helps organisations control access without giving every person or application administrator permissions.

Users and groups identify who needs access. ServiceAccounts identify workloads. Roles and ClusterRoles define allowed actions. Bindings assign those permissions.

CertificateSigningRequests provide a separate mechanism for requesting client certificates that can authenticate users.

The most important design principle is least privilege.

Start with the minimum permissions required. Prefer namespace-scoped bindings when possible. Review Secret access carefully. Test permissions with kubectl auth can-i. Review certificate requests before approval.

When authentication and authorization are understood separately, Kubernetes access becomes easier to design, troubleshoot, and secure.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x