$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
Configure an oidc
identity provider to integrate with an OpenID Connect
identity provider using an
Authorization Code Flow.
You can configure Red Hat Single Sign-On as an OpenID Connect identity provider for OpenShift Container Platform.
The Authentication Operator in OpenShift Container Platform requires that the configured OpenID Connect identity provider implements the OpenID Connect Discovery specification. |
|
By default, the openid
scope is requested. If required, extra scopes can be
specified in the extraScopes
field.
Claims are read from the JWT id_token
returned from the OpenID identity
provider and, if specified, from the JSON returned by the UserInfo
URL.
At least one claim must be configured to use as the user’s identity. The
standard identity claim is sub
.
You can also indicate which claims to use as the user’s preferred user name, display name, and email address. If multiple claims are specified, the first one with a non-empty value is used. The standard claims are:
sub
|
Short for "subject identifier." The remote identity for the user at the issuer. |
preferred_username
|
The preferred user name when provisioning a user. A
shorthand name that the user wants to be referred to as, such as |
email
|
Email address. |
name
|
Display name. |
See the OpenID claims documentation for more information.
Using an OpenID Connect identity provider requires users to get a token using
|
By default, only a kubeadmin
user exists on your cluster. To specify an
identity provider, you must create a Custom Resource (CR) that describes
that identity provider and add it to the cluster.
OpenShift Container Platform user names containing |
Identity providers use OpenShift Container Platform Secrets in the openshift-config
namespace to contain the client secret, client certificates, and keys.
You can define an OpenShift Container Platform Secret containing a string by using the following command.
$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
You can define an OpenShift Container Platform Secret containing the contents of a file, such as a certificate file, by using the following command.
$ oc create secret generic <secret_name> --from-file=/path/to/file -n openshift-config
Identity providers use OpenShift Container Platform configmaps in the openshift-config
namespace to contain the certificate authority bundle. These are primarily
used to contain certificate bundles needed by the identity provider.
Define an OpenShift Container Platform configmap containing the
certificate authority by using the following command. The certificate
authority must be stored in the ca.crt
key of the configmap.
$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
The following Custom Resources (CRs) show the parameters and acceptable values for an OpenID Connect identity provider.
If you must specify a custom certificate bundle, extra scopes, extra authorization request
parameters, or a userInfo
URL, use the full OpenID Connect CR.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: oidcidp (1)
mappingMethod: claim (2)
type: OpenID
openID:
clientID: ... (3)
clientSecret: (4)
name: idp-secret
claims: (5)
preferredUsername:
- preferred_username
name:
- name
email:
- email
issuer: https://www.idp-issuer.com (6)
1 | This provider name is prefixed to the value of the identity claim to form an identity name. It is also used to build the redirect URL. |
2 | Controls how mappings are established between this provider’s identities and user objects. |
3 | The client ID of a client registered with the OpenID provider. The
client must be allowed to redirect to
https://oauth-openshift.apps.<cluster_name>.<cluster_domain>/oauth2callback/<idp_provider_name> . |
4 | Reference to an OpenShift Container Platform Secret containing the client secret. |
5 | List of claims to use as the identity. First non-empty claim is used. At
least one claim is required. If none of the listed claims have a value,
authentication fails. For example, this uses the value of the sub claim in the returned id_token as the user’s identity. |
6 | Issuer Identifier
described in the OpenID spec. Must use https without query or fragment
component. |
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: oidcidp
mappingMethod: claim
type: OpenID
openID:
clientID: ...
clientSecret:
name: idp-secret
ca: (1)
name: ca-config-map
extraScopes: (2)
- email
- profile
extraAuthorizeParameters: (3)
include_granted_scopes: "true"
claims:
preferredUsername: (4)
- preferred_username
- email
name: (5)
- nickname
- given_name
- name
email: (6)
- custom_email_claim
- email
issuer: https://www.idp-issuer.com
1 | Optional: Reference to an OpenShift Container Platform configmap containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL. |
2 | Optional list of scopes to request, in addition to the openid scope,
during the authorization token request. |
3 | Optional map of extra parameters to add to the authorization token request. |
4 | List of claims to use as the preferred user name when provisioning a user for this identity. First non-empty claim is used. |
5 | List of claims to use as the display name. First non-empty claim is used. |
6 | List of claims to use as the email address. First non-empty claim is used. |
After you install your cluster, add an identity provider to it so your users can authenticate.
Create an OpenShift Container Platform cluster.
Create the Custom Resource (CR) for your identity providers.
You must be logged in as an administrator.
Apply the defined CR:
$ oc apply -f </path/to/CR>
If a CR does not exist, |
Obtain a token from the OAuth server.
As long as the kubeadmin
user has been removed, the oc login
command provides instructions on how to access a web page where you can retrieve the token.
You can also access this page from the web console by navigating to (?) Help → Command Line Tools → Copy Login Command.
Log in to the cluster, passing in the token to authenticate.
$ oc login --token=<token>
This identity provider does not support logging in with a user name and password. |
Confirm that the user logged in successfully, and display the user name.
$ oc whoami
Configure your identity provider (IDP) through the web console instead of the CLI.
You must be logged in to the web console as a cluster administrator.
Navigate to Administration → Cluster Settings.
Under the Global Configuration tab, click OAuth.
Under the Identity Providers section, select your identity provider from the Add drop-down menu.
You can specify multiple IDPs through the web console without overwriting existing IDPs. |