$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
Configure the gitlab identity provider using GitLab.com or any other GitLab instance as an identity provider.
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 OKD beyond the default kubeadmin user.
|
OKD usernames containing |
Configuring GitLab authentication allows users to log in to OKD with their GitLab credentials.
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.
Create a Secret in the openshift-config namespace to store identity provider client secrets, certificates, or keys, so the OAuth custom resource (CR) can reference them.
Create a Secret object containing the client secret by running the following command:
$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
Optional: Apply the following YAML to create the secret:
apiVersion: v1
kind: Secret
metadata:
name: <secret_name>
namespace: openshift-config
type: Opaque
data:
clientSecret: <base64_encoded_client_secret>
Create a Secret object from a file by running the following command:
$ oc create secret generic <secret_name> --from-file=<path_to_file> -n openshift-config
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.
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.
$ 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:
|
The following custom resource (CR) shows the parameters and acceptable values for a GitLab identity provider.
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 OKD Secret object 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 OKD ConfigMap object containing the
PEM-encoded certificate authority bundle to use in validating server
certificates for the configured URL. |
See Identity provider parameters for information on parameters, such as mappingMethod, that are common to all identity providers.
Apply the OAuth custom resource (CR) to add an identity provider to your cluster so users can authenticate with external credentials instead of the default kubeadmin user.
You installed an OKD cluster.
You defined the CR for your identity provider.
You are logged in as an administrator.
Apply the defined CR by running the following command:
$ oc apply -f </path/to/CR>
|
If a CR does not exist, |
Log in to the cluster as a user from your identity provider by running the following command, which prompts for your username and password:
$ oc login -u <username>
Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami