Chapter 7. Configuring identity providers


7.1. Configuring an htpasswd identity provider

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:

  1. Create an htpasswd file to store the user and password information.
  2. Create a secret to represent the htpasswd file.
  3. Define an htpasswd identity provider resource that references the secret.
  4. Apply the resource to the default OAuth configuration to add the identity provider.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.1.2. About htpasswd authentication

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.

Warning

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

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 htpasswd file using Linux
  • Creating an htpasswd file using Windows

7.1.3.1. Create an htpasswd file using Linux

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 htpasswd utility. On Red Hat Enterprise Linux (RHEL), this is available by installing the httpd-tools package.

Procedure

  1. Create or update your htpasswd file 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 user1

  2. Continue 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

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.exe utility. On Windows, this utility is included in the \bin subdirectory of many Apache httpd distributions.

Procedure

  1. Create or update your htpasswd file 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 user1

  2. Continue 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

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 htpasswd file.

Procedure

  • Create a Secret object that contains the htpasswd users file by running the following command:

    $ oc create secret generic htpass-secret --from-file=htpasswd=<path_to_users.htpasswd> -n openshift-config

    The --from-file key must be named htpasswd.

    Tip

    You 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

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 User objects.
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

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

    $ oc login -u <username>
  3. Confirm that the user logged in successfully and that the username displays by running the following command:

    $ oc whoami

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 Secret object named htpass-secret that contains the htpasswd user file.
  • You have configured an htpasswd identity provider named my_htpasswd_provider.
  • You have access to the htpasswd utility. On Red Hat Enterprise Linux (RHEL), this is available by installing the httpd-tools package.
  • You have cluster administrator privileges.

Procedure

  1. Retrieve the htpasswd file from the htpass-secret Secret object 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.htpasswd
  2. Add or remove users from the users.htpasswd file by running the following commands:

    1. To add a new user:

      $ htpasswd -bB users.htpasswd <username> <password>

      Example output

      Adding password for user <username>

    2. To remove an existing user:

      $ htpasswd -D users.htpasswd <username>

      Example output

      Deleting password for user <username>

  3. Replace the htpass-secret Secret object with the updated users in the users.htpasswd file 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 -
    Tip

    You 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>
  4. If you removed one or more users, you must remove the existing resources for each user by running the following commands:

    1. Delete the User object:

      $ oc delete user <username>

      Example output

      user.user.openshift.io "<username>" deleted

      Be sure to remove the user, otherwise the user can continue using their token as long as it has not expired.

    2. Delete the Identity object for the user:

      $ oc delete identity my_htpasswd_provider:<username>

      Example output

      identity.user.openshift.io "my_htpasswd_provider:<username>" deleted

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

  1. Navigate to Administration Cluster Settings.
  2. Under the Configuration tab, click OAuth.
  3. Under the Identity Providers section, select your identity provider from the Add drop-down list.

    Note

    You can specify multiple identity providers through the web console without overwriting existing identity providers.

7.2. Configuring a Keystone identity provider

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.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.2.2. About Keystone authentication

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

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

  1. Create a Secret object 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-config
  2. Optional: 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

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

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.2.5. Sample Keystone custom resource

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 User objects.
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 ConfigMap object 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 Secret object 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 Secret object containing the key for the client certificate. Required if tlsClientCert is specified.

7.2.6. Add an identity provider to your cluster

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

    $ oc login -u <username>
  3. 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

Configure an LDAP identity provider so users can log in to OpenShift Container Platform with usernames and passwords validated against your LDAPv3 directory.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.3.2. About LDAP authentication

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:

  1. Generates a search filter by combining the attribute and filter in the configured url with the user-provided username.
  2. Searches the directory using the generated filter. Denies access if the search does not return exactly one entry.
  3. Attempts to bind to the LDAP server using the DN of the entry retrieved from the search, and the user-provided password.
  4. Denies access if the bind is unsuccessful.
  5. 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 componentDescription

ldap

For regular LDAP, use the string ldap. For secure LDAP (LDAPS), use ldaps instead.

host:port

The name and port of the LDAP server. Defaults to localhost:389 for LDAP and localhost:636 for LDAPS.

basedn

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.

attribute

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 uid. It is recommended to choose an attribute that is unique across all entries in the subtree you are using.

scope

The scope of the search. Can be either one or sub. If the scope is not provided, the default is to use a scope of sub.

filter

A valid LDAP search filter. If not provided, defaults to (objectClass=*)

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

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 Secret object that contains the bindPassword field by running the following command:

    $ oc create secret generic ldap-secret --from-literal=bindPassword=<secret> -n openshift-config

    where:

    <secret>
    Specifies the LDAP bind password value for the --from-literal argument. The key name must be bindPassword.
  • 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

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

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.3.5. Sample LDAP custom resource

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 User objects.
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 bindPassword is defined.
spec.identityProviders.ldap.bindPassword
Specifies an optional reference to an OpenShift Container Platform Secret object containing the bind password. Must be set if bindDN is defined.
spec.identityProviders.ldap.ca
Specifies an optional reference to an OpenShift Container Platform ConfigMap object containing the Privacy-Enhanced Mail (PEM)-encoded certificate authority bundle to use in validating server certificates for the configured URL. Only used when insecure is false.
spec.identityProviders.ldap.insecure
Specifies whether a TLS connection is made to the server. When true, no TLS connection is made to the server. When false, ldaps:// URLs connect using TLS, and ldap:// URLs are upgraded to TLS. This must be set to false when ldaps:// 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.
Note

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

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

    $ oc login -u <username>
  3. Confirm that the user logged in successfully and that the username displays by running the following command:

    $ oc whoami

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.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.4.2. About basic authentication

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.

Important

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.

Note

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 name key. For example:

    {"sub":"userid", "name": "User Name", ...}
  • An email address using the email key. For example:

    {"sub":"userid", "email":"user@example.com", ...}
  • A preferred username using the preferred_username key. 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

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

  1. Create a Secret object 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-config
  2. Optional: 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

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

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.4.5. Sample basic authentication custom resource

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 User objects.
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 ConfigMap object 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 Secret object 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 Secret object containing the key for the client certificate. Required if tlsClientCert is specified.

7.4.6. Add an identity provider to your cluster

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

    $ oc login -u <username>
  3. Confirm that the user logged in successfully and that the username displays by running the following command:

    $ oc whoami

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

These are the requirements for the files you create on an Apache HTTPD web server:

  • The login.cgi and fail.cgi CGI script files must be executable. Use the chmod +x command on both files.
  • If SELinux is enabled, the login.cgi and fail.cgi CGI script files must have proper SELinux security contexts. Run the restorecon -RFv /var/www/cgi-bin command, or ensure that the context is the httpd_sys_script_exec_t SELinux type by using the ls -laZ command.
  • The login.cgi CGI script file runs only when the user successfully logs in according to the Require and Auth Apache configuration directives.
  • The fail.cgi CGI script file runs when the user fails to log in and returns an HTTP 401 HTTP status code.

7.4.8. Troubleshoot basic authentication

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

  1. 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-idp
  2. Review successful login responses.

    A 200 status with a sub (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 name key:

      {"sub":"userid", "name": "User Name", ...}
    • An email address using the email key:

      {"sub":"userid", "email":"user@example.com", ...}
    • A preferred username using the preferred_username key:

      {"sub":"014fbff9a07c", "preferred_username":"bob", ...}

    The preferred_username key 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.

  3. Review failed login responses.

    • 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"}

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.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.5.2. About request header authentication

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.

Note

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.loginURL parameter to the authenticating proxy URL that authenticates interactive clients and then proxies the request to https://<namespace_route>/oauth/authorize.

To redirect unauthenticated requests from clients expecting WWW-Authenticate challenges:

  • Set the provider.challengeURL parameter to the authenticating proxy URL that authenticates clients expecting WWW-Authenticate challenges and then proxy the request to https://<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}

Important

As of OpenShift Container Platform 4.1, your proxy must support mTLS.

Important

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

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

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.5.4. Sample request header custom resource

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 User objects.
spec.identityProviders.requestHeader.challengeURL
Specifies the URL for redirecting unauthenticated /oauth/authorize requests to an authenticating proxy that authenticates browser-based clients and then proxies the request to https://<namespace_route>/oauth/authorize. The URL that proxies to https://<namespace_route>/oauth/authorize must end with /authorize with 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, loginURL must be used. This value is optional.
spec.identityProviders.requestHeader.loginURL
Specifies the URL for redirecting unauthenticated /oauth/authorize requests to an authenticating proxy that authenticates clients expecting WWW-Authenticate challenges and then proxies them to https://<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, challengeURL must be used. This value is optional.
spec.identityProviders.requestHeader.ca

Specifies a reference to an OpenShift Container Platform ConfigMap object 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.

Important

As of OpenShift Container Platform 4.1, the ca field 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 with ca. 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

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

    $ oc login -u <username>
  3. Confirm that the user logged in successfully and that the username displays by running the following command:

    $ oc whoami

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

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-User header from client requests to prevent spoofing.
  • Enforces client certificate authentication in the RequestHeaderIdentityProvider configuration.
  • Requires the X-Csrf-Token header be set for all authentication requests by using the challenge flow.
  • Ensures only the /oauth/authorize endpoint 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/authorize to end with /authorize with no trailing slash.
  • Ensures subpaths of the proxy authorize URL forward to matching subpaths under https://<namespace_route>/oauth/authorize.
Note

The https://<namespace_route> address is the route to the OAuth server and can be obtained by running oc get route -n openshift-authentication.

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_gssapi module 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

  1. Generate a CA for validating requests that submit the trusted header.
  2. Create an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  3. Optional: 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.crt key of the ConfigMap object.

  4. 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.

  5. Create the custom resource (CR) for your identity providers.
  6. Create the certificate for the Apache configuration.

    The certificate that you specify as the SSLProxyMachineCertificateFile parameter value is the client certificate for the proxy that authenticates the proxy to the server. It must use TLS Web Client Authentication as the extended key type.

  7. Create the Apache configuration. Use the following template to provide your required settings and values:

    Important

    Carefully 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-User
    Note

    The https://<namespace_route> address is the route to the OAuth server and can be obtained by running oc get route -n openshift-authentication.

  8. Update the identityProviders section 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

  1. 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/request
  2. Confirm 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/request
  3. Confirm that the challengeURL redirect 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=token

    Copy the challengeURL redirect to use in the next step.

  4. Show a 401 response with a WWW-Authenticate basic challenge, a negotiate challenge, or both challenges by running the following command:

    $ curl -k -v -H 'X-Csrf-Token: 1' \
       <challengeURL_redirect + query>
  5. 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.

  6. 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.

  7. Log out of the oc tool by running the following command:

    $ oc logout
  8. Use your Kerberos credentials to get a ticket by running the following command:

    $ kinit

    Enter your Kerberos username and password at the prompt.

  9. Confirm that you can log in to the oc tool by running the following command:

    $ oc login

    If your configuration is correct, you are logged in without entering separate credentials.

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.

Note

The following steps apply to both GitHub and GitHub Enterprise unless noted.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.6.2. About GitHub authentication

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

Register an OAuth application on GitHub or GitHub Enterprise to obtain the client ID and client secret for the identity provider configuration.

Procedure

  1. 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.
  2. Click New OAuth app.
  3. Enter an application name, for example My OpenShift Install.
  4. Enter a homepage URL, such as https://oauth-openshift.apps.<cluster-name>.<cluster-domain>.
  5. Optional: Enter an application description.
  6. 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
  7. 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

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

  1. Create a Secret object containing the client secret by running the following command:

    $ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
  2. Optional: 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>
  3. Create a Secret object 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

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.

Note

This procedure is required only for GitHub Enterprise.

Procedure

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.6.6. Sample GitHub CR

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 User objects.
spec.identityProviders.github.ca
Specifies an optional reference to an OpenShift Container Platform ConfigMap object 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 Secret object 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 Enterprise hostname value in the /setup/settings file and cannot include a port number. If this value is not set, then either teams or organizations must be defined. For GitHub, omit this parameter.
spec.identityProviders.github.organizations
Specifies the list of organizations. Either the organizations or teams field must be set unless the hostname field is set, or if mappingMethod is set to lookup. Cannot be used in combination with the teams field.
spec.identityProviders.github.teams

Specifies the list of teams. Either the teams or organizations field must be set unless the hostname field is set, or if mappingMethod is set to lookup. Cannot be used in combination with the organizations field.

Note

If organizations or teams is 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 in clientID is 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

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. 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.

  3. Log in to the cluster by running the following command, passing in the token to authenticate:

    $ oc login --token=<token>
    Note

    This identity provider does not support logging in with a username and password.

  4. 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

Configure the gitlab identity provider so users can log in to OpenShift Container Platform with GitLab account credentials through OAuth.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.7.2. About GitLab authentication

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

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

  1. Create a Secret object containing the client secret by running the following command:

    $ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
  2. Optional: 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>
  3. Create a Secret object 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

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.

Note

This procedure is required only for GitHub Enterprise.

Procedure

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.7.5. Sample GitLab custom resource

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 User objects.
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 Secret object 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 ConfigMap object 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

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

    $ oc login -u <username>
  3. 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

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.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.8.2. Google authentication

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.

Note

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

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

  1. Create a Secret object containing the client secret by running the following command:

    $ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
  2. Optional: 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>
  3. Create a Secret object 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

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 User objects.
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 Secret object containing the client secret issued by Google.
spec.identityProviders.google.hostedDomain
Specifies a hosted domain used to restrict sign-in accounts. Optional if the lookup mappingMethod is used. If empty, any Google account is allowed to authenticate.

7.8.5. Add an identity provider to your cluster

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. 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.

  3. Log in to the cluster by running the following command, passing in the token to authenticate:

    $ oc login --token=<token>
    Note

    This identity provider does not support logging in with a username and password.

  4. Confirm that the user logged in successfully and that the username displays by running the following command:

    $ oc whoami

7.8.6. Additional resources

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.

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.

Note

OpenShift Container Platform usernames containing /, :, and % are not supported.

7.9.2. About OpenID Connect authentication

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".

Note

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:

ClaimDescription

sub

Short for "subject identifier." The remote identity for the user at the issuer.

preferred_username

The preferred username when provisioning a user. A shorthand name that the user wants to be referred to, such as janedoe. Typically a value that corresponds to the login or username of the user in the authentication system, such as username or email.

email

Email address.

name

Display name.

For more information, see "OpenID claims documentation".

Note

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

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

    Note

    Currently, it is not supported to use Active Directory Federation Services for Windows Server with OpenShift Container Platform when custom claims are used.

  • GitLab
  • Google
  • Keycloak
  • Microsoft Entra ID

    Note

    Currently, 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

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

  1. Create a Secret object containing the client secret by running the following command:

    $ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
  2. Optional: 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>
  3. Create a Secret object 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

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.

Note

This procedure is required only for GitHub Enterprise.

Procedure

  1. Define an OpenShift Container Platform ConfigMap object containing the CA by running the following command:

    $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
  2. Optional: 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.crt key of the ConfigMap object.

7.9.6. Sample OpenID Connect CRs

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

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 User objects.
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 Secret object 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 https without query or fragment component. For more information, see "Issuer Identifier".

7.9.6.2. Full OpenID CR

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 openid scope, 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

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

  1. Apply the defined CR by running the following command:

    $ oc apply -f </path/to/CR>
    Note

    If a CR does not exist, oc apply creates 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.

  2. 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.

  3. Log in to the cluster by running the following command, passing in the token to authenticate:

    $ oc login --token=<token>
    Note

    If 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.

  4. 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.

  5. Confirm that the user logged in successfully and that the username displays by running the following command:

    $ oc whoami

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

  1. Navigate to Administration Cluster Settings.
  2. Under the Configuration tab, click OAuth.
  3. Under the Identity Providers section, select your identity provider from the Add drop-down list.

    Note

    You can specify multiple identity providers through the web console without overwriting existing identity providers.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top