Configure Red Hat Single Sign-On on Red Hat OpenShift using custom resource definitions.
Outcomes
Deploy a KeycloakRealm custom resource.
Deploy a KeycloakClient custom resource.
Deploy a KeycloakUser custom resource.
Verify configuration of Red Hat Single Sign-On.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that the RH-SSO operator is installed and deploys the Keycloak custom resource and finance-webapp application.
[student@workstation ~]$ lab start ocp-configsso
Procedure 5.2. Instructions
Log in to your Red Hat OpenShift cluster as the admin user with the redhat password.
The web console URL is https://console-openshift-console.apps.ocp4.example.com.
From the workstation machine, navigate to the Red Hat OpenShift web console at https://console-openshift-console.apps.ocp4.example.com.
When prompted, click and log in as the admin user with the redhat password.
Access the finance-webapp application and retrieve the user access token for the application.
Navigate to → and select config-project from the field to display the list of routes in the config-project project.

The page shows the route. Click the URL to view the finance-webapp application front end.
On the subsequent web page, append /finance to the URL to display the application.
Click to view the user access token. The page displays an error.

The lab start command creates a Keycloak custom resource. Verify that the Keycloak custom resource is available and has reconciling status. After the Keycloak custom resource is in the reconciling status, you can create the custom resources in subsequent steps.
Open the terminal application on the workstation machine.
Log in to the ocp4.example.com cluster as the admin user.
[student@workstation ~]$ oc login -u admin -p redhat \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Check the status of the Keycloak CRD.
[student@workstation ~]$ oc get keycloak -n rhsso \
-o jsonpath='{.items[0].status.phase}{"\n"}'
reconcilingIt takes 5-10 minutes for the status to update from initialising to reconciling. If the command returns initialising output, then wait for some time and rerun the command.
Create a KeycloakRealm custom resource called configsso-realm in the ocp4.example.com cluster.
Change to the ~/DO313/labs/ocp-configsso/ directory.
[student@workstation ~]$ cd ~/DO313/labs/ocp-configsso/Review the file called 01keycloakrealm.yaml to deploy a keycloakRealm custom resource.
[student@workstation ocp-configsso]$cat 01keycloakrealm.yaml...output omitted... apiVersion: keycloak.org/v1alpha1 kind: KeycloakRealm metadata: name:configsso-realmnamespace: rhsso labels: app: sso realm: configsso-realm spec: instanceSelector: matchLabels: app: sso realm: id:configsso-realmrealm:configsso-realmenabled: True displayName: "Config Realm"
The YAML file creates a realm called configsso-realm in RH-SSO.
Use the oc command to create the configsso-realm KeycloakRealm custom resource in the rhsso namespace.
[student@workstation ocp-configsso]$ oc create -f 01keycloakrealm.yaml
keycloakrealm.keycloak.org/configsso-realm createdCreate a KeycloakClient custom resource called configsso-client in the ocp4.example.com cluster.
Edit the 02keycloakclient.yaml file to change the following parameters:
| Field name | Value |
|---|---|
name
|
configsso-client
|
clientId
|
configsso-client
|
secret
|
configsso-client-secret
|
[student@workstation ocp-configsso]$vim 02keycloakclient.yamlapiVersion: keycloak.org/v1alpha1 kind: KeycloakClient metadata: name:configsso-clientnamespace: rhsso labels: app: sso realm: configsso-realm client: configsso-client spec: realmSelector: matchLabels: app: sso realm: configsso-realm client: clientId:configsso-clientsecret:configsso-client-secretdefaultClientScopes: - email - offline_access - profile - roles implicitFlowEnabled: False standardFlowEnabled: True redirectUris: -http://finance-webapp-config-project.apps.ocp4.example.com/finance/*rootUrl:http://finance-webapp-config-project.apps.ocp4.example.com/finance
The YAML file creates the configsso-client client in RH-SSO.
The finance-webapp application is configured to use the configsso-client-secret for the quarkus.oidc.credentials.secret.
Use the oc command to create the configsso-client KeycloakClient custom resource in the rhsso namespace.
[student@workstation ocp-configsso]$ oc create -f 02keycloakclient.yaml
keycloakclient.keycloak.org/configsso-client createdCreate a KeycloakUser custom resource called configsso-user in the ocp4.example.com cluster.
Edit the 03keycloakuser.yaml file to change the following parameters:
| Field name | Value |
|---|---|
name
|
configsso-user
|
username
|
student
|
credentials:value
|
redhat
|
user:enabled
| True |
user:emailVerified
| True |
[student@workstation ocp-configsso]$vim 03keycloakuser.yamlapiVersion: keycloak.org/v1alpha1 kind: KeycloakUser metadata: name:configsso-usernamespace: rhsso labels: app: sso realm: configsso-realm spec: realmSelector: matchLabels: app: sso realm: configsso-realm user: username:studentcredentials: - temporary: False type: password value:redhatfirstName: student lastName: student email: student@example.com enabled:TrueemailVerified:TruerealmRoles: - offline_access
The YAML file creates the configsso-user KeycloakUser custom resource. The KeycloakUser custom resource creates and enables a student user and redhat password for the user in the RH-SSO.
Use the oc command to create the configsso-user KeycloakUser custom resource in the rhsso namespace.
[student@workstation ocp-configsso]$ oc create -f 03keycloakuser.yaml
keycloakuser.keycloak.org/configsso-user createdAccess the finance-webapp application and retrieve the user access token.
Navigate to the finance-webapp application at http://finance-webapp-config-project.apps.ocp4.example.com/finance.
Click to access the token.
Log in as the student user with redhat as the password. The page displays a student user access token.

Close all the Firefox windows and change to the /home/student directory.
[student@workstation ocp-configsso]$ cd ~
[student@workstation ~]$