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:--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:
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 allRole objects across namespaces and count them:
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:
- Resources:
configmaps - Resource name scoped to:
kube-proxy - Allowed verbs:
get
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:
RoleBinding for kube-proxy binds the Role to the following subject:
- Subject:
system:bootstrappers:kubeadm:default-node-token(group)
kube-proxy Role permissions.
5) Is dev-user present in kubeconfig?
Inspect the kubeconfig to see whether dev-user is configured:
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:
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):
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:
blue namespace:
describe:
- The
developerRole inbluescopes Pod permissions toresourceNames: [blue-app]. - That restricts the rule to the single Pod named
blue-app. - Access to
dark-blue-appis denied because it is not listed inresourceNames.
- Add
dark-blue-apptoresourceNamesin the Role, or - Remove
resourceNamesfrom the Pod rule to permit the verbs on all Pods in the namespace.
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:
dev-user:
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:
developer Role in blue to include the deployments resource in the apps API group. Edit the Role and add a rule for deployments:
deployments under the apps API group.
After saving the Role, verify it contains the deployments rule:
dev-user:
dev-user can now create Deployments in the blue namespace.
Summary
Links and References