This is a cache of https://docs.openshift.com/container-platform/4.2/authentication/identity_providers/configuring-gitlab-identity-provider.html. It is a snapshot of the page at 2024-11-23T02:22:09.255+0000.
Configuring a GitLab identity provider - Configuring identity providers | Authentication | OpenShift Container Platform 4.2
×

Configure a gitlab identity provider to use GitLab.com or any other GitLab instance as an identity provider. If you use GitLab version 7.7.0 to 11.0, you connect using the OAuth integration. If you use GitLab version 11.1 or later, you can use OpenID Connect (OIDC) to connect instead of OAuth.

About identity providers in OpenShift Container Platform

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.

Creating the secret

Identity providers use OpenShift Container Platform secrets in the openshift-config namespace to contain the client secret, client certificates, and keys.

  • You can define an OpenShift Container Platform secret containing a string by using the following command.

    $ oc create secret generic <secret_name> --from-literal=clientsecret=<secret> -n openshift-config
  • You can define an OpenShift Container Platform secret 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

Creating a ConfigMap

Identity providers use OpenShift Container Platform ConfigMaps in the openshift-config namespace to contain the certificate authority bundle. These are primarily used to contain certificate bundles needed by the identity provider.

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

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

Sample GitLab CR

The following Custom Resource (CR) shows the parameters and acceptable values for a GitLab identity provider.

GitLab CR
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
  name: cluster
spec:
  identityProviders:
  - name: gitlabidp (1)
    mappingMethod: claim (2)
    type: GitLab
    gitlab:
      clientID: {...} (3)
      clientsecret: (4)
        name: gitlab-secret
      url: https://gitlab.com (5)
      ca: (6)
        name: ca-config-map
1 This provider name is prefixed to the GitLab 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 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>.
4 Reference to an OpenShift Container Platform secret containing the client secret issued by GitLab.
5 The host URL of a GitLab provider. This could either be https://gitlab.com/ or any other self hosted instance of GitLab.
6 Optional: Reference to an OpenShift Container Platform ConfigMap containing the PEM-encoded certificate authority bundle to use in validating server certificates for the configured URL.

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
  1. Apply the defined CR:

    $ oc apply -f </path/to/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. 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 display the user name.

    $ oc whoami