Deploy and Configure Red Hat Single Sign-On on Red Hat OpenShift.
Outcomes
Install Red Hat Single Sign-On on Red Hat OpenShift.
Create Keycloak custom resources to configure RH-SSO.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that RH-SSO is not installed on Red Hat OpenShift and deploys the finance-webapp application.
[student@workstation ~]$ lab start ocp-review
Procedure 5.3. Instructions
Log in to your Red Hat OpenShift cluster as the admin user with the redhat password.
Create the rhsso project.
The web console URL is https://console-openshift-console.apps.ocp4.example.com.
Using OperatorHub, install the Red Hat Single Sign-On operator in the ocp4.example.com cluster.
Use the rhsso namespace.
Create the keycloak-db-secret secret in the rhsso namespace that is pointing to the external database by using following parameters:
| Field name | Value |
|---|---|
POSTGRES_DATABASE
|
keycloak
|
POSTGRES_EXTERNAL_ADDRESS
|
sso.lab.example.com
|
POSTGRES_EXTERNAL_PORT
|
5432
|
POSTGRES_PASSWORD
|
postgres
|
POSTGRES_USERNAME
|
postgres
|
Navigate to → , and ensure that the rhsso namespace is selected.
In the drop-down menu select the From YAML option. Then, enter manually the following content:
kind: Secret apiVersion: v1 metadata: name:keycloak-db-secretnamespace:rhssotype: Opaque stringData:POSTGRES_DATABASE: keycloakPOSTGRES_EXTERNAL_ADDRESS: sso.lab.example.comPOSTGRES_EXTERNAL_PORT: '5432'POSTGRES_PASSWORD: postgresPOSTGRES_USERNAME: postgres
Click .
Create the do313-keycloak Keycloak custom resource.
Navigate to the → menu, and click .
Click in the block.
On the page, select to display the web console YAML editor. Update the YAML code as follows and then click .
kind: Keycloak apiVersion: keycloak.org/v1alpha1 metadata: name:do313-keycloaklabels: app: sso namespace: rhsso spec: externalAccess: enabled: trueexternalDatabase:enabled: trueinstances: 1
The do313-keycloak keycloak shows in the tab. Wait for the to update from to .
It takes 5-10 minutes for the to update from to .
Create a KeycloakRealm custom resource called review-realm in the ocp4.example.com cluster by using the ~/DO313/labs/ocp-review/01keycloakrealm.yaml file.
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...Change to the ~/DO313/labs/ocp-review/ directory.
[student@workstation ~]$ cd ~/DO313/labs/ocp-review/Review the file called 01keycloakrealm.yaml to deploy the keycloakRealm custom resource.
[student@workstation ocp-review]$cat 01keycloakrealm.yaml...output omitted... apiVersion: keycloak.org/v1alpha1 kind: KeycloakRealm metadata: name:review-realmnamespace: rhsso labels: app: sso realm: review-realm spec: instanceSelector: matchLabels: app: sso realm: id:review-realmrealm:review-realmenabled: True displayName: "Review Realm"
The YAML file creates a realm called review-realm in RH-SSO.
Use the oc command to create the review-realm KeycloakRealm custom resource in the rhsso namespace.
[student@workstation ocp-review]$ oc create -f 01keycloakrealm.yaml
keycloakrealm.keycloak.org/review-realm createdCreate a KeycloakClient custom resource called review-client in the ocp4.example.com cluster by using the ~/DO313/labs/ocp-review/02keycloakclient.yaml file.
Update the ~/DO313/labs/ocp-review/03keycloakclient.yaml file to create the review-client client and review-client-secret client secret in RH-SSO.
Edit the 02keycloakclient.yaml file to change the following parameters:
| Field name | Value |
|---|---|
name
|
review-client
|
clientId
|
review-client
|
secret
|
review-client-secret
|
[student@workstation ocp-review]$vim 02keycloakclient.yamlapiVersion: keycloak.org/v1alpha1 kind: KeycloakClient metadata: name:review-clientnamespace: rhsso labels: app: sso realm: review-realm client: review-client spec: realmSelector: matchLabels: app: sso realm: review-realm client: clientId:review-clientsecret:review-client-secretdefaultClientScopes: - email - offline_access - profile - roles implicitFlowEnabled: False standardFlowEnabled: True redirectUris: - http://finance-webapp-review-project.apps.ocp4.example.com/finance/* rootUrl: http://finance-webapp-review-project.apps.ocp4.example.com/finance
The YAML file creates the review-client client in RH-SSO.
The finance-webapp application is configured to use the review-client-secret for the quarkus.oidc.credentials.secret.
Use the oc command to create the review-client KeycloakClient custom resource in the rhsso namespace.
[student@workstation ocp-review]$ oc create -f 02keycloakclient.yaml
keycloakclient.keycloak.org/review-client createdCreate a KeycloakUser custom resource called review-user in the ocp4.example.com cluster by using the ~/DO313/labs/ocp-review/03keycloakuser.yaml file.
Update the ~/DO313/labs/ocp-review/03keycloakuser.yaml file to create and enable the developer user with the redhat password in RH-SSO.
Edit the 03keycloakuser.yaml file to change the following parameters:
| Field name | Value |
|---|---|
name
|
review-user
|
username
|
developer
|
credentials:value
|
redhat
|
user:enabled
| True |
[student@workstation ocp-review]$vim 03keycloakuser.yamlapiVersion: keycloak.org/v1alpha1 kind: KeycloakUser metadata: name:review-usernamespace: rhsso labels: app: sso realm: review-realm spec: realmSelector: matchLabels: app: sso realm: review-realm user: username:developercredentials: - temporary: False type: password value:redhatfirstName: developer lastName: developer email: developer@example.com enabled:TrueemailVerified: True realmRoles: - offline_access
The YAML file creates the review-user KeycloakUser custom resource. The KeycloakUser custom resource creates and enables a developer user with the redhat password in the RH-SSO.
Use the oc command to create the review-user KeycloakUser custom resource in the rhsso namespace.
[student@workstation ocp-review]$ oc create -f 03keycloakuser.yaml
keycloakuser.keycloak.org/review-user createdAccess the finance-webapp application and retrieve the user access token.
The finance-webapp application URL is http://finance-webapp-review-project.apps.ocp4.example.com/finance.
Navigate to the finance-webapp application at http://finance-webapp-review-project.apps.ocp4.example.com/finance.
Click to access the token.
Log in as the developer user with redhat as the password.
If the configuration is correct, then the page displays the developer user access token.

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