Configuring an external OIDC identity provider for direct authentication
Configure Red Hat OpenShift Container Platform to use an external OIDC identity provider for direct authentication, enabling users to log in with existing corporate credentials while bypassing the built-in OAuth server for streamlined single sign-on.
-
You have configured your external authentication provider.
This procedure uses Keycloak as the identity provider and assumes that you have the following clients configured:
-
A confidential client for the web console called
console-testwith the valid redirect URIs set tohttps://<openshift_console_route>/auth/callback -
A public client for the OpenShift CLI (
oc) calledoc-cli-testwith the valid redirect URIs set tohttp://localhost:8080
-
-
You have access to the
kubeconfigfile generated by the installation program for the cluster. -
You have backed up any existing authentication configuration, in case you need to revert back to using the built-in OAuth server for authentication.
-
You have the Red Hat OpenShift Container Platform web console enabled on the cluster.
If the web console is not enabled in your cluster, see "Example OIDC provider configuration for CLI clients only" for an example configuration without the web console client.
-
Ensure that you are using the
kubeconfigfile generated by the installation program, or another long-lived method of logging in as a cluster administrator. -
Create a secret that allows you to authenticate with the web console by running the following command:
$ oc create secret generic console-secret \ --from-literal=clientSecret=<secret_value> \// -n openshift-configReplace
<secret_value>with the value of the secret for theconsole-testclient in your identity provider. -
Optional: Create a config map that contains the provider’s certificate authority bundle by running the following command:
$ oc create configmap keycloak-oidc-ca --from-file=ca-bundle.crt=my-directory/ca-bundle.crt \ -n openshift-configSpecify the path to your provider’s
ca-bundle.crtfile. -
Edit the authentication configuration by running the following command:
$ oc edit authentication.config/cluster -
Update the authentication configuration by setting the
typefield toOIDC, configuring theoidcProvidersfield for your provider, and setting thewebhookTokenAuthenticatorfield tonull:apiVersion: config.openshift.io/v1 kind: Authentication metadata: # ... spec: type: OIDC webhookTokenAuthenticator: null oidcProviders: - claimMappings: extra: - key: example.com/role valueExpression: claims.?role.orValue("unknown") groups: claim: groups prefix: 'oidc-groups-test:' uid: claim: "sub" username: claim: email prefixPolicy: Prefix prefix: prefixString: 'oidc-user-test:' issuer: audiences: - console-test - oc-cli-test issuerCertificateAuthority: name: keycloak-oidc-ca issuerURL: https://keycloak-keycloak.apps.example.com/realms/master name: 'keycloak-oidc-server' oidcClients: - clientID: oc-cli-test componentName: cli componentNamespace: openshift-console - clientID: console-test clientSecret: name: console-secret componentName: console componentNamespace: openshift-console extraScopes: - email - profilewhere:
spec.type-
Specifies the authentication type. Must be set to
OIDCto indicate to use an external OIDC identity provider. spec.webhookTokenAuthenticator-
Specifies the webhook token authenticator configuration. Must be set to
nullwhentypeis set toOIDC. spec.oidcProviders-
Specifies the OIDC provider configuration. Currently, only one OIDC provider configuration is allowed.
spec.oidcProviders.claimMappings.extra-
Specifies the mappings used to construct the extra attributes for the cluster identity. This field is optional.
spec.oidcProviders.claimMappings.groups.claim-
Specifies the name of the claim to construct group names for the cluster identity.
spec.oidcProviders.claimMappings.uid-
Specifies the claim mapping used to construct the UID for the cluster identity. This field is optional.
spec.oidcProviders.claimMappings.username.claim-
Specifies the name of the claim to construct usernames for the cluster identity.
spec.oidcProviders.issuer.audiences-
Specifies the list of audiences that this authentication provider issues tokens for.
spec.oidcProviders.issuer.issuerCertificateAuthority.name-
Specifies the name of the config map that contains the
ca-bundle.crtkey. If unset, system trust is used instead. spec.oidcProviders.issuer.issuerURL-
Specifies the URL for the token issuer.
spec.oidcProviders.name-
Specifies the name for external OIDC provider.
spec.oidcProviders.oidcClients.clientID-
Specifies the client ID that your provider uses. Configure separate entries for the OpenShift CLI (
oc) and the Red Hat OpenShift Container Platform web console. spec.oidcProviders.oidcClients.clientSecret.name-
Specifies the name of the secret that stores the secret value for the console client.
spec.oidcProviders.oidcClients.extraScopes-
Specifies the extra scopes to request. Some providers, such as GitLab, might require extra scopes in order to log in through the web console properly.
-
Exit and save the changes to apply the new configuration.
-
Wait for the cluster to roll out new revisions to all nodes.
-
Check the Kubernetes API server Operator status by running the following command:
$ oc get co kube-apiserverExample outputNAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE kube-apiserver 4.22.0 True True False 85m NodeInstallerProgressing: 2 node are at revision 8; 1 node is at revision 10The message in the preceding example shows that one node has progressed to the new revision and two nodes have not yet updated. It can take 20 minutes or more to roll out the new revision to all nodes, depending on the size of your cluster.
-
To troubleshoot any issues, you can also check the Cluster Authentication Operator and
kube-apiserverpod logs for errors.
-
-
Verify that you can log in to the OpenShift CLI (
oc) by authenticating with your identity provider:-
Log in by running the following command:
$ oc login --exec-plugin=oc-oidc \ --issuer-url=https://keycloak-keycloak.apps.example.com/realms/master \ --client-id=oc-cli-test \ --extra-scopes=email --callback-port=8080 \ --oidc-certificate-authority my-directory/ca-bundle.crtwhere:
--exec-plugin-
Specifies the exec plugin type. Only a value of
oc-oidcis allowed. --issuer-url-
Specifies the issuer URL for your identity provider.
--client-id-
Specifies the client ID for the OpenShift CLI (
oc). --oidc-certificate-authority-
Specifies the path to the
ca-bundle.crtfile on your local machine.Example outputPlease visit the following URL in your browser: http://localhost:8080
-
Open http://localhost:8080 in a browser.
-
Authenticate with credentials from your identity provider.
After successfully authenticating, you should see a message similar to the following output in your terminal:
Logged into "https://api.my-cluster.example.com:6443" as "oidc-user-test:user1@example.com" from an external oidc issuer.
-
-
Verify that you can log in to the Red Hat OpenShift Container Platform web console by authenticating with your identity provider:
-
Open the web console URL for your cluster in a browser.
You are redirected to your identity provider to log in.
-
Authenticate with credentials from your identity provider.
Verify that you logged in successfully and are redirected to the Red Hat OpenShift Container Platform web console.
-
OIDC provider configuration parameters
Configure OIDC providers for external authentication by using these parameters to map JWT token claims to cluster identities, validate authentication tokens, and enable platform components to authenticate with identity providers.
The following table lists all available OIDC provider parameters for direct authentication:
| Parameter | Description |
|---|---|
|
Configures the rules to be used by the Kubernetes API server for translating claims in a JSON web token (JWT), issued by the identity provider, to a cluster identity. |
|
An optional field for configuring the mappings used to construct the extra attribute for the cluster identity. When omitted, no extra attributes will be present on the cluster identity. Key values for extra mappings must be unique. A maximum of 32 extra attribute mappings can be provided. |
|
A required field that specifies the string to use as the extra attribute key. The following restrictions apply:
|
|
A required field to specify the CEL expression to extract the extra attribute value from claims of a JWT token. The
|
|
Configures how the groups of a cluster identity should be constructed from the claims in a JWT token issued by the identity provider. When referencing a claim, if the claim is present in the JWT token, its value must be a comma-separated list of groups. |
|
Optional parameter. JWT token claim used for groups mapping. Set either |
|
Optional parameter (Technology Preview). CEL expression that produces a string or string array from JWT token claims. Access claims by using the Set either |
|
Configures the prefix that is applied to the cluster identity attribute during the process of mapping JWT claims to cluster identity attributes. |
|
An optional field for configuring the claim mapping used to construct the UID for the cluster identity. When omitted, this means the user has no opinion and the platform is left to choose a default, which is subject to change over time. The current default is to use the |
|
An optional field for specifying the JWT token claim that is used in the mapping. The value of this claim will be assigned to the field in which this mapping is associated. To specify the claim, use a single string value for You must set either |
|
An optional field for specifying a CEL expression that produces a string value from JWT token claims. When using CEL expressions have access to the token claims through a CEL variable, You must set either |
|
Configures how the username of a cluster identity should be constructed from the claims in a JWT token issued by the identity provider. |
|
Optional parameter. JWT token claim used for username mapping. Set either |
|
Optional parameter (Technology Preview). CEL expression that produces a string value from JWT token claims. Must result in a single string. Access claims by using the Set either |
|
Configures the prefix that should be prepended to the value of the JWT claim. Must be set when |
|
Configures the prefix that is applied to the cluster identity username attribute during the process of mapping JWT claims to cluster identity attributes. Must not be an empty string ( |
|
Configures how a prefix should be applied to the value of the JWT claim specified in the When set to When set to When omitted, this means no opinion and the platform is left to choose any prefixes that are applied which is subject to change over time. Currently, the platform prepends |
|
Configures the rules to be used by the Kubernetes API server for validating the claims in a JWT token issued by the identity provider. Validation rules are joined by an |
|
Optional parameter (Technology Preview). Required when |
|
Technology Preview. CEL expression that validates token claims. Must evaluate to Access claims by using the Constraints: 1-1024 characters. |
|
Technology Preview. Error message displayed when validation fails. Constraints: 1-256 characters. |
|
Configures the required claim and value that the Kubernetes API server uses to validate if an incoming JWT is valid for this identity provider. Required when |
|
Configures the name of the required claim. When taken from the JWT claims, the claim must be a string value. Must not be an empty string ( |
|
Configures the value that |
|
Validation rule type. Allowed values:
|
|
A required field that configures how the platform interacts with the identity provider and how tokens issued from the identity provider are evaluated by the Kubernetes API server. |
|
A required field that configures the acceptable audiences the JWT token, issued by the identity provider, must be issued to. At least one of the entries must match the |
|
Optional parameter (Technology Preview). Custom OIDC discovery endpoint URL. Must be a valid HTTPS URL and differ from When not specified, Red Hat OpenShift Container Platform constructs the discovery URL by using the standard OIDC format: |
|
Configures the certificate authority, used by the Kubernetes API server, to validate the connection to the identity provider when fetching discovery information. When not specified, the system trust is used. When specified, it must reference a config map in the |
|
The name of the referenced config map. |
|
Configures the URL used to issue tokens by the identity provider. The Kubernetes API server determines how authentication tokens should be handled by matching the |
|
A required field that configures the unique human-readable identifier associated with the identity provider. It is used to distinguish between multiple identity providers and has no impact on token validation or authentication mechanics. Must not be an empty string ( |
|
Configures how on-cluster, platform clients should request tokens from the identity provider. Must not exceed 20 entries and entries must have unique namespace/name pairs. |
|
Configures the client identifier, from the identity provider, that the platform component uses for authentication requests made to the identity provider. The identity provider must accept this identifier for platform components to be able to use the identity provider as an authentication mode. Must not be an empty string ( |
|
Configures the client secret used by the platform component when making authentication requests to the identity provider. When not specified, no client secret is used when making authentication requests to the identity provider. When specified, it references a secret in the Public clients do not require a client secret, but private clients do require a client secret to work with the identity provider. |
|
The name of the referenced secret. |
|
Specifies the name of the platform component being configured to use the identity provider as an authentication mode. It is used in combination with |
|
Specifies the namespace in which the platform component being configured to use the identity provider as an authentication mode is running. It is used in combination with |
|
Configures the extra scopes that should be requested by the platform component when making authentication requests to the identity provider. This is useful if you have configured claim mappings that require specific scopes to be requested beyond the standard OIDC scopes. When omitted, no additional scopes are requested. |
|
Optional parameter (Technology Preview). Validation rules for user objects created from authenticated tokens. All rules must pass (AND operation). Each rule contains Access user by using the |
|
Required. CEL expression that validates the user object. Must evaluate to |
|
Required. Error message displayed when validation fails. |
Example OIDC provider configuration for CLI clients only
In Red Hat OpenShift Container Platform clusters where the web console is disabled, you can configure direct authentication with an external OIDC provider for a CLI client only. In these cases, users must authenticate with the cluster directly through the OpenShift CLI (oc) instead of through the web console.
The following example OIDC provider configuration shows how to configure a CLI client without defining a web console client:
apiVersion: config.openshift.io/v1
kind: Authentication
metadata:
# ...
spec:
type: OIDC
webhookTokenAuthenticator: null
oidcProviders:
- claimMappings:
groups:
claim: groups
prefix: 'oidc-groups-test:'
username:
claim: email
prefixPolicy: Prefix
prefix:
prefixString: 'oidc-user-test:'
issuer:
audiences:
- my-cli-client-id
issuerURL: my-issuer-url
name: my-oidc-provider-name