Chapter 7. Configuring identity providers
7.1. Configuring an htpasswd identity provider Copy linkLink copied to clipboard!
Configure the htpasswd identity provider so users can log in to OpenShift Container Platform with credentials from an htpasswd file.
To define an htpasswd identity provider, complete these tasks:
-
Create an
htpasswdfile to store the user and password information. -
Create a secret to represent the
htpasswdfile. -
Define an
htpasswdidentity provider resource that references the secret. - Apply the resource to the default OAuth configuration to add the identity provider.
7.1.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.1.2. About htpasswd authentication Copy linkLink copied to clipboard!
Configure htpasswd authentication to use a flat password file for login to OpenShift Container Platform. The file stores hashed credentials for each user and enables local authentication without an external identity provider.
Do not use htpasswd authentication in OpenShift Container Platform for production environments. Use htpasswd authentication only for development environments.
7.1.3. Create the htpasswd file Copy linkLink copied to clipboard!
To configure the htpasswd identity provider, create an htpasswd file so usernames and hashed passwords are available for the cluster secret. The following procedures describe how to create the file on Linux and Windows Operating Systems.
-
Creating an
htpasswdfile using Linux -
Creating an
htpasswdfile using Windows
7.1.3.1. Create an htpasswd file using Linux Copy linkLink copied to clipboard!
Create a flat htpasswd file on Red Hat Enterprise Linux (RHEL) with the htpasswd utility to store usernames and hashed passwords for your cluster. The file enables the htpasswd identity provider to authenticate users in OpenShift Container Platform from locally stored credentials.
Prerequisites
-
You have access to the
htpasswdutility. On Red Hat Enterprise Linux (RHEL), this is available by installing thehttpd-toolspackage.
Procedure
Create or update your
htpasswdfile with a username and hashed password by running the following command:$ htpasswd -c -B -b </path/to/users.htpasswd> <username> <password>The command generates a hashed version of the password.
For example:
$ htpasswd -c -B -b users.htpasswd <username> <password>Example output
Adding password for user user1Continue to add or update credentials to the file by running the following command:
$ htpasswd -B -b </path/to/users.htpasswd> <user_name> <password>
7.1.3.2. Create an htpasswd file using Windows Copy linkLink copied to clipboard!
Create a flat htpasswd file on Windows with the htpasswd.exe utility to store usernames and hashed passwords for your cluster. The file enables the htpasswd identity provider to authenticate users in OpenShift Container Platform from locally stored credentials.
Prerequisites
-
You have access to the
htpasswd.exeutility. On Windows, this utility is included in the\binsubdirectory of many Apache httpd distributions.
Procedure
Create or update your
htpasswdfile with a username and hashed password by running the following command:$ htpasswd.exe -c -B -b <\path\to\users.htpasswd> <username> <password>The command generates a hashed version of the password.
For example:
$ htpasswd.exe -c -B -b users.htpasswd <username> <password>Example output
Adding password for user user1Continue to add or update credentials to the file by running the following command:
$ htpasswd.exe -b <\path\to\users.htpasswd> <username> <password>
7.1.4. Create the htpasswd secret Copy linkLink copied to clipboard!
Create an OpenShift Container Platform secret from your htpasswd file so the htpasswd identity provider can read user credentials for cluster login.
Prerequisites
-
You created an
htpasswdfile.
Procedure
Create a
Secretobject that contains thehtpasswdusers file by running the following command:$ oc create secret generic htpass-secret --from-file=htpasswd=<path_to_users.htpasswd> -n openshift-configThe
--from-filekey must be namedhtpasswd.TipYou can alternatively apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: htpass-secret namespace: openshift-config type: Opaque data: htpasswd: <base64_encoded_htpasswd_file_contents>
7.1.5. Sample htpasswd CR Copy linkLink copied to clipboard!
Review the custom resource fields and acceptable values for configuring an htpasswd identity provider in OpenShift Container Platform.
htpasswd CR
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: my_htpasswd_provider
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret
where:
spec.identityProviders.name- Specifies the provider name, which is prefixed to provider usernames to form an identity name.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between identities from this provider and
Userobjects. spec.identityProviders.htpasswd.fileData.name-
Specifies an existing secret containing a file generated using
htpasswd. For more information, see "htpasswd".
7.1.6. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Log in to the cluster as a user from your identity provider, entering the password when prompted.
$ oc login -u <username>Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.1.7. Update users for an htpasswd identity provider Copy linkLink copied to clipboard!
Update users in the htpasswd identity provider so login credentials in OpenShift Container Platform stay in sync when you add or remove accounts.
Prerequisites
-
You have created a
Secretobject namedhtpass-secretthat contains thehtpasswduser file. -
You have configured an
htpasswdidentity provider namedmy_htpasswd_provider. -
You have access to the
htpasswdutility. On Red Hat Enterprise Linux (RHEL), this is available by installing thehttpd-toolspackage. - You have cluster administrator privileges.
Procedure
Retrieve the
htpasswdfile from thehtpass-secretSecretobject and save it to your local machine by running the following command:$ oc get secret htpass-secret -ojsonpath={.data.htpasswd} -n openshift-config | base64 --decode > users.htpasswdAdd or remove users from the
users.htpasswdfile by running the following commands:To add a new user:
$ htpasswd -bB users.htpasswd <username> <password>Example output
Adding password for user <username>To remove an existing user:
$ htpasswd -D users.htpasswd <username>Example output
Deleting password for user <username>
Replace the
htpass-secretSecretobject with the updated users in theusers.htpasswdfile by running the following command:$ oc create secret generic htpass-secret --from-file=htpasswd=users.htpasswd --dry-run=client -o yaml -n openshift-config | oc replace -f -TipYou can also apply the following YAML to replace the secret:
apiVersion: v1 kind: Secret metadata: name: htpass-secret namespace: openshift-config type: Opaque data: htpasswd: <base64_encoded_htpasswd_file_contents>If you removed one or more users, you must remove the existing resources for each user by running the following commands:
Delete the
Userobject:$ oc delete user <username>Example output
user.user.openshift.io "<username>" deletedBe sure to remove the user, otherwise the user can continue using their token as long as it has not expired.
Delete the
Identityobject for the user:$ oc delete identity my_htpasswd_provider:<username>Example output
identity.user.openshift.io "my_htpasswd_provider:<username>" deleted
7.1.8. Configure identity providers using the web console Copy linkLink copied to clipboard!
You can configure identity providers on your OpenShift Container Platform cluster through the web console by updating the OAuth settings in the Cluster Settings.
Prerequisites
- You are logged in to the web console as a cluster administrator.
Procedure
-
Navigate to Administration
Cluster Settings. - Under the Configuration tab, click OAuth.
Under the Identity Providers section, select your identity provider from the Add drop-down list.
NoteYou can specify multiple identity providers through the web console without overwriting existing identity providers.
7.2. Configuring a Keystone identity provider Copy linkLink copied to clipboard!
Configure a Keystone identity provider to connect OpenShift Container Platform to an OpenStack Keystone v3 server so that users can sign in with Keystone credentials.
7.2.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.2.2. About Keystone authentication Copy linkLink copied to clipboard!
Configure Keystone authentication in OpenShift Container Platform to share sign-in with your OpenStack Keystone server. Mapping users by Keystone ID reduces access risk when usernames are reused.
Map OpenShift Container Platform users to Keystone usernames or unique Keystone IDs. Users log in with their Keystone username and password.
Basing users on the Keystone ID is gives each user a unique identity. If you delete a Keystone user, then create a new user with the same username but a different Keystone ID, the new user does not have access to resources of the deleted user.
7.2.3. Create the secret Copy linkLink copied to clipboard!
You can create a TLS Secret object in the openshift-config namespace by using the oc CLI or by applying a YAML file to store client certificates and keys that identity providers require for secure communication.
Procedure
Create a
Secretobject that contains the key and certificate by running the following command:$ oc create secret tls <secret_name> --key=key.pem --cert=cert.pem -n openshift-configOptional: Apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: <secret_name> namespace: openshift-config type: kubernetes.io/tls data: tls.crt: <base64_encoded_cert> tls.key: <base64_encoded_key>
7.2.4. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.2.5. Sample Keystone custom resource Copy linkLink copied to clipboard!
You can configure a Keystone identity provider for your cluster by applying an OAuth custom resource (CR) with a Keystone identity provider. Review domain name, server URL, certificate authority, and TLS client certificate parameters in this sample before you connect to your Keystone server.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: keystoneidp
mappingMethod: claim
type: Keystone
keystone:
domainName: default
url: https://keystone.example.com:5000
ca:
name: ca-config-map
tlsClientCert:
name: client-cert-secret
tlsClientKey:
name: client-key-secret
where:
spec.identityProviders.name- Specifies the provider name, which is prefixed to provider usernames to form an identity name.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between identities from this provider and
Userobjects. spec.identityProviders.keystone.domainName- Specifies the Keystone domain name. In Keystone, usernames are domain-specific. Only a single domain is supported.
spec.identityProviders.keystone.url-
Specifies the URL to use to connect to the Keystone server (required). This must use
https. spec.identityProviders.keystone.ca-
Specifies an optional reference to an OpenShift Container Platform
ConfigMapobject containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL. spec.identityProviders.keystone.tlsClientCert-
Specifies an optional reference to an OpenShift Container Platform
Secretobject containing the client certificate to present when making requests to the configured URL. spec.identityProviders.keystone.tlsClientKey-
Specifies a reference to an OpenShift Container Platform
Secretobject containing the key for the client certificate. Required iftlsClientCertis specified.
7.2.6. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Log in to the cluster as a user from your identity provider, entering the password when prompted.
$ oc login -u <username>Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.3. Configuring an LDAP identity provider Copy linkLink copied to clipboard!
Configure an LDAP identity provider so users can log in to OpenShift Container Platform with usernames and passwords validated against your LDAPv3 directory.
7.3.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.3.2. About LDAP authentication Copy linkLink copied to clipboard!
Review how usernames and passwords are validated against the LDAP directory so you can configure the LDAP identity provider correctly.
During authentication, the LDAP directory is searched for an entry that matches the provided username. If a single unique match is found, a simple bind is attempted using the distinguished name (DN) of the entry plus the provided password.
LDAP authentication uses the following process:
-
Generates a search filter by combining the attribute and filter in the configured
urlwith the user-provided username. - Searches the directory using the generated filter. Denies access if the search does not return exactly one entry.
- Attempts to bind to the LDAP server using the DN of the entry retrieved from the search, and the user-provided password.
- Denies access if the bind is unsuccessful.
- Builds an identity using the configured attributes as the identity, email address, display name, and preferred username if the bind is successful.
The configured url is an RFC 2255 URL, which specifies the LDAP host and search parameters to use. The syntax of the URL is:
ldap://host:port/basedn?attribute?scope?filter
For this URL:
| URL component | Description |
|---|---|
|
|
For regular LDAP, use the string |
|
|
The name and port of the LDAP server. Defaults to |
|
| The DN of the branch of the directory where all searches should start from. At the very least, this must be the top of your directory tree, but it could also specify a subtree in the directory. |
|
|
The attribute to search for. Although RFC 2255 allows a comma-separated list of attributes, only the first attribute is used, no matter how many are provided. If no attributes are provided, the default is to use |
|
|
The scope of the search. Can be either |
|
|
A valid LDAP search filter. If not provided, defaults to |
During a search, the attribute and filter from the configured url are combined with the user-provided username to create a search filter in the following format:
(&(<filter>)(<attribute>=<username>))
For example, consider a URL of:
ldap://ldap.example.com/o=Acme?cn?sub?(enabled=true)
When a client attempts to connect using username bob, the resulting search filter is (&(enabled=true)(cn=bob)).
If the LDAP directory requires authentication to search, specify a bindDN and bindPassword to use to perform the entry search.
7.3.3. Create the LDAP secret Copy linkLink copied to clipboard!
Create a secret that contains the LDAP bind password in the openshift-config namespace so the identity provider can authenticate to the directory.
Procedure
Create a
Secretobject that contains thebindPasswordfield by running the following command:$ oc create secret generic ldap-secret --from-literal=bindPassword=<secret> -n openshift-configwhere:
<secret>-
Specifies the LDAP bind password value for the
--from-literalargument. The key name must bebindPassword.
Alternatively, apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: ldap-secret namespace: openshift-config type: Opaque data: bindPassword: <base64_encoded_bind_password>
7.3.4. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.3.5. Sample LDAP custom resource Copy linkLink copied to clipboard!
Review the sample LDAP custom resource (CR) and acceptable parameter values so you can configure attribute mappings, bind credentials, and connection settings for the LDAP identity provider.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: ldapidp
mappingMethod: claim
type: LDAP
ldap:
attributes:
id:
- dn
email:
- mail
name:
- cn
preferredUsername:
- uid
bindDN: ""
bindPassword:
name: ldap-secret
ca:
name: ca-config-map
insecure: false
url: "ldaps://ldaps.example.com/ou=users,dc=acme,dc=com?uid"
where:
spec.identityProviders.name- Specifies the provider name. The provider name is prefixed to the returned user ID to form an identity
spec.identityProviders.mappingMethod-
Specifies how mappings are established between the identities of this provider and
Userobjects. spec.identityProviders.ldap.attributes.id- Specifies the list of attributes to use as the identity. The first non-empty attribute is used. At least one attribute is required. If none of the listed attributes have a value, authentication fails. Defined attributes are retrieved as raw, allowing binary values to be used.
spec.identityProviders.ldap.attributes.email- Specifies the list of attributes to use as the email address. The first non-empty attribute is used.
spec.identityProviders.ldap.attributes.name- Specifies the list of attributes to use as the display name. The first non-empty attribute is used.
spec.identityProviders.ldap.attributes.preferredUsername- Specifies the list of attributes to use as the preferred username when provisioning a user for this identity. The first non-empty attribute is used.
spec.identityProviders.ldap.bindDN-
Specifies the optional DN to use to bind during the search phase. Must be set if
bindPasswordis defined. spec.identityProviders.ldap.bindPassword-
Specifies an optional reference to an OpenShift Container Platform
Secretobject containing the bind password. Must be set ifbindDNis defined. spec.identityProviders.ldap.ca-
Specifies an optional reference to an OpenShift Container Platform
ConfigMapobject containing the Privacy-Enhanced Mail (PEM)-encoded certificate authority bundle to use in validating server certificates for the configured URL. Only used wheninsecureisfalse. spec.identityProviders.ldap.insecure-
Specifies whether a TLS connection is made to the server. When
true, no TLS connection is made to the server. Whenfalse,ldaps://URLs connect using TLS, andldap://URLs are upgraded to TLS. This must be set tofalsewhenldaps://URLs are in use, as these URLs always attempt to connect using TLS. spec.identityProviders.ldap.url- Specifies an RFC 2255 URL for the LDAP host and search parameters to use.
To allowlist users for an LDAP integration, use the lookup mapping method. Before a login from LDAP is allowed, a cluster administrator must create an Identity object and a User object for each LDAP user.
7.3.6. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Log in to the cluster as a user from your identity provider, entering the password when prompted.
$ oc login -u <username>Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.4. Configuring a basic authentication identity provider Copy linkLink copied to clipboard!
Configure the basic-authentication identity provider. Users can log in to OpenShift Container Platform with credentials validated against a remote authentication service, without maintaining a separate user store in the cluster.
7.4.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.4.2. About basic authentication Copy linkLink copied to clipboard!
Configure basic authentication to validate user credentials against a remote service over HTTP. Use this integration when you need a flexible back-end for username and password login in OpenShift Container Platform.
Basic authentication is a generic back-end integration mechanism that allows users to log in to OpenShift Container Platform with credentials validated against a remote identity provider.
Because basic authentication is generic, you can use this identity provider for advanced authentication configurations.
Basic authentication must use an HTTPS connection to the remote server to prevent potential snooping of the user ID and password and man-in-the-middle attacks.
With basic authentication configured, users send their username and password to OpenShift Container Platform during login. OpenShift Container Platform validates those credentials against a remote server. OpenShift Container Platform makes a server-to-server request, passing the credentials as a basic authentication header.
This only works for username and password login mechanisms, and OpenShift Container Platform must be able to make network requests to the remote authentication server.
Usernames and passwords are validated against a remote URL that is protected by basic authentication and returns JSON.
A 401 response indicates failed authentication.
A non-200 status, or the presence of a non-empty "error" key, indicates an error:
{"error":"Error message"}
A 200 status with a sub (subject) key indicates success:
{"sub":"userid"}
where:
userid- Specifies a value that is unique to the authenticated user and must not be modified.
A successful response can optionally provide additional data, such as:
A display name using the
namekey. For example:{"sub":"userid", "name": "User Name", ...}An email address using the
emailkey. For example:{"sub":"userid", "email":"user@example.com", ...}A preferred username using the
preferred_usernamekey. This is useful when the unique, unchangeable subject is a database key or UID, and a more human-readable name exists. This is used as a hint when provisioning the OpenShift Container Platform user for the authenticated identity. For example:{"sub":"014fbff9a07c", "preferred_username":"bob", ...}
7.4.3. Create the secret Copy linkLink copied to clipboard!
You can create a TLS Secret object in the openshift-config namespace by using the oc CLI or by applying a YAML file to store client certificates and keys that identity providers require for secure communication.
Procedure
Create a
Secretobject that contains the key and certificate by running the following command:$ oc create secret tls <secret_name> --key=key.pem --cert=cert.pem -n openshift-configOptional: Apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: <secret_name> namespace: openshift-config type: kubernetes.io/tls data: tls.crt: <base64_encoded_cert> tls.key: <base64_encoded_key>
7.4.4. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.4.5. Sample basic authentication custom resource Copy linkLink copied to clipboard!
You can configure basic authentication for your cluster by applying an OAuth custom resource (CR) with a BasicAuth identity provider. Use this sample to review provider parameters and acceptable values before you connect to your remote authentication server.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: basicidp
mappingMethod: claim
type: BasicAuth
basicAuth:
url: https://www.example.com/remote-idp
ca:
name: ca-config-map
tlsClientCert:
name: client-cert-secret
tlsClientKey:
name: client-key-secret
where:
spec.identityProviders.name- Specifies that the provider name is prefixed to the returned user ID to form an identity name.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between the identities of this provider and
Userobjects. spec.identityProviders.basicAuth.url- Specifies the URL that accepts credentials in Basic authentication headers.
spec.identityProviders.basicAuth.ca-
Optional: Specifies a reference to an OpenShift Container Platform
ConfigMapobject containing the Privacy-Enhanced Mail (PEM)-encoded certificate authority bundle to use in validating server certificates for the configured URL. spec.identityProviders.basicAuth.tlsClientCert-
Optional: Specifies a reference to an OpenShift Container Platform
Secretobject containing the client certificate to present when making requests to the configured URL. spec.identityProviders.basicAuth.tlsClientKey-
Specifies a reference to an OpenShift Container Platform
Secretobject containing the key for the client certificate. Required iftlsClientCertis specified.
7.4.6. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Log in to the cluster as a user from your identity provider, entering the password when prompted.
$ oc login -u <username>Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.4.7. Example Apache HTTPD configuration for basic identity providers Copy linkLink copied to clipboard!
You can use CGI scripting in Apache HTTPD to configure a remote authentication server that returns JSON responses for basic identity providers in OpenShift Container Platform.
The following is an example of an Apache VirtualHost configuration file.
<VirtualHost *:443>
# CGI Scripts in here
DocumentRoot /var/www/cgi-bin
# SSL Directives
SSLEngine on
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
# Configure HTTPD to execute scripts
ScriptAlias /basic /var/www/cgi-bin
# Handles a failed login attempt
ErrorDocument 401 /basic/fail.cgi
# Handles authentication
<Location /basic/login.cgi>
AuthType Basic
AuthName "Please Log In"
AuthBasicProvider file
AuthUserFile /etc/httpd/conf/passwords
Require valid-user
</Location>
</VirtualHost>
The following is an example of a login.cgi CGI script file.
#!/bin/bash
echo "Content-Type: application/json"
echo ""
echo '{"sub":"userid", "name":"'$REMOTE_USER'"}'
exit 0
The following is an example of a fail.cgi CGI script file.
#!/bin/bash
echo "Content-Type: application/json"
echo ""
echo '{"error": "Login failure"}'
exit 0
7.4.7.1. File requirements Copy linkLink copied to clipboard!
These are the requirements for the files you create on an Apache HTTPD web server:
-
The
login.cgiandfail.cgiCGI script files must be executable. Use thechmod +xcommand on both files. -
If SELinux is enabled, the
login.cgiandfail.cgiCGI script files must have proper SELinux security contexts. Run therestorecon -RFv /var/www/cgi-bincommand, or ensure that the context is thehttpd_sys_script_exec_tSELinux type by using thels -laZcommand. -
The
login.cgiCGI script file runs only when the user successfully logs in according to theRequireandAuthApache configuration directives. -
The
fail.cgiCGI script file runs when the user fails to log in and returns anHTTP 401HTTP status code.
7.4.8. Troubleshoot basic authentication Copy linkLink copied to clipboard!
Troubleshoot basic authentication by testing backend connectivity and verifying JSON login responses when users cannot authenticate in OpenShift Container Platform.
The most common issue relates to network connectivity to the backend server. To debug connectivity, run curl commands on a control plane node.
Procedure
To test successful and unsuccessful logins, replace the
<user>and<password>in the following example command with valid or invalid credentials:$ curl --cacert /path/to/ca.crt --cert /path/to/client.crt --key /path/to/client.key -u <user>:<password> -v https://www.example.com/remote-idpReview successful login responses.
A
200status with asub(subject) key indicates success:{"sub":"userid"}The subject must be unique to the authenticated user and must not be modified.
A successful response can optionally provide additional data, such as:
A display name using the
namekey:{"sub":"userid", "name": "User Name", ...}An email address using the
emailkey:{"sub":"userid", "email":"user@example.com", ...}A preferred username using the
preferred_usernamekey:{"sub":"014fbff9a07c", "preferred_username":"bob", ...}
The
preferred_usernamekey is useful when the unique, unchangeable subject is a database key or UID, and a more human-readable name exists. This is used as a hint when provisioning the OpenShift Container Platform user for the authenticated identity.Review failed login responses.
-
A
401response indicates failed authentication. -
A non-
200status or the presence of a non-empty "error" key indicates an error:{"error":"Error message"}
-
A
7.5. Configuring a request header identity provider Copy linkLink copied to clipboard!
Configure the request-header identity provider to identify users from request header values, such as X-Remote-User. Use this provider when an authenticating proxy validates users and sets those headers for OpenShift Container Platform.
7.5.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.5.2. About request header authentication Copy linkLink copied to clipboard!
Request header authentication identifies users from header values such as X-Remote-User. An authenticating proxy with mutual TLS (mTLS) validates users and sets the identity header for OpenShift Container Platform.
The request header identity provider is typically used in combination with an authenticating proxy, which sets the request header value. This identity provider cannot be combined with other identity providers that use direct password logins, such as htpasswd, Keystone, LDAP or basic authentication.
You can also use the request header identity provider for advanced configurations such as the community-supported SAML application. This solution is not supported by Red Hat.
For users to authenticate using this identity provider, they must access https://<namespace_route>/oauth/authorize and subpaths of that endpoint through an authenticating proxy. To accomplish this, configure the OAuth server to redirect unauthenticated requests for OAuth tokens to the proxy endpoint that proxies to https://<namespace_route>/oauth/authorize.
To redirect unauthenticated requests from clients expecting browser-based login flows:
-
Set the
provider.loginURLparameter to the authenticating proxy URL that authenticates interactive clients and then proxies the request tohttps://<namespace_route>/oauth/authorize.
To redirect unauthenticated requests from clients expecting WWW-Authenticate challenges:
-
Set the
provider.challengeURLparameter to the authenticating proxy URL that authenticates clients expectingWWW-Authenticatechallenges and then proxy the request tohttps://<namespace_route>/oauth/authorize.
The provider.challengeURL and provider.loginURL parameters can include the following tokens in the query portion of the URL:
${url}is replaced with the current URL, escaped to be safe in a query parameter.For example:
https://www.example.com/sso-login?then=${url}${query}is replaced with the current query string, unescaped.For example:
https://www.example.com/auth-proxy/oauth/authorize?${query}
As of OpenShift Container Platform 4.1, your proxy must support mTLS.
7.5.2.1. Security Support Provider Interface connection support on Microsoft Windows Copy linkLink copied to clipboard!
Using Security Support Provider Interface connection support on Microsoft Windows is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
The Security Support Provider Interface (SSPI) enables the OpenShift CLI (oc) to support SSO flows on Microsoft Windows. If you use the request header identity provider with a GSSAPI-enabled proxy to connect an Active Directory server to OpenShift Container Platform, users can automatically authenticate to OpenShift Container Platform by using the oc command line interface from a domain-joined Microsoft Windows computer.
7.5.3. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.5.4. Sample request header custom resource Copy linkLink copied to clipboard!
Review the sample request header OAuth custom resource (CR) to understand provider parameters and acceptable values before you configure the identity provider in your cluster.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: requestheaderidp
mappingMethod: claim
type: RequestHeader
requestHeader:
challengeURL: "https://www.example.com/challenging-proxy/oauth/authorize?${query}"
loginURL: "https://www.example.com/login-proxy/oauth/authorize?${query}"
ca:
name: ca-config-map
clientCommonNames:
- my-auth-proxy
headers:
- X-Remote-User
- SSO-User
emailHeaders:
- X-Remote-User-Email
nameHeaders:
- X-Remote-User-Display-Name
preferredUsernameHeaders:
- X-Remote-User-Login
where:
spec.identityProviders.name- Specifies that the provider name is prefixed to the username in the request header to form an identity name.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between the identities of this provider and
Userobjects. spec.identityProviders.requestHeader.challengeURL-
Specifies the URL for redirecting unauthenticated
/oauth/authorizerequests to an authenticating proxy that authenticates browser-based clients and then proxies the request tohttps://<namespace_route>/oauth/authorize. The URL that proxies tohttps://<namespace_route>/oauth/authorizemust end with/authorizewith no trailing slash and must also proxy subpaths for OAuth approval flows to work properly.${url}is replaced with the current URL, escaped to be safe in a query parameter.${query}is replaced with the current query string. If this attribute is not defined,loginURLmust be used. This value is optional. spec.identityProviders.requestHeader.loginURL-
Specifies the URL for redirecting unauthenticated
/oauth/authorizerequests to an authenticating proxy that authenticates clients expectingWWW-Authenticatechallenges and then proxies them tohttps://<namespace_route>/oauth/authorize.${url}is replaced with the current URL, escaped to be safe in a query parameter.${query}is replaced with the current query string. If this attribute is not defined,challengeURLmust be used. This value is optional. spec.identityProviders.requestHeader.caSpecifies a reference to an OpenShift Container Platform
ConfigMapobject containing a Privacy-Enhanced Mail (PEM)-encoded certificate bundle used as a trust anchor to validate the Transport Layer Security (TLS) certificates presented by the remote server.ImportantAs of OpenShift Container Platform 4.1, the
cafield is required for this identity provider. This means that your proxy must support mutual TLS.spec.identityProviders.requestHeader.clientCommonNames-
Specifies a list of common names (
cn). If set, a valid client certificate with a Common Name (cn) in the specified list must be presented before the request headers are checked for usernames. If empty, any Common Name is allowed. Can only be used in combination withca. This value is optional. spec.identityProviders.requestHeader.headers- Specifies header names to check, in order, for the user identity. The first header containing a value is used as the identity. This field is required, and header matching is case-insensitive.
spec.identityProviders.requestHeader.emailHeaders- Specifies header names to check, in order, for an email address. The first header containing a value is used as the email address. Header matching is case-insensitive. This value is optional.
spec.identityProviders.requestHeader.nameHeaders- Specifies header names to check, in order, for a display name. The first header containing a value is used as the display name. Header matching is case-insensitive. This value is optional.
spec.identityProviders.requestHeader.preferredUsernameHeaders-
Specifies header names to check, in order, for a preferred username, if different from the immutable identity determined from the headers specified in
headers. The first header containing a value is used as the preferred username when provisioning. Header matching is case-insensitive. This value is optional.
7.5.5. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Log in to the cluster as a user from your identity provider, entering the password when prompted.
$ oc login -u <username>Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.5.6. Example Apache authentication configuration using request header Copy linkLink copied to clipboard!
Review this example to configure an Apache authentication proxy with the request header identity provider. Use this example to set up a proxy and connect it to OpenShift Container Platform.
The example configures an Apache authentication proxy for OpenShift Container Platform by using the request header identity provider.
7.5.7. Custom proxy configuration Copy linkLink copied to clipboard!
Review the requirements for a custom authentication proxy used with the request header identity provider. Meeting these requirements prevents header spoofing and ensures OAuth authorization flows work correctly.
Using the mod_auth_gssapi module is a popular way, but not required, to configure the Apache authentication proxy by using the request header identity provider. Other proxies can easily be used if the following requirements are met:
-
Blocks the
X-Remote-Userheader from client requests to prevent spoofing. -
Enforces client certificate authentication in the
RequestHeaderIdentityProviderconfiguration. -
Requires the
X-Csrf-Tokenheader be set for all authentication requests by using the challenge flow. -
Ensures only the
/oauth/authorizeendpoint and subpaths of that endpoint are proxied. Redirects must be rewritten to allow the backend server to send the client to the correct location. -
Requires the proxy URL for
https://<namespace_route>/oauth/authorizeto end with/authorizewith no trailing slash. -
Ensures subpaths of the proxy authorize URL forward to matching subpaths under
https://<namespace_route>/oauth/authorize.
The https://<namespace_route> address is the route to the OAuth server and can be obtained by running oc get route -n openshift-authentication.
7.5.8. Configure Apache authentication using the request header Copy linkLink copied to clipboard!
Configure an Apache authentication proxy with the mod_auth_gssapi module for the request header identity provider. Use this example to set up a proxy that validates users and forwards trusted identity headers to OpenShift Container Platform.
This proxy uses a client certificate to connect to the OAuth server, which is configured to trust the X-Remote-User header.
Prerequisites
-
Obtain the
mod_auth_gssapimodule from the optional channel. For more information, see "Optional channel". The following packages are installed on your local machine:
-
httpd -
mod_ssl -
mod_session -
apr-util-openssl -
mod_auth_gssapi
-
Procedure
- Generate a CA for validating requests that submit the trusted header.
Create an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map. For example:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The certificate authority must be stored in the
ca.crtkey of theConfigMapobject.Generate a client certificate for the proxy.
You can generate this certificate by using any x509 certificate tooling. The client certificate must be signed by the CA you generated for validating requests that submit the trusted header.
- Create the custom resource (CR) for your identity providers.
Create the certificate for the Apache configuration.
The certificate that you specify as the
SSLProxyMachineCertificateFileparameter value is the client certificate for the proxy that authenticates the proxy to the server. It must useTLS Web Client Authenticationas the extended key type.Create the Apache configuration. Use the following template to provide your required settings and values:
ImportantCarefully review the template and customize the template contents to fit your environment.
LoadModule request_module modules/mod_request.so LoadModule auth_gssapi_module modules/mod_auth_gssapi.so # Some Apache configurations might require these modules. # LoadModule auth_form_module modules/mod_auth_form.so # LoadModule session_module modules/mod_session.so # Nothing needs to be served over HTTP. This virtual host simply redirects to # HTTPS. <VirtualHost *:80> DocumentRoot /var/www/html RewriteEngine On RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,L] </VirtualHost> <VirtualHost *:443> # This needs to match the certificates you generated. See the CN and X509v3 # Subject Alternative Name in the output of: # openssl x509 -text -in /etc/pki/tls/certs/localhost.crt ServerName www.example.com DocumentRoot /var/www/html SSLEngine on SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key SSLCACertificateFile /etc/pki/CA/certs/ca.crt SSLProxyEngine on SSLProxyCACertificateFile /etc/pki/CA/certs/ca.crt # It is critical to enforce client certificates. Otherwise, requests can # spoof the X-Remote-User header by accessing the /oauth/authorize endpoint # directly. SSLProxyMachineCertificateFile /etc/pki/tls/certs/authproxy.pem # To use the challenging-proxy, an X-Csrf-Token must be present. RewriteCond %{REQUEST_URI} ^/challenging-proxy RewriteCond %{HTTP:X-Csrf-Token} ^$ [NC] RewriteRule ^.* - [F,L] <Location /challenging-proxy/oauth/authorize> # Insert your backend server name/ip here. ProxyPass https://<namespace_route>/oauth/authorize AuthName "SSO Login" # For Kerberos AuthType GSSAPI Require valid-user RequestHeader set X-Remote-User %{REMOTE_USER}s GssapiCredStore keytab:/etc/httpd/protected/auth-proxy.keytab # Enable the following if you want to allow users to fallback # to password based authentication when they do not have a client # configured to perform kerberos authentication. GssapiBasicAuth On # For ldap: # AuthBasicProvider ldap # AuthLDAPURL "ldap://ldap.example.com:389/ou=People,dc=my-domain,dc=com?uid?sub?(objectClass=*)" </Location> <Location /login-proxy/oauth/authorize> # Insert your backend server name/ip here. ProxyPass https://<namespace_route>/oauth/authorize AuthName "SSO Login" AuthType GSSAPI Require valid-user RequestHeader set X-Remote-User %{REMOTE_USER}s env=REMOTE_USER GssapiCredStore keytab:/etc/httpd/protected/auth-proxy.keytab # Enable the following if you want to allow users to fallback # to password based authentication when they do not have a client # configured to perform kerberos authentication. GssapiBasicAuth On ErrorDocument 401 /login.html </Location> </VirtualHost> RequestHeader unset X-Remote-UserNoteThe
https://<namespace_route>address is the route to the OAuth server and can be obtained by runningoc get route -n openshift-authentication.Update the
identityProviderssection of the custom resource (CR):identityProviders: - name: requestheaderidp type: RequestHeader requestHeader: challengeURL: "https://<namespace_route>/challenging-proxy/oauth/authorize?${query}" loginURL: "https://<namespace_route>/login-proxy/oauth/authorize?${query}" ca: name: ca-config-map clientCommonNames: - my-auth-proxy headers: - X-Remote-User
Verification
Confirm that you can bypass the proxy when you supply the correct client certificate and header by running the following command:
$ curl -L -k -H "X-Remote-User: joe" \ --cert /etc/pki/tls/certs/authproxy.pem \ https://<namespace_route>/oauth/token/requestConfirm that requests that do not supply the client certificate fail by running the following command:
$ curl -L -k -H "X-Remote-User: joe" \ https://<namespace_route>/oauth/token/requestConfirm that the
challengeURLredirect is active by running the following command:$ curl -k -v -H 'X-Csrf-Token: 1' \ https://<namespace_route>/oauth/authorize?client_id=openshift-challenging-client&response_type=tokenCopy the
challengeURLredirect to use in the next step.Show a
401response with aWWW-Authenticatebasic challenge, a negotiate challenge, or both challenges by running the following command:$ curl -k -v -H 'X-Csrf-Token: 1' \ <challengeURL_redirect + query>If you generated a Kerberos ticket by using
kinit, destroy it by running the following command:$ kdestroy -c <cache_name>Replace
<cache_name>with the name of your Kerberos cache.Log in to the OpenShift CLI (
oc) with your Kerberos credentials by running the following command:$ oc login -u <username>Enter your Kerberos username and password at the prompt.
Log out of the
octool by running the following command:$ oc logoutUse your Kerberos credentials to get a ticket by running the following command:
$ kinitEnter your Kerberos username and password at the prompt.
Confirm that you can log in to the
octool by running the following command:$ oc loginIf your configuration is correct, you are logged in without entering separate credentials.
7.6. Configuring a GitHub or GitHub Enterprise identity provider Copy linkLink copied to clipboard!
Configure the github identity provider so users can log in to OpenShift Container Platform with GitHub or GitHub Enterprise accounts through OAuth. Use this integration when you want cluster users to authenticate with existing GitHub credentials instead of managing separate cluster passwords.
You can use the GitHub integration to connect to either GitHub or GitHub Enterprise. For GitHub Enterprise integrations, you must provide the hostname of your instance and can optionally provide a ca certificate bundle to use in requests to the server.
The following steps apply to both GitHub and GitHub Enterprise unless noted.
7.6.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.6.2. About GitHub authentication Copy linkLink copied to clipboard!
Configure GitHub authentication so users can log in with GitHub or GitHub Enterprise credentials. Separate OpenShift Container Platform user accounts are not required.
To prevent anyone with any GitHub user ID from logging in to your OpenShift Container Platform cluster, you can restrict access to only those in specific GitHub organizations.
7.6.3. Register a GitHub application Copy linkLink copied to clipboard!
Register an OAuth application on GitHub or GitHub Enterprise to obtain the client ID and client secret for the identity provider configuration.
Procedure
Start the registration process by navigating to the appropriate page in GitHub or GitHub Enterprise:
-
For GitHub, click your profile picture in the upper right corner and select Settings
Developer settings OAuth Apps. -
For GitHub Enterprise, go to your GitHub Enterprise home page and then select Settings
Developer settings Register a new application.
-
For GitHub, click your profile picture in the upper right corner and select Settings
- Click New OAuth app.
-
Enter an application name, for example
My OpenShift Install. -
Enter a homepage URL, such as
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>. - Optional: Enter an application description.
Enter the authorization callback URL, where the end of the URL contains the identity provider
name:https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>For example:
https://oauth-openshift.apps.openshift-cluster.example.com/oauth2callback/github- Click Register application. GitHub provides a client ID and a client secret. You need these values to complete the identity provider configuration.
7.6.4. Create the secret Copy linkLink copied to clipboard!
Create a Secret object in the openshift-config namespace to store the client secret for your identity provider. The identity provider custom resource (CR) references this secret during configuration.
Procedure
Create a
Secretobject containing the client secret by running the following command:$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-configOptional: Apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: <secret_name> namespace: openshift-config type: Opaque data: clientSecret: <base64_encoded_client_secret>Create a
Secretobject from a file by running the following command:$ oc create secret generic <secret_name> --from-file=<path_to_file> -n openshift-config
7.6.5. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
This procedure is required only for GitHub Enterprise.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.6.6. Sample GitHub CR Copy linkLink copied to clipboard!
Review the custom resource fields and acceptable values for configuring a GitHub identity provider in OpenShift Container Platform. Use these definitions to set client credentials and access restrictions before applying the configuration to the cluster.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: githubidp
mappingMethod: claim
type: GitHub
github:
ca:
name: ca-config-map
clientID: {...}
clientSecret:
name: github-secret
hostname: ...
organizations:
- myorganization1
- myorganization2
teams:
- myorganization1/team-a
- myorganization2/team-b
where:
spec.identityProviders.name- Specifies the provider name, which is prefixed to the GitHub numeric user ID to form an identity name. It is also used to build the callback URL.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between identities from this provider and
Userobjects. spec.identityProviders.github.ca-
Specifies an optional reference to an OpenShift Container Platform
ConfigMapobject containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL. Only for use in GitHub Enterprise with a non-publicly trusted root certificate. spec.identityProviders.github.clientID-
Specifies the client ID issued when you register a GitHub OAuth application. The application must be configured with a callback URL of
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>. spec.identityProviders.github.clientSecret-
Specifies a reference to an OpenShift Container Platform
Secretobject containing the client secret issued by GitHub. spec.identityProviders.github.hostname-
Specifies the hostname of your GitHub Enterprise instance, such as
example.com. This value must match the GitHub Enterprisehostnamevalue in the/setup/settingsfile and cannot include a port number. If this value is not set, then eitherteamsororganizationsmust be defined. For GitHub, omit this parameter. spec.identityProviders.github.organizations-
Specifies the list of organizations. Either the
organizationsorteamsfield must be set unless thehostnamefield is set, or ifmappingMethodis set tolookup. Cannot be used in combination with theteamsfield. spec.identityProviders.github.teamsSpecifies the list of teams. Either the
teamsororganizationsfield must be set unless thehostnamefield is set, or ifmappingMethodis set tolookup. Cannot be used in combination with theorganizationsfield.NoteIf
organizationsorteamsis specified, only GitHub users that are members of at least one of the listed organizations are allowed to log in. If the GitHub OAuth application configured inclientIDis not owned by the organization, an organization owner must grant third-party access to use this option. This can be done during the first GitHub login by the administrator of the organization, or from the GitHub organization settings.
7.6.7. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Obtain a token from the OAuth server.
As long as the
kubeadminuser has been removed, theoc logincommand 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 by running the following command, passing in the token to authenticate:
$ oc login --token=<token>NoteThis identity provider does not support logging in with a username and password.
Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.7. Configuring a GitLab identity provider Copy linkLink copied to clipboard!
Configure the gitlab identity provider so users can log in to OpenShift Container Platform with GitLab account credentials through OAuth.
7.7.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.7.2. About GitLab authentication Copy linkLink copied to clipboard!
Review GitLab authentication options for OpenShift Container Platform. Use this integration when you want users to log in with GitLab account credentials through OAuth or OpenID Connect.
If you use GitLab version 7.7.0 to 11.0, you connect using OAuth integration. If you use GitLab version 11.1 or later, you can use OpenID Connect (OIDC) to connect instead of OAuth.
7.7.3. Create the secret Copy linkLink copied to clipboard!
Create a Secret object in the openshift-config namespace to store the client secret for your identity provider. The identity provider custom resource (CR) references this secret during configuration.
Procedure
Create a
Secretobject containing the client secret by running the following command:$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-configOptional: Apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: <secret_name> namespace: openshift-config type: Opaque data: clientSecret: <base64_encoded_client_secret>Create a
Secretobject from a file by running the following command:$ oc create secret generic <secret_name> --from-file=<path_to_file> -n openshift-config
7.7.4. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
This procedure is required only for GitHub Enterprise.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.7.5. Sample GitLab custom resource Copy linkLink copied to clipboard!
Review the sample GitLab OAuth custom resource (CR) to understand provider parameters and acceptable values before you configure the identity provider in your cluster.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: gitlabidp
mappingMethod: claim
type: GitLab
gitlab:
clientID: {...}
clientSecret:
name: gitlab-secret
url: https://gitlab.com
ca:
name: ca-config-map
where:
spec.identityProviders.name- Specifies that the provider name is prefixed to the GitLab numeric user ID to form an identity name. It is also used to build the callback URL.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between identities from this provider and
Userobjects. spec.identityProviders.gitlab.clientID-
Specifies the client ID of a registered GitLab OAuth application. The application must be configured with a callback URL of
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>. spec.identityProviders.gitlab.clientSecret-
Specifies a reference to an OpenShift Container Platform
Secretobject containing the client secret issued by GitLab. spec.identityProviders.gitlab.url-
Specifies the host URL of a GitLab provider. This could either be
https://gitlab.com/or any other self-hosted instance of GitLab. spec.identityProviders.gitlab.ca-
Specifies a reference to an OpenShift Container Platform
ConfigMapobject containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL. This value is optional.
7.7.6. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Log in to the cluster as a user from your identity provider, entering the password when prompted.
$ oc login -u <username>Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.8. Configuring a Google identity provider Copy linkLink copied to clipboard!
Configure a Google identity provider so users can authenticate to OpenShift Container Platform with Google accounts. When configured, sign-in is permitted only for Google accounts in that hosted domain.
7.8.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.8.2. Google authentication Copy linkLink copied to clipboard!
By using Google as an identity provider, you can authenticate to your server. You can use the hostedDomain configuration attribute to limit authentication to members of a specific hosted domain.
Google authentication uses OpenID Connect through the cluster OAuth server.
Using Google as an identity provider requires users to get a token using <namespace_route>/oauth/token/request to use with command-line tools.
7.8.3. Create the secret Copy linkLink copied to clipboard!
Create a Secret object in the openshift-config namespace to store the client secret for your identity provider. The identity provider custom resource (CR) references this secret during configuration.
Procedure
Create a
Secretobject containing the client secret by running the following command:$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-configOptional: Apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: <secret_name> namespace: openshift-config type: Opaque data: clientSecret: <base64_encoded_client_secret>Create a
Secretobject from a file by running the following command:$ oc create secret generic <secret_name> --from-file=<path_to_file> -n openshift-config
7.8.4. Sample Google custom resource Copy linkLink copied to clipboard!
Review the custom resource (CR) fields and acceptable values for configuring a Google identity provider in OpenShift Container Platform. Use these definitions to set client credentials and hosted domain restrictions before applying the configuration to the cluster.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: googleidp
mappingMethod: claim
type: Google
google:
clientID: {...}
clientSecret:
name: google-secret
hostedDomain: "example.com"
where:
spec.identityProviders.name- Specifies the provider name, which is prefixed to the Google numeric user ID to form an identity name. The provider name is also used to build the redirect URL.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between identities from this provider and
Userobjects. spec.identityProviders.google.clientID-
Specifies the client ID from the Google Cloud project where you create the OAuth client. The project must be configured with a redirect URI of
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>. spec.identityProviders.google.clientSecret-
Specifies a reference to an OpenShift Container Platform
Secretobject containing the client secret issued by Google. spec.identityProviders.google.hostedDomain-
Specifies a hosted domain used to restrict sign-in accounts. Optional if the
lookupmappingMethodis used. If empty, any Google account is allowed to authenticate.
7.8.5. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Obtain a token from the OAuth server.
As long as the
kubeadminuser has been removed, theoc logincommand 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 by running the following command, passing in the token to authenticate:
$ oc login --token=<token>NoteThis identity provider does not support logging in with a username and password.
Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.8.6. Additional resources Copy linkLink copied to clipboard!
7.9. Configuring an OpenID Connect identity provider Copy linkLink copied to clipboard!
To integrate OpenShift Container Platform with an external OpenID Connect (OIDC) identity provider, configure the oidc identity provider by using the Authorization Code Flow. Use this integration when your organization already uses OIDC for single sign-on.
7.9.1. Identity providers in OpenShift Container Platform Copy linkLink copied to clipboard!
You can configure identity providers by creating a custom resource (CR) that describes the provider and adding it to the cluster. Identity providers enable user authentication in OpenShift Container Platform beyond the default kubeadmin user.
OpenShift Container Platform usernames containing /, :, and % are not supported.
7.9.2. About OpenID Connect authentication Copy linkLink copied to clipboard!
Review OpenID Connect (OIDC) discovery, scopes, and claim mapping before you configure the oidc identity provider. OIDC support and correctly mapped claims are required for the Authentication Operator to authenticate users in OpenShift Container Platform.
The Authentication Operator in OpenShift Container Platform requires that the configured OIDC identity provider implements the OIDC discovery specification. For more information, see "OpenID Connect Discovery".
ID Token and UserInfo decryptions are not supported.
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 identity of the user. The standard identity claim is sub.
You can also indicate which claims to use as the preferred username, display name, and email address of the user. If multiple claims are specified, the first one with a non-empty value is used. The following table lists the standard claims:
| Claim | Description |
|---|---|
|
| Short for "subject identifier." The remote identity for the user at the issuer. |
|
|
The preferred username when provisioning a user. A shorthand name that the user wants to be referred to, such as |
|
| Email address. |
|
| Display name. |
For more information, see "OpenID claims documentation".
Unless your OpenID Connect identity provider supports the resource owner password credentials (ROPC) grant flow, users must get a token from <namespace_route>/oauth/token/request to use with command-line tools.
7.9.3. Supported OpenID Connect providers Copy linkLink copied to clipboard!
Review the OpenID Connect (OIDC) providers that Red Hat tests and supports with OpenShift Container Platform. Choose a provider from this list if you need a Red Hat-tested OIDC integration with OpenShift Container Platform.
The following OIDC providers are tested and supported with OpenShift Container Platform. Using an OIDC provider that is not on the following list might work with OpenShift Container Platform, but the provider was not tested by Red Hat and therefore is not supported by Red Hat.
Active Directory Federation Services for Windows Server
NoteCurrently, it is not supported to use Active Directory Federation Services for Windows Server with OpenShift Container Platform when custom claims are used.
- GitLab
- Keycloak
Microsoft Entra ID
NoteCurrently, it is not supported to use Microsoft Entra ID when group names are required to be synced.
- Okta
- Ping Identity
- Red Hat Single Sign-On
7.9.4. Create the secret Copy linkLink copied to clipboard!
Create a Secret object in the openshift-config namespace to store the client secret for your identity provider. The identity provider custom resource (CR) references this secret during configuration.
Procedure
Create a
Secretobject containing the client secret by running the following command:$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-configOptional: Apply the following YAML to create the secret:
apiVersion: v1 kind: Secret metadata: name: <secret_name> namespace: openshift-config type: Opaque data: clientSecret: <base64_encoded_client_secret>Create a
Secretobject from a file by running the following command:$ oc create secret generic <secret_name> --from-file=<path_to_file> -n openshift-config
7.9.5. Create a ConfigMap Copy linkLink copied to clipboard!
Create a ConfigMap object in the openshift-config namespace that contains the certificate authority bundle for the identity provider. OpenShift Container Platform uses this bundle to validate Transport Layer Security (TLS) connections to the identity provider.
This procedure is required only for GitHub Enterprise.
Procedure
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command:$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-configOptional: Apply the following YAML to create the config map:
apiVersion: v1 kind: ConfigMap metadata: name: ca-config-map namespace: openshift-config data: ca.crt: | <CA_certificate_PEM>The CA must be stored in the
ca.crtkey of theConfigMapobject.
7.9.6. Sample OpenID Connect CRs Copy linkLink copied to clipboard!
Review the sample OpenID Connect (OIDC) custom resources (CRs) before you configure the oidc identity provider. These examples show required parameters, acceptable values, and optional fields such as custom certificate bundles and extra scopes.
If you must specify a custom certificate bundle, extra scopes, extra authorization request parameters, or a userInfo URL, use the full OIDC CR.
7.9.6.1. Standard OIDC CR Copy linkLink copied to clipboard!
The following is an example of a standard OIDC CR.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: oidcidp
mappingMethod: claim
type: OpenID
openID:
clientID: ...
clientSecret:
name: idp-secret
claims:
preferredUsername:
- preferred_username
name:
- name
email:
- email
groups:
- groups
issuer: https://www.idp-issuer.com
where:
spec.identityProviders.name- Specifies that 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.
spec.identityProviders.mappingMethod-
Specifies how mappings are established between identities from this provider and
Userobjects. spec.identityProviders.openID.clientID-
Specifies 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>. spec.identityProviders.openID.clientSecret-
Specifies a reference to an OpenShift Container Platform
Secretobject containing the client secret. spec.identityProviders.openID.claims- Specifies the list of claims to use as the identity. The first non-empty claim is used.
spec.identityProviders.openID.issuer-
Specifies the Issuer Identifier described in the OpenID spec. Must use
httpswithout query or fragment component. For more information, see "Issuer Identifier".
7.9.6.2. Full OpenID CR Copy linkLink copied to clipboard!
The following is an example of a full OpenID Connect CR.
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:
name: ca-config-map
extraScopes:
- email
- profile
extraAuthorizeParameters:
include_granted_scopes: "true"
claims:
preferredUsername:
- preferred_username
- email
name:
- nickname
- given_name
- name
email:
- custom_email_claim
- email
groups:
- groups
issuer: https://www.idp-issuer.com
where:
spec.identityProviders.openID.ca- Specifies a reference to an OpenShift Container Platform config map containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL. This value is optional.
spec.identityProviders.openID.extraScopes-
Specifies the list of scopes to request, in addition to the
openidscope, during the authorization token request. This value is optional. spec.identityProviders.openID.extraAuthorizeParameters- Specifies a map of extra parameters to add to the authorization token request. This value is optional.
spec.identityProviders.openID.claims.preferredUsername- Specifies the list of claims to use as the preferred username when provisioning a user for this identity. The first non-empty claim is used.
spec.identityProviders.openID.claims.name- Specifies the list of claims to use as the display name. The first non-empty claim is used.
spec.identityProviders.openID.claims.email- Specifies the list of claims to use as the email address. The first non-empty claim is used.
spec.identityProviders.openID.claims.groups- Specifies the list of claims to use to synchronize groups from the OpenID Connect provider to OpenShift Container Platform upon user login. The first non-empty claim is used.
7.9.7. Add an identity provider to your cluster Copy linkLink copied to clipboard!
Apply the identity provider custom resource (CR) to your cluster after you define it. With this configuration, you can authenticate with the configured identity provider.
Prerequisites
- You have access to a OpenShift Container Platform cluster.
- You have created the CR for your identity providers.
- You are logged in as an administrator.
Procedure
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>NoteIf a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning.Obtain a token from the OAuth server.
As long as the
kubeadminuser has been removed, theoc logincommand 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 by running the following command, passing in the token to authenticate:
$ oc login --token=<token>NoteIf your OpenID Connect identity provider supports the resource owner password credentials (ROPC) grant flow, you can log in with a username and password. You might need to take steps to enable the ROPC grant flow for your identity provider.
After the OIDC identity provider is configured in OpenShift Container Platform, log in by running the following command. The command prompts you for your username and password:
$ oc login -u <identity_provider_username> --server=<api_server_url_and_port>If your OpenID Connect identity provider supports the resource owner password credentials (ROPC) grant flow, you might need to take steps to enable the ROPC grant flow for your identity provider.
Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami
7.9.8. Configure identity providers using the web console Copy linkLink copied to clipboard!
You can configure identity providers on your OpenShift Container Platform cluster through the web console by updating the OAuth settings in the Cluster Settings.
Prerequisites
- You are logged in to the web console as a cluster administrator.
Procedure
-
Navigate to Administration
Cluster Settings. - Under the Configuration tab, click OAuth.
Under the Identity Providers section, select your identity provider from the Add drop-down list.
NoteYou can specify multiple identity providers through the web console without overwriting existing identity providers.