Configuring a GitLab identity provider

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 OKD

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.

Creating the secret

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

Procedure

  • Create a Secret object containing a string by using the following command:

    1. $ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config

    You can alternatively apply the following YAML to create the secret:

    1. apiVersion: v1
    2. kind: Secret
    3. metadata:
    4. name: <secret_name>
    5. namespace: openshift-config
    6. type: Opaque
    7. data:
    8. clientSecret: <base64_encoded_client_secret>
  • You can define a Secret object containing the contents of a file, such as a certificate file, by using the following command:

    1. $ oc create secret generic <secret_name> --from-file=<path_to_file> -n openshift-config

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

    You can alternatively apply the following YAML to create the config map:

    1. apiVersion: v1
    2. kind: ConfigMap
    3. metadata:
    4. name: ca-config-map
    5. namespace: openshift-config
    6. type: Opaque
    7. data:
    8. ca.crt: |
    9. <CA_certificate_PEM>

Sample GitLab CR

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

GitLab CR

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

Additional resources

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 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:

    1. $ 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.

    1. $ oc login -u <username>
  3. Confirm that the user logged in successfully, and display the user name.

    1. $ oc whoami