To authenticate to Kubernetes with OIDC, you configure the API server to trust your identity provider, then point a user entry in your kubeconfig at a credential plugin such as kubelogin. The plugin opens a browser, gets an ID token, and hands it to kubectl. You can also paste a token straight into the kubeconfig, but it expires fast, so the plugin route is the one you will use day to day.
This guide covers both sides: what the cluster needs, what goes in the kubeconfig, how kubectl oidc-login behaves, how to bind RBAC to groups, and how to debug the errors that show up first.
TL;DR
- Kubernetes treats the OIDC ID token as a bearer token. The API server needs an HTTPS issuer URL and a client ID, and it finds signing keys through OIDC discovery.
- In kubeconfig, use an
execuser that runskubectl oidc-login get-token, rather than pasting tokens that expire. - Bind RBAC to the groups your provider emits, not to individual users, so access follows directory membership.
- Most failures come from a wrong issuer URL, missing group claims, a skewed clock, or a missing plugin binary.
- Keep tokens short-lived and store the token cache in the OS keyring.
Table of Contents
- How OIDC authentication works with kubectl
- What the cluster and the identity provider need
- Two ways to put OIDC in a kubeconfig
- What happens when you run kubectl oidc-login
- Map OIDC identities to RBAC
- Working with several clusters
- Troubleshooting OIDC login errors
- Keep OIDC logins secure
- Our perspective
- Manage your clusters from one native app
- FAQ
- Sources
How OIDC authentication works with kubectl
Kubernetes does not log users in itself. It supports OIDC and uses the ID token as a bearer token, which means your identity provider does the sign-in and Kubernetes only verifies what it receives. The API server requires an HTTPS issuer URL and a client ID, and it discovers the externally issued JWT signing keys through OIDC discovery.
In practice the flow looks like this:
- You run a kubectl command.
- kubectl asks the credential plugin for a token.
- The plugin opens your browser and you sign in to the identity provider, with MFA if your organization enforces it.
- The provider returns an ID token (a JWT) containing claims such as your username, email and groups.
- kubectl sends the token to the API server, which validates the signature and issuer and reads the claims.
As one engineering write-up puts it, OIDC lets Kubernetes federate user identification to identity providers. The client in this flow is the native application kubectl running on a developer's computer, so the OAuth client at your provider must be configured as a native or public client type that allows a local redirect.
What the cluster and the identity provider need
Before touching your kubeconfig, make sure both ends are ready.
On the API server, the classic flag-based setup uses --oidc-issuer-url and --oidc-client-id, plus optional flags such as --oidc-username-claim, --oidc-groups-claim, --oidc-username-prefix and --oidc-groups-prefix. Newer Kubernetes releases also offer a configuration-file approach. The documentation notes that the file lets you configure multiple JWT authenticators, each with its own issuer URL and discovery URL, and use CEL expressions to map claims to user attributes and validate them. The API server reloads the authenticators automatically when the file changes.
On the identity provider, you need four things the cluster must know: the issuer (it must support OIDC discovery), the client ID, the claim that holds the username, and the claim that holds groups. Request the scopes that produce those claims. A common recommendation is to add the email and groups extra scopes in the kubeconfig so the token carries what RBAC needs.
On managed clusters, you often configure this through the provider's API or console instead of API server flags. Amazon EKS, for example, supports up to 10 OIDC identity providers on clusters running Kubernetes 1.32 or later, only one on earlier versions, and requires a publicly accessible issuer URL without a self-signed certificate. Check your platform's page for its own limits.

Two ways to put OIDC in a kubeconfig
Option 1: a static token
The simplest method is to take the ID token and pass it with kubectl's --token argument or add it directly to the kubeconfig. This is fine for a quick test. ID tokens are short-lived, so a pasted token stops working soon after and you have to repeat the process. Do not use this for daily work.
Option 2: an exec credential plugin
This is the standard approach. You add a user entry that tells kubectl to run a helper whenever it needs a token. With kubelogin, the setup command from its documentation looks like this:
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_ID
That is the documented kubelogin setup, which also advises adding --token-cache-storage=keyring for security. Add --exec-arg=--oidc-extra-scope=email and --exec-arg=--oidc-extra-scope=groups if your RBAC relies on those claims. Then attach the user to a context for your cluster:
kubectl config set-context my-cluster-oidc --cluster=my-cluster --user=oidc
kubectl config use-context my-cluster-oidc
Replace ISSUER_URL and YOUR_CLIENT_ID with your provider's values. The plugin itself installs separately, for example through krew as oidc-login.
What happens when you run kubectl oidc-login
The plugin is built as a client-go credential plugin. According to its README, it opens the browser, caches the ID and refresh tokens, returns a valid ID token, refreshes it when expired, and re-authenticates if the refresh token has expired.

So your first command in a session pops a browser tab. For the following commands you see nothing until the refresh token lapses, which is set by your identity provider's policy. One guide notes that the plugin keeps its cache under ~/.kube/cache/oidc-login/, separated by issuer and client ID, and that you should protect that directory as sensitive data with mode 0700. The same guide describes a provider whose ID tokens expire after 15 minutes by default, which shows why the refresh step matters: lifetimes are short by design.
To sign out, delete the cache with kubectl oidc-login clean.
Map OIDC identities to RBAC
Authentication only proves who you are. What you can do comes from RBAC. A RoleBinding grants permissions within a namespace and a ClusterRoleBinding grants them cluster-wide, and the subjects can be users, groups or ServiceAccounts. Usernames and groups are plain strings, with only the system: prefix reserved.
With OIDC you use the user and group claims from the token to configure RoleBindings. The practical advice is to bind to groups. When someone joins or leaves a team in your directory, their cluster access changes without anyone editing a manifest.
A minimal example, assuming your groups claim has a platform-admins group and you set a oidc: groups prefix on the API server:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: platform-admins-view
subjects:
- kind: Group
name: "oidc:platform-admins"
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: view
apiGroup: rbac.authorization.k8s.io
Start with view or a namespaced Role and widen only when needed. Prefixes keep OIDC groups from colliding with names you already use for other authenticators.
Working with several clusters
Every cluster can trust the same provider with a different client ID, or share one. Either way, each cluster gets its own cluster entry, context and, if client IDs differ, its own user entry in the kubeconfig. The token cache is separated by issuer and client ID, so two clusters using the same pair share a login, while different pairs trigger separate browser sign-ins.
A few habits keep this manageable:
- Name users after the cluster or environment, such as
oidc-prodandoidc-staging, so a context never points at the wrong login. - Keep production and non-production on different client IDs if your security team wants separate sign-in prompts and token lifetimes.
- Know where the file lives on each machine. Our guide to kubeconfig location on Windows, macOS and Linux covers the paths and the
KUBECONFIGvariable. - Review how contexts are switched and merged in our kubeconfig context management guide, because merging files from several teams is where stale OIDC users tend to hide.
If some of your clusters sit behind a private network, you can reach them through a tunnel instead of a VPN. See how to copy SSH tunnel commands and fix certificate errors for that setup. The API server's issuer must still be reachable from the API server itself, so tunneling changes how you connect, not how the cluster reaches the provider.
Troubleshooting OIDC login errors
Start with the basics from the Kubernetes docs: check that the kubeconfig is valid and that $KUBECONFIG is set correctly. For authentication errors, validate the token and the authentication server address. For authorization errors, check credentials and permissions. If you use a helper, confirm it is still installed and configured. kubectl config view shows what kubectl actually reads.
| Symptom | Likely cause | What to do |
|---|---|---|
| Plugin not found, or exec errors | The oidc-login binary is missing or not on PATH | Reinstall the plugin and confirm kubectl can run it |
| Browser never opens, or loops | Wrong client ID or callback URI at the provider | Compare the redirect URI registered at the provider with the one the plugin uses |
| Refresh keeps failing | Clock skew, unwritable cache, or unreachable discovery | Sync the clock, check cache permissions, and curl the .well-known/openid-configuration endpoint |
| Logged in but Forbidden | No RoleBinding for your user or group | Bind a Role to the group claim in your token |
| Group-based access fails | Token lacks groups, or the claim name differs | Decode the token and compare the claim to the API server's groups claim setting |
| Windows: command line too long | Very large token from many group memberships | Upgrade kubectl or reduce group count |
Details behind the less obvious rows:
- Token refresh failures. One kubelogin guide suggests verifying the local clock, a writable cache directory, reachable discovery, correct client ID and callback URI, and running with
--v=1for diagnostics. For a private issuer CA, configure the plugin's certificate-authority option. - Groups not working. To check, decode the ID token, for example at jwt.io, and confirm the group key matches the configured groups claim. If groups are missing, reconfigure the provider to emit them. Only paste tokens into a decoder you trust, or decode locally, since a live token is a credential.
- Server-side errors. Messages about being unable to fetch JWKs usually mean a typo in the issuer URL, while a failed discovery fetch points to network problems. That documentation is for Google's distributed cloud product, but the causes apply to any API server that must reach its issuer.
- Windows and big tokens. On Windows, kubectl can fail with "The command line is too long" when an Azure AD token exceeds 8,191 characters, which happens at roughly 70 to 200 group memberships. Listed fixes include moving to kubectl 1.28 or later or reducing group memberships.
Keep OIDC logins secure
OIDC is the recommended route once several people use a cluster. The hardening guide says that for production clusters with multiple users accessing the API directly, you should use external authentication sources such as OIDC, keep tokens short-lived, and isolate the OIDC-supporting software from general workloads because it runs with high privileges.
A short checklist:
- Short token lifetimes. OWASP's Kubernetes Top 10 says tokens should be as short-lived as tolerable, so a leaked credential may expire before it is replayed.
- MFA at the provider. The same page recommends enforcing MFA where possible, typically through the OIDC provider.
- No anonymous access. For self-managed clusters, OWASP suggests setting
--anonymous-auth=falseon the API server and kubelet, and granting no RBAC permissions tosystem:unauthenticatedon managed services. - Keyring cache. The plugin stores its cache on the file system by default, and its README recommends
--token-cache-storage=keyringfor better protection. - No human tokens in CI. For automation, use a ServiceAccount or another workload credential rather than copying someone's login cache into a pipeline.
For wider API exposure, including network paths and audit, see our Kubernetes API access security guide.
Our perspective
Most OIDC trouble we see is not in the protocol. It sits around it: a kubeconfig with a dozen stale users, a token cache nobody thinks about, and three terminal tabs each pointed at a different cluster.
We built Kubezilla Desktop around the idea that credentials should stay on your machine. Your kubeconfigs are stored securely and locally, with no cloud sync and no telemetry. When the file that holds your cluster access never leaves your laptop, the question of who else can read it gets much simpler to answer.
The second half is the daily work. Once you are authenticated, you should not need a stack of CLI tools and browser tabs to see logs, check metrics, edit YAML, scale a workload or open a pod terminal. A native app written in Rust starts fast and stays light on memory, so the tool is never the thing slowing you down. For clusters behind a bastion, SSH tunneling is built in, so you can reach them without a VPN.
Good authentication gives you safe access. A good client makes that access fast to use across every cluster you manage.
Margus
Manage your clusters from one native app
Once your kubeconfig authenticates cleanly, the next friction is switching between clusters, tabs and tools. Kubezilla Desktop is a native Linux, macOS and Windows app that gives you one interface for multi-cluster access, live log streaming, metrics, pod terminals, YAML editing, workload scaling, Helm and ArgoCD operations, and PVC file browsing. Kubeconfigs stay in secure local storage. It costs €5 per month.

If you run clusters across several providers, our write-up on multi-cloud Kubernetes management shows how teams cut console hopping, and the Kubernetes client page describes what the app does day to day.
FAQ
How do I use kubectl oidc login?
Install the oidc-login plugin, add an exec user to your kubeconfig with your issuer URL and client ID, and run any kubectl command. The plugin opens your browser for sign-in, caches the tokens, and refreshes them automatically. Run kubectl oidc-login clean to remove the cache and sign out.
Can I put an OIDC token directly in my kubeconfig?
Yes, Kubernetes allows you to add the ID token to the kubeconfig or pass it with --token. The catch is that ID tokens are short-lived, so you would have to replace it again and again. An exec plugin that refreshes tokens for you is the practical choice.
Do I need to restart the API server to add an OIDC provider?
With the older flag-based setup, changing the OIDC flags means changing the API server configuration. With the configuration-file approach in current Kubernetes, the API server reloads authenticators automatically when the file changes. On managed clusters, you usually make the change through the provider's own interface.
Why am I authenticated but still getting Forbidden?
Authentication and authorization are separate. The API server accepted your token, but no RoleBinding or ClusterRoleBinding matches your username or groups. Decode your token, check the user and group claims, and bind a Role to the group name exactly as the API server sees it, including any prefix.
Should CI pipelines use kubelogin?
No. Interactive browser login is designed for people. For pipelines, use a ServiceAccount or another workload credential, so no individual's token cache sits on a build server.
Sources
- Authenticating | Kubernetes
- kubelogin setup documentation
- int128/kubelogin README
- Scalable User Authentication with OpenID Connect
- OIDC & SSO for kubectl
- Amazon EKS: external OIDC identity provider
- Using RBAC Authorization | Kubernetes
- Troubleshooting kubectl | Kubernetes
- Using kubelogin for kubectl Authentication
- Troubleshoot user access issues | GKE
- Troubleshoot Google Distributed Cloud authentication issues
- Troubleshoot OIDC provider issues
- Hardening Guide: Authentication Mechanisms | Kubernetes
- K09: Broken Authentication Mechanisms | OWASP
