Skip to main content
In this lab, we explore role-based access controls (RBAC) in Kubernetes. The tutorial covers inspecting the API server configuration, reviewing roles and permissions, and creating the necessary roles and bindings for a development user. Follow along to gain hands-on experience with securing your Kubernetes cluster. ──────────────────────────────

Inspecting the API Server Configuration

Start by inspecting the kube-apiserver manifest to identify the configured authorization modes. In the manifest snippet below, note the use of “Node,RBAC” for the authorization mode:
An alternative verification method is to inspect the running processes on the control plane. For instance, execute the following command:
The output confirms that the kube-apiserver is running with the “Node,RBAC” authorization mode. ──────────────────────────────

Reviewing Roles in the Cluster

Begin by identifying the existing roles within the default namespace. The output below shows that no roles exist in that namespace:
To count the roles across all namespaces, use this command:
There are 12 roles configured cluster-wide. ──────────────────────────────

Examining the kube-proxy Role

Next, examine the permissions assigned to the kube-proxy role in the kube-system namespace. Run the following command to display its details:
From the output, the kube-proxy role is limited to performing the “get” action on ConfigMap resources only. It cannot delete or update ConfigMaps. ──────────────────────────────

Checking Role Bindings for kube-proxy

Identify which service account is bound to the kube-proxy role by examining the role bindings in the kube-system namespace:
List the role bindings in the kube-system namespace:
Then, inspect the kube-proxy role binding:
This confirms that the kube-proxy role is associated with the group “system:bootstrappers:kubeadm:default-node-token”. ──────────────────────────────

Inspecting the kubeconfig and User Permissions

Review the kubeconfig file to verify the configured users on the cluster:
Test the permissions for the “dev-user” by listing pods in the default namespace:
This error confirms that the “dev-user” currently lacks permission to list pods in the default namespace. ──────────────────────────────

Creating Roles and Role Bindings for the dev-user

Before proceeding, review how to create a role in Kubernetes. The following command creates a role named “developer” granting list, create, and delete permissions on pods. Notice that the correct flag is —resource (singular):
You can verify the created role by describing it:
Next, assign the “developer” role to “dev-user” by creating a role binding:
Verify the role binding:
──────────────────────────────

Troubleshooting Access in the Blue Namespace

Suppose the dev-user tries to retrieve details of a pod named “dark-blue-app” in the blue namespace:
The error received is:
Upon inspection, the blue namespace has an existing “developer” role and the “dev-user-binding” role binding:
Currently, the “developer” role in the blue namespace grants permission only for the pod “dark-blue-app.” To provide the dev-user with the ability to manage that pod and to create new deployments, update the role to include rules for handling deployments in the “apps” API group. Below is an example of the updated role:
Save the changes, then test the configuration by creating a deployment as the dev-user:
The successful creation of the deployment confirms that the necessary permissions have been granted.
Always verify RBAC changes by testing user permissions in the designated namespace to ensure that the intended access is provided while maintaining security.
──────────────────────────────

Conclusion

In this lab, you have:
  • Inspected the kube-apiserver configuration to confirm the use of Node,RBAC authorization mode.
  • Reviewed the roles across namespaces and counted the total number of roles.
  • Examined the kube-proxy role’s permissions and its corresponding role binding.
  • Inspected the kubeconfig to determine that the dev-user initially lacked permission to list pods.
  • Created a role and role binding for the dev-user to grant appropriate pod access in the default namespace.
  • Troubleshooted a permission issue in the blue namespace by updating the “developer” role to allow managing deployments.
This concludes the Kubernetes RBAC lab. For more details on Kubernetes security and RBAC best practices, refer to the Kubernetes Documentation.

Watch Video