Skip to main content
This lab walks through inspecting RBAC configuration on a Kubernetes cluster, examining existing Role and RoleBinding objects, and creating the RBAC resources needed to let a user manage Pods and Deployments within a namespace.

1) Inspect authorization modes configured on the cluster

Check the kube-apiserver manifest on the control plane node to confirm which authorization modes are enabled:
The flag --authorization-mode=Node,RBAC indicates the API server is configured to use Node and RBAC authorization. You can also confirm this by inspecting the running kube-apiserver process on the control plane:
Both the manifest and running process confirm that RBAC is enabled on the cluster.
RBAC must be enabled on the API server for Role, ClusterRole, RoleBinding, and ClusterRoleBinding objects to be enforced.

2) How many Roles exist cluster-wide?

List all Role objects across namespaces and count them:
Sample output (truncated):
Count the lines:
There are 12 Role objects in this cluster example.

3) What resources does the kube-proxy Role in the kube-system namespace have access to?

Describe the kube-proxy Role:
Output:
Interpretation:
  • Resources: configmaps
  • Resource name scoped to: kube-proxy
  • Allowed verbs: get
This Role permits only the get verb on the configmap named kube-proxy. It cannot update or delete that ConfigMap.

4) Which account is the kube-proxy Role bound to?

List RoleBindings in the kube-system namespace and inspect the kube-proxy binding:
The RoleBinding for kube-proxy binds the Role to the following subject:
  • Subject: system:bootstrappers:kubeadm:default-node-token (group)
That group receives the kube-proxy Role permissions.

5) Is dev-user present in kubeconfig?

Inspect the kubeconfig to see whether dev-user is configured:
Relevant excerpt:
dev-user exists as a user entry in the kubeconfig.

6) Can dev-user list pods in the default namespace?

Attempt to list pods as dev-user:
Response:
dev-user does not have permission to list pods in the default namespace.

7) Create Role and RoleBinding so dev-user can create, list, and delete pods in the default namespace

Create a Role granting list, create, and delete on pods, and bind it to dev-user with a RoleBinding. Create the Role (namespace: default):
Describe the Role:
Output:
Create the RoleBinding:
Describe the RoleBinding:
Output:
Now dev-user can list, create, and delete pods within the default namespace.
You can limit a Role to specific object names using resourceNames. If you omit resourceNames, the rule applies to all objects of that resource type in the namespace.

8) Investigate why dev-user cannot get the dark-blue-app pod in namespace blue

Attempt to get the pod as dev-user in the blue namespace:
Response:
Check Roles and RoleBindings in the blue namespace:
Output from describe:
Diagnosis:
  • The developer Role in blue scopes Pod permissions to resourceNames: [blue-app].
  • That restricts the rule to the single Pod named blue-app.
  • Access to dark-blue-app is denied because it is not listed in resourceNames.
Fix options:
  • Add dark-blue-app to resourceNames in the Role, or
  • Remove resourceNames from the Pod rule to permit the verbs on all Pods in the namespace.
Important note: If you keep create with resourceNames, the ability to create will only apply when the created object’s metadata.name matches one of the listed resourceNames. To allow creation of arbitrary names, remove resourceNames. Example: edit the Role to permit dark-blue-app specifically:
After editing, verify as dev-user:
Adjusting resourceNames or removing it resolves the permission error.
Be careful when using resourceNames. It enforces fine-grained access, but can unintentionally block operations (including create) if the object name does not match.

9) Grant dev-user permissions to create Deployments in the blue namespace

When dev-user attempts to create a Deployment in blue:
Response:
To enable Deployment management, update the developer Role in blue to include the deployments resource in the apps API group. Edit the Role and add a rule for deployments:
Note: Use the plural deployments under the apps API group. After saving the Role, verify it contains the deployments rule:
You should see:
Now try creating the Deployment again as dev-user:
dev-user can now create Deployments in the blue namespace.
Summary Links and References

Watch Video