(Still needs the Manual Processes > Prerequisites to take place in your OpenID Connect Auth server, like Red Hat SSO)
In this directory you can find a ./configure.sh
file that will allow you to quickly apply OpenID Connect authentication to a logged in cluster. Edit the file and run as follows:
# Check configuration
./configure.sh
# Actually apply configuration
./configure.sh --commit
Requires the OpenID Connect Keycloak OIDC Credentials JSON file to be present on the system and/or other variables defined as well.
Before you can configure OpenShift to use OpenID Connect as an Identity Provider, you need to create the Client Application in your OpenID Connect Auth server. The following instructions will assume use of Red Hat SSO - you can find an easy/quick way to deploy Red Hat SSO to OpenShift here: https://github.com/kenmoini/rh-sso-demo
A few key things to note in general:
- For Valid Redirect URIs, provide the OpenShift OAuth Callback endpoint, eg
https://oauth-openshift.apps.cluster-3078.3078.sandbox601.opentlc.com/oauth2callback/myapp
following the format of:https://oauth-openshift.apps.<cluster_name>.<base_domain>/oauth2callback/<IdP_Name>
Some things to note for Red Hat SSO:
- Set the Login Theme to whatever you'd like
- Access Type should be set to
confidential
Click Save
If your OpenID Connect Server has a self-signed CA and/or Certificate not in the default system keystore then you'll need to get it and provide it to the OpenShift OAuth Cluster Configuration as a ConfigMap. If running Red Hat SSO on OpenShift you can get the router-ca
that secures the Application Routes with the following command:
oc get secret router-ca -n openshift-ingress-operator -o template='{{index .data "tls.key"}}' | base64 -d > $HOME/oidc-ca-cert.pem
Next, you can create the needed OpenShift Secret with the following command, so long as you are logged in as a cluster-admin, provided the downloaded Keycloak OpenID Connect JSON file is located in the $HOME
directory:
oc create secret generic myapp-oidc-client-secret --from-literal=clientSecret=$(jq -r '.credentials.secret' $HOME/oidc-creds.json) -n openshift-config
If you have a self-signed CA Certificate that needs to be provided to the OpenShift OAuth Configuration then you can create it with the following command, provided the PEM is located in the $HOME
directory:
oc create configmap myapp-oidc-client-ca-cert --from-file=ca.crt=$HOME/oidc-ca-cert.pem -n openshift-config
With the Secret{+ConfigMap} created, you can now reference it in the YAML definition of the OAuth provider:
-
Get the Client ID from the downloaded JSON file with the following command:
jq -r '.resource' $HOME/oidc-creds.json
-
Replace the needed text in the following YAML with whatever your Client configuration is:
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- mappingMethod: claim
name: myapp
openID:
ca:
name: myapp-oidc-client-ca-cert
claims:
email:
- email
name:
- name
preferredUsername:
- preferred_username
clientID: CLIENT_ID_HERE
clientSecret:
name: myapp-oidc-client-secret
extraScopes: []
issuer: >-
ISSUER_URI_HERE
Notes:
- Replace the CLIENT_ID_HERE and ISSUER_URI_HERE with your OpenID Connect Client information
- For RH SSO, the Issuer URI would look something like this:
https://sso.example.com/auth/realms/REALM_NAME
- For RH SSO, the Issuer URI would look something like this:
- The
.spec.identityProviders[0].name
is the same as the IdP Name prefixed to the end of the Valid Redirect URI that was created earlier
With the YAML created, we can apply it to the cluster now with the following command, assuming you saved it to a file called oauth.yaml:
WARNING The following command may overwrite your current IdP settings!
oc patch OAuth cluster --patch-file oauth.yaml
Once the Authentication Operator has restarted you should be able to log into the cluster with OpenID Connect Authentication!