Skip to main content
In this lab, we explore role-based access controls (RBAC) within a Kubernetes cluster. You will inspect the environment, review the API server authorization modes, and work through practical scenarios with roles, role bindings, and user permissions.

Inspecting the API Server Authorization Modes

The first step is to examine the cluster configuration to determine which authorization modes are active. One approach is to review the Kubernetes API server manifest. The diagram below illustrates a terminal interface where the task is focused on inspecting Kubernetes authorization modes—specifically, Node, RBAC, and ABAC—by checking the kube-apiserver settings.
The image shows a terminal interface with a task to inspect Kubernetes authorization modes, focusing on kube-apiserver settings, with options like Node, RBAC, and ABAC.
Examine the kube-apiserver manifest file. In the YAML excerpt below, note that the parameter --authorization-mode is configured with the value Node,RBAC:
Alternatively, you can verify the authorization mode by inspecting the running control plane processes. Look for the authorization-related parameters using this command:
This confirms that the kube-apiserver is running with the “Node” and “RBAC” authorization modes.

Checking Roles and Their Permissions

Inspect the roles available in the cluster by counting the total number of roles across all namespaces:
Next, review the kube-proxy role within the kube-system namespace to see what resources it manages:
Describe the kube-proxy role:
The kube-proxy role is explicitly permitted to retrieve (get) the ConfigMap named “kube-proxy” but not to modify or delete it.

Role Bindings and User Permissions

To determine which accounts are associated with the kube-proxy role, review the role bindings in the kube-system namespace:
The kube-proxy role is assigned via its respective role binding, which generally targets a specific group (for example, system bootstrappers). Additionally, a user account named “dev-user” is created with corresponding credentials in the kubeconfig file. To inspect this file, execute:
Below is an excerpt from the kubeconfig showing the “dev-user” credentials:
Test the “dev-user” permissions by attempting to list pods in the default namespace:
Since listing pods is forbidden for “dev-user,” you will need to create an appropriate role and role binding that grants permissions to create, list, and delete pods.

Creating a Role and Role Binding for a Developer

Step 1: Create the Role

Create a Role named developer in the default namespace that permits listing, creating, and deleting pods. Ensure that you use the singular form for resource flag:
Verify the newly created role:

Step 2: Bind the Role to dev-user

Create a RoleBinding called dev-user-binding that assigns the developer role to the “dev-user”:
Inspect the binding details to confirm the assignment:

Adjusting Permissions in the Blue Namespace

When “dev-user” attempts to access the pod (named dark-blue-app) in the blue namespace, a forbidden error occurs. Begin by checking the roles and role bindings in the blue namespace:
View the details of the developer role in the blue namespace:
The current configuration permits access only to a pod named “blue-app”. To allow “dev-user” to access the dark-blue-app pod, edit the role accordingly:
After updating the resource names, verify access using the following command:
Always double-check that the resource names in your Role match the actual names in the namespace. This ensures that the correct permissions are applied.

Granting Permissions to Manage Deployments

The next requirement is to allow “dev-user” to create Deployments in the blue namespace. Initially, an attempt to create a deployment as “dev-user” might fail due to insufficient permissions:
To fix this, update the developer role in the blue namespace to include a new rule for deployments in the “apps” API group. The updated role should maintain the existing permissions for pods while adding the required permissions for deployments. An example of the modified role manifest is shown below:
After saving the updated configuration, verify the role:
Test the new permissions by creating a deployment as “dev-user”:
With these changes, “dev-user” now has the necessary permissions to manage Deployments in the blue namespace.

Conclusion

This lab provided a comprehensive walkthrough on inspecting Kubernetes authorization modes, reviewing role assignments, and adjusting Role-Based Access Control (RBAC) configurations. By carefully modifying roles and role bindings, you ensure that users like “dev-user” receive only the permissions required to perform their tasks, enhancing both security and operational efficiency. Happy clustering!

References

Explore creating ClusterRoles and ClusterRoleBindings to manage permissions across the entire cluster in future labs.

Watch Video