Configuring a GitHub or GitHub Enterprise identity provider¶
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.
Identity providers in 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.
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.
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
-
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.
-
Click New OAuth app.
-
Enter an application name, for example
My OpenShift Install. -
Enter a homepage URL, such as
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>. -
Optional: Enter an application description.
-
Enter the authorization callback URL, where the end of the URL contains the identity provider
name:For example:
-
Click Register application. GitHub provides a client ID and a client secret. You need these values to complete the identity provider configuration.
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
-
Create a
Secretobject containing the client secret by running the following command: -
Optional: Apply the following YAML to create the secret:
-
Create a
Secretobject from a file by running the following command:
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
-
Define an OpenShift Container Platform
ConfigMapobject containing the CA by running the following command: -
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.crtkey of theConfigMapobject.
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
Userobjects. spec.identityProviders.github.ca- Specifies an optional reference to an OpenShift Container Platform
ConfigMapobject containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL. Only for use in GitHub Enterprise with a non-publicly trusted root certificate. spec.identityProviders.github.clientID- Specifies the client ID issued when you register a GitHub OAuth application. The application must be configured with a callback URL of
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>. spec.identityProviders.github.clientSecret- Specifies a reference to an OpenShift Container Platform
Secretobject containing the client secret issued by GitHub. spec.identityProviders.github.hostname- Specifies the hostname of your GitHub Enterprise instance, such as
example.com. This value must match the GitHub Enterprisehostnamevalue in the/setup/settingsfile and cannot include a port number. If this value is not set, then eitherteamsororganizationsmust be defined. For GitHub, omit this parameter. spec.identityProviders.github.organizations- Specifies the list of organizations. Either the
organizationsorteamsfield must be set unless thehostnamefield is set, or ifmappingMethodis set tolookup. Cannot be used in combination with theteamsfield. spec.identityProviders.github.teams-
Specifies the list of teams. Either the
teamsororganizationsfield must be set unless thehostnamefield is set, or ifmappingMethodis set tolookup. Cannot be used in combination with theorganizationsfield.Note
If
organizationsorteamsis specified, only GitHub users that are members of at least one of the listed organizations are allowed to log in. If the GitHub OAuth application configured inclientIDis not owned by the organization, an organization owner must grant third-party access to use this option. This can be done during the first GitHub login by the administrator of the organization, or from the GitHub organization settings.
Additional resources
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
-
Apply the defined CR by running the following command:
Note
If a CR does not exist,
oc applycreates a new CR and might trigger the following warning:Warning: oc apply should be used on resources created by either oc create --save-config or oc apply. In this case you can safely ignore this warning. -
Obtain a token from the OAuth server.
As long as the
kubeadminuser has been removed, theoc logincommand provides instructions on how to access a web page where you can retrieve the token.You can also access this page from the web console by navigating to (?) Help → Command Line Tools → Copy Login Command.
-
Log in to the cluster by running the following command, passing in the token to authenticate:
Note
This identity provider does not support logging in with a username and password.
-
Confirm that the user logged in successfully and that the username displays by running the following command:
Additional resources