123DevOps··7 min read

"Basic" authentication in Kubernetes: from removed basic auth to certificates, tokens, and OIDC

--basic-auth-file was removed in Kubernetes 1.19. Learn today's basic mechanisms hands-on: X.509 certificates through the CSR API, ServiceAccount tokens, OIDC with AuthenticationConfiguration, webhooks, and EKS, AKS, and GKE IAM.

Kubernetes

If you searched for “basic auth in Kubernetes” and found tutorials with --basic-auth-file and a CSV of usernames and passwords, stop right there: that mechanism was removed in Kubernetes 1.19. The release changelog states plainly that support for basic authentication via --basic-auth-file has been removed. In this guide, we set up today’s “basic” mechanisms, including the full X.509 certificate flow, run on a kind cluster with Kubernetes 1.37.

What exists today

Kubernetes has no user database. The API server receives a credential, runs it through a chain of authenticators, and if one of them recognizes it, the request continues with a username and a list of groups. What that user may do is decided by authorization, usually RBAC.

Mechanism For whom Status
--basic-auth-file (username and password) Humans Removed in 1.19
X.509 client certificate Humans, components, break-glass Supported
ServiceAccount token (bound) Workloads and automation Supported, recommended for machines
Static token file (--token-auth-file) Legacy Supported, discouraged
OIDC / AuthenticationConfiguration Humans via a corporate IdP Structured config stable since 1.34
Webhook token Integration with your own systems Supported
Cloud IAM (EKS, AKS, GKE) Humans and pipelines on managed clusters Provider-specific

Users vs ServiceAccounts

Users live outside the cluster: there is no kind: User. A user is just the name the authenticator returns (a certificate’s CN, an OIDC token claim). ServiceAccounts are cluster objects, namespaced, made for processes. A ServiceAccount’s username follows the format system:serviceaccount:<namespace>:<name>. Rule of thumb: people come in through the IdP; pods and pipelines use ServiceAccounts or the cloud’s workload identity.

X.509 certificates with the CSR API

The API server accepts certificates signed by the CA given in --client-ca-file. The CN becomes the username and each O becomes a group. Instead of signing by hand with the CA key, use the CertificateSigningRequest API.

Generate the key and the CSR

openssl genpkey -algorithm ed25519 -out e-ana.key
openssl req -new -key e-ana.key -out e-ana.csr -subj "/CN=e-ana/O=e-devs"

Submit, approve, and extract

cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: e-ana
spec:
  request: $(base64 < e-ana.csr | tr -d '\n')
  signerName: kubernetes.io/kube-apiserver-client
  expirationSeconds: 86400
  usages:
    - client auth
EOF
kubectl certificate approve e-ana
kubectl get csr e-ana -o jsonpath='{.status.certificate}' | base64 -d > e-ana.crt
NAME    AGE   SIGNERNAME                            REQUESTOR          REQUESTEDDURATION   CONDITION
e-ana   7s    kubernetes.io/kube-apiserver-client   kubernetes-admin   24h                 Approved,Issued

subject=O=e-devs, CN=e-ana
issuer=CN=kubernetes
notBefore=Nov 25 04:32:39 2026 GMT
notAfter=Nov 26 04:32:39 2026 GMT

Add the user to kubeconfig and test

kubectl config set-credentials e-ana --client-key=e-ana.key \
  --client-certificate=e-ana.crt --embed-certs=true
kubectl config set-context e-ana@lab --cluster=kind-blog-lab --user=e-ana --namespace=e-auth
kubectl auth whoami --user=e-ana
kubectl get pods -n e-auth --user=e-ana
ATTRIBUTE                                           VALUE
Username                                            e-ana
Groups                                              [e-devs system:authenticated]
Extra: authentication.kubernetes.io/credential-id   [X509SHA256=925a0964...]

Error from server (Forbidden): pods is forbidden: User "e-ana" cannot list resource "pods" in API group "" in the namespace "e-auth"

Authenticated, but not authorized. A RoleBinding for the e-devs group fixes that, and it applies to everyone whose certificate carries O=e-devs:

kubectl create role e-pod-reader --verb=get,list,watch --resource=pods -n e-auth
kubectl create rolebinding e-devs-read --role=e-pod-reader --group=e-devs -n e-auth
kubectl --context e-ana@lab auth can-i list pods     # yes
kubectl --context e-ana@lab auth can-i delete pods   # no

Finally, delete the CSR object with kubectl delete csr e-ana.

The revocation problem

In the lab, after kubectl delete csr e-ana, kubectl auth whoami --user=e-ana kept working. Kubernetes doesn’t check revocation lists for client certificates: the certificate is valid until its notAfter. So use a short lifetime (expirationSeconds), grant permissions through RoleBindings (which you can delete), and never use the system:masters group, which bypasses RBAC. Certificates work well for emergency access and components, poorly for people’s day-to-day work.

ServiceAccount tokens

Since 1.24, Kubernetes no longer creates token Secrets automatically. The way forward is the bound token, issued by the TokenRequest API, with an expiry and an audience. Below, the output shows the first token’s payload, decoded with a small Python script, and the second command’s error:

kubectl -n e-auth create serviceaccount e-ci
kubectl -n e-auth create token e-ci --duration=15m
kubectl -n e-auth create token e-ci --duration=5m
{"aud": ["https://kubernetes.default.svc.cluster.local"], "sub": "system:serviceaccount:e-auth:e-ci"} lifetime_s= 900
error: failed to create token: ... spec.expirationSeconds: Invalid value: 300: may not specify a duration less than 10 minutes

The minimum is 10 minutes. With --audience=https://vault.example.com, the token is only good for that destination: in the lab, the API server rejected it with Unauthorized, as it should.

The legacy format still exists: a Secret of type kubernetes.io/service-account-token with the kubernetes.io/service-account.name annotation. Decoded in the lab, the token had no exp claim, meaning it never expires. The cluster then labeled the Secret with kubernetes.io/legacy-token-last-used, which helps you find and clean up these tokens. Use the legacy format only when there is no alternative.

Static token file

--token-auth-file points to a CSV (token,user,uid,"group1,group2"). It is still supported, but the tokens never expire and any change requires restarting the API server. On managed clusters, you don’t even have access to that flag. Avoid it.

OIDC and AuthenticationConfiguration

For people, the recommended path is a corporate IdP (Keycloak, Entra ID, Okta, Google, Dex) issuing OIDC tokens. The --oidc-* flags work, but the structured configuration, AuthenticationConfiguration (apiserver.config.k8s.io/v1, the --authentication-config flag), has been stable since 1.34. It accepts multiple issuers and CEL rules, and is reloaded without restarting the API server. It can’t be combined with the --oidc-* flags. The shape:

apiVersion: apiserver.config.k8s.io/v1
kind: AuthenticationConfiguration
jwt:
  - issuer:
      url: https://sso.example.com/realms/platform
      audiences:
        - kubernetes
    claimValidationRules:
      - expression: "claims.email_verified == true"
        message: "email must be verified"
    claimMappings:
      username:
        claim: email
        prefix: "oidc:"
      groups:
        claim: groups
        prefix: "oidc:"
    userValidationRules:
      - expression: "!user.username.startsWith('system:')"
        message: "names prefixed with system: are reserved"

I checked the field names against the k8s.io/apiserver v0.37.1 source, but did not apply this file in the lab: changing API server flags on a shared cluster is not something to do for a test. Check the current docs before using it. On the client side, the kubeconfig uses an exec plugin (such as kubelogin) to log in through the browser and refresh the token.

Webhook token authentication

With --authentication-token-webhook-config-file, the API server sends each unknown token to a service of yours, in a TokenReview object, and trusts the answer. It’s the same format the API server itself uses to validate tokens, and you can see it working in the lab:

kubectl create -f tokenreview.yaml -o jsonpath='{.status}'
{
  "authenticated": true,
  "audiences": ["https://kubernetes.default.svc.cluster.local"],
  "user": {
    "username": "system:serviceaccount:e-auth:e-ci",
    "groups": ["system:serviceaccounts", "system:serviceaccounts:e-auth", "system:authenticated"]
  }
}

Managed clusters: cloud IAM

Provider Authentication Example command
EKS IAM + access entries (the aws-auth ConfigMap is deprecated) aws eks create-access-entry
AKS Microsoft Entra ID, with Kubernetes RBAC or Azure RBAC az aks update --enable-aad --enable-azure-rbac
GKE Google IAM + RBAC, with Google Groups for RBAC gcloud container clusters get-credentials

On EKS, the pair of commands looks like this (flags checked with aws eks <cmd> help):

aws eks create-access-entry --cluster-name my-cluster \
  --principal-arn arn:aws:iam::111122223333:role/platform-team
aws eks associate-access-policy --cluster-name my-cluster \
  --principal-arn arn:aws:iam::111122223333:role/platform-team \
  --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy \
  --access-scope type=namespace,namespaces=payments

On AKS, --disable-local-accounts turns off the local admin credential, and az aks get-credentials --format exec generates a kubeconfig that hands login over to Entra ID. On GKE, get-credentials configures the gke-gcloud-auth-plugin, and --security-group enables Google Groups as RBAC groups. Details change often: check each provider’s current docs. The authorization side continues in RBAC with ClusterRoles and RoleBindings, and the overall risk map is in the Kubernetes attack surface.

Checklist

  • No references to --basic-auth-file (removed in 1.19) in docs or automation
  • People authenticate through an IdP (OIDC or cloud IAM), not long-lived certificates
  • X.509 certificates with a short expirationSeconds and without the system:masters group
  • Automation uses kubectl create token or workload identity, with an expiry and an audience
  • Legacy token Secrets inventoried via the kubernetes.io/legacy-token-last-used label and removed
  • No --token-auth-file in production
  • On EKS, access entries instead of aws-auth

Authentication only answers “who are you”; make sure that answer comes from somewhere you can revoke in seconds.

Get updates on new posts and stay in the loop!