This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.4.6. Configuring a GitHub or GitHub Enterprise identity provider
Configure a github
identity provider to validate user names and passwords against GitHub or GitHub Enterprise’s OAuth authentication server. OAuth facilitates a token exchange flow between OpenShift Container Platform and GitHub or GitHub Enterprise.
You can use the GitHub integration to connect to either GitHub or GitHub Enterprise. For GitHub Enterprise integrations, you must provide the hostname
of your instance and can optionally provide a ca
certificate bundle to use in requests to the server.
The following steps apply to both GitHub and GitHub Enterprise unless noted.
Configuring GitHub authentication allows users to log in to OpenShift Container Platform with their GitHub credentials. 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.
By default, only a kubeadmin
user exists on your cluster. To specify an identity provider, you must create a custom resource (CR) that describes that identity provider and add it to the cluster.
OpenShift Container Platform user names containing /
, :
, and %
are not supported.
4.6.2. Registering a GitHub application 复制链接链接已复制到粘贴板!
To use GitHub or GitHub Enterprise as an identity provider, you must register an application to use.
Procedure
Register an application on GitHub:
-
For GitHub, click Settings
Developer settings OAuth Apps Register a new OAuth application. -
For GitHub Enterprise, go to your GitHub Enterprise home page and then click Settings
Developer settings Register a new application.
-
For GitHub, click Settings
-
Enter an application name, for example
My OpenShift Install
. -
Enter a homepage URL, such as
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>
. - Optional: Enter an application description.
Enter the authorization callback URL, where the end of the URL contains the identity provider
name
:https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
https://oauth-openshift.apps.example-openshift-cluster.com/oauth2callback/github/
https://oauth-openshift.apps.example-openshift-cluster.com/oauth2callback/github/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Register application. GitHub provides a client ID and a client secret. You need these values to complete the identity provider configuration.
4.6.3. Creating the secret 复制链接链接已复制到粘贴板!
Identity providers use OpenShift Container Platform Secret
objects in the openshift-config
namespace to contain the client secret, client certificates, and keys.
You can define an OpenShift Container Platform
Secret
object containing a string by using the following command.oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can define an OpenShift Container Platform
Secret
object containing the contents of a file, such as a certificate file, by using the following command.oc create secret generic <secret_name> --from-file=/path/to/file -n openshift-config
$ oc create secret generic <secret_name> --from-file=/path/to/file -n openshift-config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.6.4. Creating a config map 复制链接链接已复制到粘贴板!
Identity providers use OpenShift Container Platform ConfigMap
objects in the openshift-config
namespace to contain the certificate authority bundle. These are primarily used to contain certificate bundles needed by the identity provider.
This procedure is only required for GitHub Enterprise.
Procedure
Define an OpenShift Container Platform
ConfigMap
object containing the certificate authority by using the following command. The certificate authority must be stored in theca.crt
key of theConfigMap
object.oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
$ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.6.5. Sample GitHub CR 复制链接链接已复制到粘贴板!
The following custom resource (CR) shows the parameters and acceptable values for a GitHub identity provider.
GitHub CR
- 1
- This provider name is prefixed to the GitHub numeric user ID to form an identity name. It is also used to build the callback URL.
- 2
- Controls how mappings are established between this provider’s identities and
User
objects. - 3
- 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. - 4
- The client ID of a registered 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>
. - 5
- Reference to an OpenShift Container Platform
Secret
object containing the client secret issued by GitHub. - 6
- For GitHub Enterprise, you must provide the host name of your instance, such as
example.com
. This value must match the GitHub Enterprisehostname
value in in the/setup/settings
file and cannot include a port number. If this value is not set, then eitherteams
ororganizations
must be defined. For GitHub, omit this parameter. - 7
- The list of organizations. Either the
organizations
orteams
field must be set unless thehostname
field is set, or ifmappingMethod
is set tolookup
. Cannot be used in combination with theteams
field. - 8
- The list of teams. Either the
teams
ororganizations
field must be set unless thehostname
field is set, or ifmappingMethod
is set tolookup
. Cannot be used in combination with theorganizations
field.
If organizations
or teams
is specified, only GitHub users that are members of at least one of the listed organizations will be 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 in order to use this option. This can be done during the first GitHub login by the organization’s administrator, or from the GitHub organization settings.
Additional resources
-
See Identity provider parameters for information on parameters, such as
mappingMethod
, that are common to all identity providers.
4.6.6. Adding an identity provider to your clusters 复制链接链接已复制到粘贴板!
After you install your cluster, add an identity provider to it so your users can authenticate.
Prerequisites
- Create an OpenShift Container Platform cluster.
- Create the custom resource (CR) for your identity providers.
- You must be logged in as an administrator.
Procedure
Apply the defined CR:
oc apply -f </path/to/CR>
$ oc apply -f </path/to/CR>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意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.Obtain a token from the OAuth server.
As long as the
kubeadmin
user has been removed, theoc login
command provides instructions on how to access a web page where you can retrieve the token.You can also access this page from the web console by navigating to (?) Help
Command Line Tools Copy Login Command. Log in to the cluster, passing in the token to authenticate.
oc login --token=<token>
$ oc login --token=<token>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意This identity provider does not support logging in with a user name and password.
Confirm that the user logged in successfully, and display the user name.
oc whoami
$ oc whoami
Copy to Clipboard Copied! Toggle word wrap Toggle overflow