Skip to main content
In this guide, we simulate a scenario where summer interns have been granted limited access to a staging cluster but can unexpectedly view sensitive information in other namespaces. We will review the Role-Based Access Control (RBAC) configuration, identify the misconfiguration leak, and demonstrate how to remediate it.

Step 1. Reviewing the Staging Namespace Role

The staging cluster employs a role named intern-role that allows interns to get, watch, and list pods exclusively within the staging namespace. You can list the defined roles by running:
Below is the definition of intern-role:
The intern-role is strictly limited to pod operations within the staging namespace.

Step 2. Reviewing the Role Binding for Interns

The intern-role is assigned to the interns group using a role binding in the staging namespace. List the role bindings with the command:
Here is the interns-rolebinding configuration:
This binding restricts the actions of any user in the interns group to listing, watching, and getting pods in the staging namespace.

Step 3. Validating Intern Permissions

To validate the configuration, we can impersonate an intern user (e.g., Bob) and verify his permissions.

Verifying Pod Access in Staging

Confirm that Bob can list pods in the staging namespace:
Expected output:

Testing Access to Secrets in a Sensitive Namespace

Intern Bob should not have access to secrets in the top-secret namespace. First, note that running an incomplete command (without specifying a verb) returns an error:
Output:
Now, check the correct command:
Output:
The result is concerning because an intern (Bob) should not be allowed to retrieve secrets in the top-secret namespace.

Step 4. Identifying the RBAC Leak

The misconfiguration stems from an unintended higher-privileged ClusterRoleBinding. The developers-binding binds a powerful ClusterRole named developer-role (which grants full cluster-wide permissions) to both the developers and interns groups. To inspect the developers-binding, run:
The output is similar to:
For further verification, you can examine the effective permissions by impersonating Bob using a self-subject access review:
Review the developer-role configuration:
Expected definition:
Because the interns group is included in the developers-binding, interns unintentionally receive cluster-wide privileges.

Step 5. Remediating the RBAC Misconfiguration

To remediate the issue, remove the interns group from the developers-binding:
  1. Edit the ClusterRoleBinding:
  2. Remove the interns entry from the subjects list.
After saving the changes, validate that Bob no longer has access to secrets in sensitive namespaces.

Verification Steps

  • Check access to secrets in top-secret:
    Expected output:
  • Confirm that Bob cannot access secrets in the staging namespace:
    Expected output:
  • Ensure that Bob still can get pods in the staging namespace:
    Expected output:

Step 6. Diagnosing with Verbose Output

If further RBAC issues arise or you suspect additional permission leaks, increase the verbosity of the command to glean more details about the source of the permissions:
The verbose output can assist in pinpointing which role or binding is granting the unexpected access.
By following these steps, you can effectively diagnose and remediate RBAC misconfigurations within your Kubernetes clusters, ensuring that each user group has only the permissions intended for their roles. This not only bolsters security but also adheres to the principle of least privilege.

Watch Video

Practice Lab