This document guides how to set up Kubernetes OpenID Connect (OIDC) authentication. Let's see the following steps:
- Set up the OIDC provider
- Verify authentication
- Bind a cluster role
- Set up the Kubernetes API server
- Set up the kubeconfig
- Verify cluster access
Kubelogin supports the authentication flows such as Device Authorization Grant or Authorization Code Flow. For the details of flows supported in Kubelogin, see the usage. For the details of your provider, ask the administrator of your provider.
Run the following command to show the instruction to set up the configuration:
kubectl oidc-login setup --oidc-issuer-url=ISSUER_URL --oidc-client-id=YOUR_CLIENT_IDSet the following flags:
- Set the issuer URL of your OpenID Connect provider to
--oidc-issuer-url. - Set the client ID for your OpenID Connect provider to
--oidc-client-id. - If your provider requires a client secret, set
--oidc-client-secret.
If your provider supports the Device Authorization Grant, set --grant-type=device-code.
It launches the browser and navigates to the authentication page of your provider.
If your provider supports the Authorization Code Flow, set --grant-type=authcode.
It starts a local server for the authentication.
It launches the browser and navigates to the authentication page of your provider.
You can see the full options:
kubectl oidc-login setup --helpYou can run the following command to bind cluster-admin role to you:
kubectl create clusterrolebinding oidc-cluster-admin --clusterrole=cluster-admin --user='ISSUER_URL#YOUR_SUBJECT'Add the following flags to kube-apiserver:
--oidc-issuer-url=ISSUER_URL
--oidc-client-id=YOUR_CLIENT_ID
See Kubernetes Authenticating: OpenID Connect Tokens for the all flags.
Add oidc user to the kubeconfig.
kubectl config set-credentials oidc \
--exec-interactive-mode=Never \
--exec-api-version=client.authentication.k8s.io/v1 \
--exec-command=kubectl \
--exec-arg=oidc-login \
--exec-arg=get-token \
--exec-arg=--oidc-issuer-url=ISSUER_URL \
--exec-arg=--oidc-client-id=YOUR_CLIENT_IDIf your provider requires a client secret, add --oidc-client-secret=YOUR_CLIENT_SECRET.
For security, it is recommended to add --token-cache-storage=keyring to store the token cache to the keyring instead of the file system.
If you encounter an error, see the token cache for details.
Make sure you can access the Kubernetes cluster.
kubectl --user=oidc cluster-infoYou can switch the current context to oidc.
kubectl config set-context --current --user=oidcYou can share the kubeconfig to your team members for on-boarding.