$ oc create secret generic <secret_name> --from-literal=clientSecret=<secret> -n openshift-config
Configure a Google identity provider so users can authenticate to OKD with Google accounts. When configured, sign-in is permitted only for Google accounts in that hosted domain.
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 |
By using Google as an identity provider, you can authenticate to your server. You can use the hostedDomain configuration attribute to limit authentication to members of a specific hosted domain.
Google authentication uses OpenID Connect through the cluster OAuth server.
|
Using Google as an identity provider requires users to get a token using |
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
Review the custom resource (CR) fields and acceptable values for configuring a Google identity provider in OKD. Use these definitions to set client credentials and hosted domain restrictions before applying the configuration to the cluster.
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: googleidp
mappingMethod: claim
type: Google
google:
clientID: {...}
clientSecret:
name: google-secret
hostedDomain: "example.com"
where:
spec.identityProviders.nameSpecifies the provider name, which is prefixed to the Google numeric user ID to form an identity name. The provider name is also used to build the redirect URL.
spec.identityProviders.mappingMethodSpecifies how mappings are established between identities from this provider and User objects.
spec.identityProviders.google.clientIDSpecifies the client ID from the Google Cloud project where you create the OAuth client. The project must be configured with a redirect URI of
https://oauth-openshift.apps.<cluster-name>.<cluster-domain>/oauth2callback/<idp-provider-name>.
spec.identityProviders.google.clientSecretSpecifies a reference to an OKD Secret object containing the client secret issued by Google.
spec.identityProviders.google.hostedDomainSpecifies a hosted domain used to restrict sign-in accounts. Optional if the lookup mappingMethod is used. If empty, any Google account is allowed to authenticate.
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, |
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 (?) Help → Command Line Tools → Copy Login Command.
Log in to the cluster by running the following command, passing in the token to authenticate:
$ oc login --token=<token>
|
This identity provider does not support logging in with a username and password. |
Confirm that the user logged in successfully and that the username displays by running the following command:
$ oc whoami