Lab20 - Namespace - RBAC
Lab20 - Namespace - RBAC
Lab20 - Namespace - RBAC
Introduction
Role-based access control (RBAC) is a method of regulating access to computer or network
resources based on the roles of individual users within your organization. RBAC authorization
uses the rbac.authorization.k8s.io API group to drive authorization decisions, allowing you to
dynamically configure policies through the Kubernetes API.
In this lab, you will understand and work with the Namespace and RBAC.
Objectives:
• Create namespace
• Create user
• Create role & rolebinding
• Create clusterrolebinding
• Cleanup
1.1 Let us clone the git repository which contains manifests required for this exercise, by
executing the below command.
1.3 We can create a Namespace in two ways either by using kubectl create namespace
command or by using configuration file.
Create a new namespace with the name kube-core.
Output:
Output:
Output:
Output:
1.9 Let's view the manifest of file used to create new namespaces.
# cat -n ~/k8s-rbac/namespace-dev.json
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Note: Error is because the user has no privileges, let us now create roles and rolebindings which
allows the user to list the pods in production name space.
Output:
Student Material – Do Not Re-distribute. For any queries contact:
[email protected] or https://www.linkedin.com/in/naushadpasha/
1.21 Let us view the manifest of the role, by executing the below command:
# cat -n ~/k8s-rbac/role-pod-reader.yaml
Output:
Output:
1.23 Let us view the manifest for role binding, by executing the below command:
# cat -n ~/k8s-rbac/rolebinding-pod-reader.yaml
Output:
1.25 Let us describe the role pod-reader, by executing the below command
# kubectl describe role pod-reader --namespace=production
Output:
1.26 Let us describe the rolebinding read-pods, by executing the below command
# kubectl describe rolebinding read-pods --
namespace=production
Output:
1.27 Let us create a pod in the “production” namespace and see if the employee user can list
Output:
Output:
1.29 Let us now try to create the pod as employee user, by executing the below command.
Output:
Note: Pod creation failed as the user doesn’t have the privileges, we created the role to only
list the pods (which the user can). Let’s us make the user as cluster admin.
In most cases after provisioning our cluster using kops or kubeadm or any other popular tool
Clusteradmin Role already exists in the cluster. We can use it and create only
ClusterRoleBinding for our user “employee”.
1.30 Let us verify the cluster roles, by executing the below command:
Output:
# cat -n ~/k8s-rbac/clusterrolebinding.yaml
Output:
Output:
1.33 Now, the user employee is cluster-admin, let us now try to create the pod as employee
user, by executing the below command.
Output:
Note: User employee was able to create a pod in production namespace. Employee can also
create the pods in the default namespace as he is cluster-admin.
Output: