Configuring a GitHub or GitHub Enterprise identity provider

    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.

    Configuring GitHub authentication allows users to log in to OKD with their GitHub credentials. To prevent anyone with any GitHub user ID from logging in to your OKD 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.

    OKD user names containing /, :, and % are not supported.

    Registering a GitHub application

    To use GitHub or GitHub Enterprise as an identity provider, you must register an application to use.

    Procedure

    1. Register an application on GitHub:

    2. Enter an application name, for example My OpenShift Install.

    3. Enter a homepage URL, such as https://oauth-openshift.apps.<cluster-name>.<cluster-domain>.

    4. Optional: Enter an application description.

    5. For example:

      1. https://oauth-openshift.apps.example-openshift-cluster.com/oauth2callback/github/
    6. Click Register application. GitHub provides a client ID and a client secret. You need these values to complete the identity provider configuration.

    Identity providers use OKD Secret objects in the openshift-config namespace to contain the client secret, client certificates, and keys.

    • You can define an OKD Secret object containing a string by using the following command.

      1. You can define an OKD Secret object containing the contents of a file, such as a certificate file, by using the following command.

      Creating a config map

      Identity providers use OKD 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.

      Procedure

      • Define an OKD ConfigMap object containing the certificate authority by using the following command. The certificate authority must be stored in the ca.crt key of the ConfigMap object.

        1. $ oc create configmap ca-config-map --from-file=ca.crt=/path/to/ca -n openshift-config

      The following custom resource (CR) shows the parameters and acceptable values for a GitHub identity provider.

      GitHub CR

      1. apiVersion: config.openshift.io/v1
      2. kind: OAuth
      3. metadata:
      4. spec:
      5. identityProviders:
      6. - name: githubidp (1)
      7. mappingMethod: claim (2)
      8. type: GitHub
      9. github:
      10. ca: (3)
      11. name: ca-config-map
      12. clientID: {...} (4)
      13. name: github-secret
      14. hostname: ... (6)
      15. organizations: (7)
      16. - myorganization1
      17. - myorganization2
      18. teams: (8)
      19. - myorganization1/team-a
      20. - myorganization2/team-b
      1This provider name is prefixed to the GitHub numeric user ID to form an identity name. It is also used to build the callback URL.
      2Controls how mappings are established between this provider’s identities and User objects.
      3Optional: Reference to an OKD 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.
      4The client ID of a registered GitHub OAuth application. The application must be configured with a callback URL of ;.
      5Reference to an OKD Secret object containing the client secret issued by GitHub.
      6For GitHub Enterprise, you must provide the hostname of your instance, such as example.com. This value must match the GitHub Enterprise hostname value in in the 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.
      7The 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.
      8The 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.

      Additional resources

      Adding an identity provider to your clusters

      Prerequisites

      • Create an OKD cluster.

      • Create the custom resource (CR) for your identity providers.

      • You must be logged in as an administrator.

      Procedure

      1. Apply the defined CR:

        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 (?) HelpCommand Line ToolsCopy Login Command.

      3. Log in to the cluster, passing in the token to authenticate.

        1. $ oc login --token=<token>