Guided Exercise: Define and Apply Permissions with RBAC
Define role-based access controls and apply permissions to users.
Outcomes
- Remove project creation privileges from users who are not OpenShift cluster administrators.
- Create OpenShift groups and add members to these groups.
- Create a project and assign project administration privileges to the project.
- As a project administrator, assign read and write privileges to different groups of users.
Instructions
-
Log in to the OpenShift cluster and determine which cluster role bindings assign the
self-provisioner
cluster role.-
Run the login command in your terminal, with the login provided to you (requires admin access):
-
List all cluster role bindings that reference the
self-provisioner
cluster role.
-
-
Remove the privilege to create projects from all users who are not cluster administrators by deleting the
self-provisioner
cluster role from thesystem:authenticated:oauth
virtual group.-
Confirm that the
self-provisioners
cluster role binding that you found in the previous step assigns theself-provisioner
cluster role to thesystem:authenticated:oauth
group.Expected output:
-
Remove the
self-provisioner
cluster role from thesystem:authenticated:oauth
virtual group, which deletes theself-provisioners
role binding.Expected output:
Warning: Your changes may get lost whenever a master is restarted, unless you prevent reconciliation of this rolebinding using the following command: oc annotate clusterrolebinding.rbac self-provisioners 'rbac.authorization.kubernetes.io/autoupdate=false' --overwrite clusterrole.rbac.authorization.k8s.io/self-provisioner removed: "system:authenticated:oauth"
Note
You can safely ignore the warning about your changes being lost.
-
Verify that the role is removed from the group. The cluster role binding
self-provisioners
should not exist.Expected output:
-
Determine whether any other cluster role bindings reference the
self-provisioner
cluster role.Expected output:
-
Log in as the
leader-${SUFFIX}
user with theredhat
password.Expected output:
-
Try to create a project. The operation should fail.
Expected output:
-
-
Create a project and add project administration privileges to the
leader-${SUFFIX}
user.-
Log in with your admin user:
Expected output:
-
Create the
auth-rbac-${SUFFIX}
project.Expected output:
-
Grant project administration privileges to the
leader-${SUFFIX}
user on theauth-rbac-${SUFFIX}
project.Expected output:
-
-
Create the
dev-group-${SUFFIX}
andqa-group-${SUFFIX}
groups and add their respective members.-
Create a group named
dev-group-${SUFFIX}
.Expected output:
-
Add the
developer-${SUFFIX}
user to the group that you created in the previous step.Expected output:
-
Create a second group named
qa-group-${SUFFIX}
.Expected output:
-
Add the
qa-engineer-${SUFFIX}
user to the group that you created in the previous step.Expected output:
-
Review all existing OpenShift groups to verify that they have the correct members.
-
-
As the
leader-${SUFFIX}
user, assign write privileges fordev-group-${SUFFIX}
and read privileges forqa-group-${SUFFIX}
to theauth-rbac-${SUFFIX}
project.-
Log in as the
leader-${SUFFIX}
user.Expected output:
-
Add write privileges to the
dev-group-${SUFFIX}
group on theauth-rbac-${SUFFIX}
project.Expected output:
-
Add read privileges to the
qa-group-${SUFFIX}
group on theauth-rbac-${SUFFIX}
project.Expected output:
-
Review all role bindings on the
auth-rbac-${SUFFIX}
project to verify that they assign roles to the correct groups and users. The following output omits default role bindings that OpenShift assigns to service accounts.
-
-
As the
developer-${SUFFIX}
user, deploy an Apache HTTP Server to prove that thedeveloper-${SUFFIX}
user has write privileges in the project. Also try to grant write privileges to theqa-engineer-${SUFFIX}
user to prove that thedeveloper-${SUFFIX}
user has no project administration privileges.-
Log in as the
developer-${SUFFIX}
user.Expected output:
-
Deploy an Apache HTTP Server by using the standard image stream from OpenShift.
Expected output:
_...output omitted..._ --> Creating resources ... imagestreamtag.image.openshift.io "httpd:2.4" created Warning: would violate PodSecurity "restricted:v1.24": _...output omitted..._ deployment.apps "httpd" created service "httpd" created --> Success _...output omitted..._
Note
It is safe to ignore pod security warnings for exercises in this course. OpenShift uses the Security Context Constraints controller to provide safe defaults for pod security.
-
Try to grant write privileges to the
qa-engineer-${SUFFIX}
user. The operation should fail.Expected output:
-
-
Verify that the
qa-engineer-${SUFFIX}
user can view objects in theauth-rbac-${SUFFIX}
project, but not modify anything.-
Log in as the
qa-engineer-${SUFFIX}
user.Expected output:
-
Attempt to scale the
httpd
application. The operation should fail.Expected output:
-
-
Restore project creation privileges to all users.
-
Log in with your admin user:
-
Restore project creation privileges for all users by re-creating the
self-provisioners
cluster role binding that the OpenShift installer created.oc adm policy add-cluster-role-to-group --rolebinding-name self-provisioners self-provisioner system:authenticated:oauth
Expected output:
Warning: Group 'system:authenticated:oauth' not found clusterrole.rbac.authorization.k8s.io/self-provisioner added: "system:authenticated:oauth"
Note
You can safely ignore the warning that the group was not found.
-
Congrats, you have completed the lab!