Controlling access to OpenShift resources Flashcards
Log in to your OpenShift cluster as the admin user and remove the ability to create projects cluster wide.
- Log in to the cluster as the admin user.
$ oc login -u admin -p redhat \
> https://api.ocp4.example.com:6443 - Remove the self-provisioner cluster role from the system:authenticated:oauth virtual group.
$ oc adm policy remove-cluster-role-from-group \
> self-provisioner system:authenticated:oauth
Create a group named wp-mgrs for the WordPress managers and grant project creation privileges to it. Add the leader user to the group and create the authorization-review project as the leader user.
- Create a group named wp-mgrs.
$ oc adm groups new wp-mgrs - Grant cluster creation privileges to the wp-mgrs group.
$ oc adm policy add-cluster-role-to-group \
> self-provisioner wp-mgrs - Add the leader user to the wp-mgrs group.
$ oc adm groups add-users wp-mgrs leader - As the leader user, create the authorization-review project.
$ oc login -u leader -p redhat
oc new-project authorization-review
Create a group named wp-devs and grant edit privileges on the authorization-review project. Add the developer user to the group.
- Log in to the cluster as the admin user.
$ oc login -u admin -p redhat - Create a group named wp-devs.
$ oc adm groups new wp-devs - Add the developer user to wp-devs.
$ oc adm groups add-users wp-devs developer - Grant edit privileges to the wp-devs group on the authorization-review project.
$ oc policy add-role-to-group edit wp-devs
Create a group named wp-qa and grant view privileges on the authorization-review project. Add the qa user to the group.
1. Create a group named wp-qa. $ oc adm groups new wp-qa 2. Add the qa user to wp-qa. $ oc adm groups add-users wp-qa qa 3. Grant view privileges to the wp-qa group on the authorization-review project. $ oc policy add-role-to-group view wp-qa
Allow the wordpress application to run as root: create a service account named wordpress-sa and grant the anyuid SCC to it.
- Create a service account named wordpress-sa.
$ oc create sa wordpress-sa - Grant anyuid SCC to the wordpress-sa service account.
$ oc adm policy add-scc-to-user anyuid -z wordpress-sa
As the developer user, create a secret named review-secret, which you will use with the MySQL database and WordPress applications.
The secret should include three key-value pairs: user=wpuser, password=redhat123, and database=wordpress.
- Log in as the developer user.
$ oc login -u developer -p developer - Create a secret named review-secret.
$ oc create secret generic review-secret \
> –from-literal user=wpuser –from-literal password=redhat123 \
> –from-literal database=wordpress
Deploy a MySQL database application named mysql using the image located at registry.access.redhat.com/rhscl/mysql-57-rhel7:5.7-47. After it was deployed, modify the deployment to use the review-secret secret, as environment variables with the MYSQL_ prefix.
- Create a new application to deploy a mysql database server.
$ oc new-app –name mysql \
> –docker-image registry.access.redhat.com/rhscl/mysql-57-rhel7:5.7-47 - Use the review-secret secret to initialize the environment variables on the mysql deployment.
$ oc set env deployment/mysql –prefix MYSQL_ \
> –from secret/review-secret
Deploy a WordPress application named wordpress using the container image located at docker.io/library/wordpress:5.3.0. Add the WORDPRESS_DB_HOST=mysql and WORDPRESS_DB_NAME=wordpress environmental variables when creating the application. Once deployed, modify the wordpress deployment to use the review-secret secret as environment variables with the WORDPRESS_DB_ prefix. The application needs these additional variables to connect to the database. Because the wordpress application needs extra privileges, assign the wordpress-sa service account to it.
- Deploy a wordpress application.
$ oc new-app –name wordpress \
> –docker-image docker.io/library/wordpress:5.3.0 \
> -e WORDPRESS_DB_HOST=mysql \
> -e WORDPRESS_DB_NAME=wordpress - Set the wordpress-sa service account to the wordpress deployment.
$ oc set serviceaccount deployment/wordpress \
> wordpress-sa - Use the review-secret secret to initialize the environment variables on the wordpress deployment.
$ oc set env deployment/wordpress \
> –prefix WORDPRESS_DB_ –from secret/review-secret
As the qa user, verify the mysql database and wordpress application status and try to make a change to the wordpress deployment.
- Log in as the qa user.
$ oc login -u qa -p redhat - Verify the wordpress application status.
$ oc status - Try to delete the wordpress application to verify that the qa user does not have edit privileges in the project.
$ oc delete all -l app=wordpress