← Back to blog

Kubeconfig OIDC Authentication: Setup, kubectl Login and Fixes

November 8, 2026
Kubeconfig OIDC Authentication: Setup, kubectl Login and Fixes

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.

Kubezilla Desktop
Manage Kubernetes Clusters in One App
Kubezilla Desktop brings multiple clusters into one native interface, with secure local kubeconfig storage and real-time resource management.
Visit Kubezilla Desktop

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 exec user that runs kubectl 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

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:

  1. You run a kubectl command.
  2. kubectl asks the credential plugin for a token.
  3. The plugin opens your browser and you sign in to the identity provider, with MFA if your organization enforces it.
  4. The provider returns an ID token (a JWT) containing claims such as your username, email and groups.
  5. 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.

What the cluster and the identity provider need

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.

OIDC plugin login and token refresh flow

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-prod and oidc-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 KUBECONFIG variable.
  • 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.

SymptomLikely causeWhat to do
Plugin not found, or exec errorsThe oidc-login binary is missing or not on PATHReinstall the plugin and confirm kubectl can run it
Browser never opens, or loopsWrong client ID or callback URI at the providerCompare the redirect URI registered at the provider with the one the plugin uses
Refresh keeps failingClock skew, unwritable cache, or unreachable discoverySync the clock, check cache permissions, and curl the .well-known/openid-configuration endpoint
Logged in but ForbiddenNo RoleBinding for your user or groupBind a Role to the group claim in your token
Group-based access failsToken lacks groups, or the claim name differsDecode the token and compare the claim to the API server's groups claim setting
Windows: command line too longVery large token from many group membershipsUpgrade kubectl or reduce group count

Details behind the less obvious rows:

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:

  1. 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.
  2. MFA at the provider. The same page recommends enforcing MFA where possible, typically through the OIDC provider.
  3. No anonymous access. For self-managed clusters, OWASP suggests setting --anonymous-auth=false on the API server and kubelet, and granting no RBAC permissions to system:unauthenticated on managed services.
  4. Keyring cache. The plugin stores its cache on the file system by default, and its README recommends --token-cache-storage=keyring for better protection.
  5. 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.

Kubezilla Desktop

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