Join our Newsletter — 33% off our NHI Course
Home› Guides› How to set up HashiCorp Vault Kubernetes auth:…
Guide Secrets Management

How to set up HashiCorp Vault Kubernetes auth: Roles, audiences and short-lived pod access

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 17 min read
On this page

HashiCorp Vault's Kubernetes auth method lets a pod swap its own service account token for a short-lived Vault token, so no application has to ship with a static Vault secret. It is the most common way workloads in a cluster reach Vault, and it is also one of the easiest places to grant far more access than intended. A role bound to every namespace, a reviewer token that never expires or a Vault token with a month-long lifetime quietly turns a pod identity into a long-lived, broadly scoped credential.

This guide walks through setting up the method end to end: enabling the mount, choosing how Vault calls the Kubernetes TokenReview API, writing tightly bound roles with audiences and short token lifetimes, handling short-lived projected tokens, and using service account annotations for templated policies. It does not repeat the platform overview in our HashiCorp Vault Guide; read that first if you are new to Vault's identity model.

This is an independent guide from NHI Mgmt Group, based on HashiCorp's public documentation as of November 2026. It is not sponsored or reviewed by HashiCorp. Product features change, so confirm settings against HashiCorp's current documentation.

Key takeaways

  • The Kubernetes auth method validates a pod's service account JWT through the Kubernetes TokenReview API and returns a Vault token carrying the policies of a named role.
  • Every role should name specific service accounts and specific namespaces. A wildcard * in either field lets any matching workload in the cluster claim the role's policies.
  • Set an audience on each role and mount a projected service account token with that audience, so a token minted for another consumer cannot be replayed to Vault.
  • Prefer the local token of the Vault pod, or the client's own JWT, as the reviewer credential. A long-lived reviewer secret works but gives up the benefit of short-lived tokens.
  • Keep token_ttl and token_max_ttl short and leave alias_name_source on its default of serviceaccount_uid.
  • Issuer validation options are deprecated; new mounts default to disable_iss_validation=true, and older mounts need checking before cluster upgrades.

How Kubernetes auth works

HashiCorp describes the method as one that can be used to authenticate with Vault using a Kubernetes Service Account Token, making it easy to introduce a Vault token into a pod. The flow has four steps:

  1. The pod reads its service account JWT, normally from /var/run/secrets/kubernetes.io/serviceaccount/token or from a projected volume path you choose.
  2. The pod calls auth/kubernetes/login with two fields: role and jwt.
  3. Vault sends the JWT to the Kubernetes TokenReview API to confirm it is valid and still belongs to a live service account, then checks the service account name, namespace and audience against the role.
  4. If everything matches, Vault returns a client token at auth.client_token, with policies and metadata such as service_account_name, service_account_namespace and service_account_uid.

Two trust relationships sit inside that flow. Vault trusts the Kubernetes API server to say whether a JWT is genuine, and the pod trusts Vault enough to hand over its JWT. HashiCorp notes that this pattern depends on sharing the JWT over the network, which is acceptable because Vault is part of the trusted compute base, but that Kubernetes applications should not share this JWT with other applications, because it allows API calls to be made on behalf of the pod. Treat the service account token as a credential in its own right, as covered in our Kubernetes Service Account Token Guide.

Kubernetes needs to run with --service-account-lookup, which has defaulted to true since Kubernetes 1.7. Without it, deleted tokens are not properly revoked and can still authenticate to the method.

Step 1: Enable the auth method and plan mounts

Enable the method with vault auth enable kubernetes. The default path is auth/kubernetes. If you run more than one cluster, enable one mount per cluster, for example vault auth enable -path=k8s-prod-eu kubernetes, because each mount holds exactly one cluster configuration (API host, CA certificate and reviewer credential).

Planning points before you configure anything:

  • One mount per cluster, named for the cluster. Mount names appear in audit logs and in the mount accessor used by templated policies, so a clear name saves time during an investigation.
  • Keep production and non-production clusters on separate mounts. A role on a development cluster mount can never accidentally authorise a production workload, and the reverse.
  • Decide who can write to auth/<mount>/role/*. Whoever can create roles can decide which pods get which policies. Restrict that path to your platform or Vault administrators, and manage roles through code review.

Step 2: Configure the cluster connection and reviewer

The auth/<mount>/config endpoint tells Vault how to reach the Kubernetes API. The only required parameter is kubernetes_host, the host, host and port, or URL of the API server. The main optional parameters are:

ParameterWhat it doesRecommended practice
kubernetes_hostAPI server address Vault calls for TokenReview.Use the in-cluster service address when Vault runs in the cluster; confirm external addresses with kubectl cluster-info.
kubernetes_ca_certPEM CA certificate for TLS to the API server.Always set it, or rely on the local CA in a pod. Never skip TLS verification.
token_reviewer_jwtBearer token Vault uses to call TokenReview.Leave unset where possible (see the options below).
pem_keysPublic keys or certificates to verify service account JWT signatures.Optional; not every installation exposes these keys.
disable_local_ca_jwtStops Vault defaulting to the local CA and JWT in its pod.Set to true only when Vault in a pod must review tokens for a different cluster.
use_annotations_as_alias_metadataCopies selected service account annotations into Vault alias metadata.Enable only if you use templated policies, as it requires extra Kubernetes read permissions.

Choosing the reviewer credential

From Kubernetes 1.21, the token mounted into pods by default expires and is bound to the lifetime of the pod and service account. This matters for the reviewer: if Vault uses a short-lived token as token_reviewer_jwt, it stops working as soon as that token expires or the pod is deleted, and every login then fails. HashiCorp lists four options:

OptionAll tokens short-livedEarly revocation possibleNotes
Vault pod's local token as reviewerYesYesRecommended when Vault runs in the cluster; needs Vault 1.9.3 or later.
Client's own JWT as reviewerYesYesEach client service account needs the system:auth-delegator ClusterRole.
Long-lived token secret as reviewerNoYesKeeps older workflows but loses the benefit of short-lived tokens.
JWT auth with Kubernetes as OIDC providerYesNoNo reviewer needed, but Vault tokens cannot be revoked before their TTL ends.

Vault inside the cluster. Omit token_reviewer_jwt and kubernetes_ca_cert. Vault loads token and ca.crt from /var/run/secrets/kubernetes.io/serviceaccount/ and re-reads the file periodically, so rotation of the projected token is handled for you. The configuration is a single line:

vault write auth/kubernetes/config kubernetes_host=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT

Vault outside the cluster. Omit token_reviewer_jwt so Vault presents each client's JWT to TokenReview. You then bind system:auth-delegator to the service accounts that log in. This avoids storing any JWT in Vault at the cost of more RBAC to maintain. If you choose a long-lived reviewer secret instead, create a dedicated vault-auth service account, bind only system:auth-delegator to it, store the token as a kubernetes.io/service-account-token secret, and add it to your rotation schedule. Our guide on How to rotate a Kubernetes service account token and detect old token use covers that process.

Whichever reviewer you use, its service account needs permission to call TokenReview. HashiCorp's example is a ClusterRoleBinding of the built-in system:auth-delegator ClusterRole to the reviewer service account. Do not give the reviewer anything more; it should not be able to read secrets or create pods.

Step 3: Write tightly bound roles

A role maps a set of service accounts to Vault policies and token settings. HashiCorp's example:

vault write auth/kubernetes/role/demo bound_service_account_names=myapp bound_service_account_namespaces=default policies=default audience=myapp ttl=1h

The binding parameters decide who can log in:

  • bound_service_account_names (required): service account names allowed to use the role. * allows all names.
  • bound_service_account_namespaces: namespaces allowed to use the role. * allows all namespaces.
  • bound_service_account_namespace_selector: a label selector for namespaces, in JSON or YAML. matchExpressions is not supported, and Vault needs permission to read namespaces. If you set this together with bound_service_account_namespaces, the two conditions are combined with OR, so either can grant access.
  • audience: the audience claim Vault verifies in the JWT.

Design rules we recommend:

  1. One role per application, named for it. A role called payments-api bound to payments-api in namespace payments is easy to review. A shared role for a whole team is not.
  2. No wildcards in both fields. A role with * for names and namespaces lets any pod in the cluster, including one a developer creates in a sandbox namespace, take the role's policies. A wildcard in names alone is acceptable only when the namespace is locked down and every workload in it should share the same access.
  3. Be careful with namespace selectors. Anyone who can label a namespace can then satisfy the selector. If your selector is team=payments, control who can set that label, and remember the OR behaviour if you also list namespaces.
  4. Set a distinct audience per role or per Vault cluster, for example vault-prod, and mount a projected token with that audience in the pod (Step 4).
  5. Attach the smallest policy set. Use token_policies; the older policies field is deprecated. Avoid attaching broad policies just to make a deployment work.

Token settings on the role

The role also controls the Vault token returned at login. The sample response in HashiCorp's documentation shows a lease_duration of 2,764,800 seconds, which is 32 days: that is what you get when you leave the lifetime to system defaults. Set it explicitly:

  • token_ttl: the incremental lifetime of the token. One hour or less suits most services, which can log in again with their pod token when needed.
  • token_max_ttl: the maximum lifetime, including renewals. Keep it at a small multiple of token_ttl, for example four to eight hours.
  • token_policies: the policies granted, as above.

Short Vault tokens matter because the pod token behind them is already short-lived and bound to the pod. A Vault token that outlives the pod by weeks undoes that benefit.

Alias names and identity

alias_name_source decides how Vault names the identity alias for the service account. The default, serviceaccount_uid, uses the machine-generated UID, which HashiCorp describes as the default and recommended, more secure option. The alternative, serviceaccount_name, uses namespace/name. HashiCorp advises using it only if you accept the risk or have strong controls over creating, deleting and accessing service accounts. The risk is simple: if someone deletes and re-creates a service account with the same name, a name-based alias maps the new account to the old Vault entity and whatever entity-level policies or group memberships it had.

Step 4: Give pods a short-lived, audience-bound token

The pod side is where most of the security benefit lands. HashiCorp notes that by default Kubernetes extends the lifetime of admission-injected service account tokens to a year to smooth the move to short-lived tokens. You can disable that with --service-account-extend-token-expiration=false on kube-apiserver, or mount your own serviceAccountToken projected volume.

A projected volume is the better choice for workloads that talk to Vault, because you set both the expiry and the audience:

  • Audience: set it to the same value as the role's audience, for example vault-prod. A token minted for the Kubernetes API, or for another service, then fails Vault's audience check.
  • Expiration: a short value such as 10 to 60 minutes. The kubelet rotates the file before expiry, so clients should re-read it rather than cache it at start-up.
  • Path: mount it at a dedicated path and point the client at it. HashiCorp's Go example uses auth.WithServiceAccountTokenPath to read a non-default path.

Also turn off the default token where the pod does not need to call the Kubernetes API. Pods that automount a token they never use widen the blast radius if the container is compromised; see How to find pods that automount service account tokens.

Finally, the login itself: an agent or sidecar, a client library or a direct API call all end with a POST to v1/auth/<mount>/login carrying role and jwt. Whatever client you use, make sure it re-authenticates when its Vault token expires instead of trying to stretch one token with renewals.

Step 5: Handle issuer validation and cluster upgrades

Kubernetes 1.21 changed the iss claim of mounted tokens, which can be specific to the cluster rather than the old kubernetes/serviceaccount. Vault 1.9.0 responded by not validating the issuer by default, because the Kubernetes API already does the same check during TokenReview. The disable_iss_validation and issuer parameters are now deprecated, and new mounts default to disable_iss_validation=true.

The catch is older mounts. Mounts created before Vault 1.9 keep the old default, and HashiCorp says you need to set disable_iss_validation=true explicitly before upgrading Kubernetes to 1.21. Check each mount with vault read -field disable_iss_validation auth/<mount>/config. If you have a reason to keep issuer validation, the issuer must match the API server's --service-account-issuer value, which most clusters publish at /.well-known/openid-configuration.

Add a Kubernetes auth check to your cluster upgrade runbook: confirm the reviewer credential still works, the issuer setting is correct and a test pod can log in before you move production workloads.

Step 6: Templated policies from service account annotations

Writing one policy per application does not scale for large estates. Kubernetes auth can feed service account annotations into Vault alias metadata, so a single templated policy can give each application its own path. Set use_annotations_as_alias_metadata=true on the config. Only annotations with the vault.hashicorp.com/alias-metadata- prefix are used, each value must be 512 characters or less, and Vault must be allowed to read service accounts from the Kubernetes API.

HashiCorp's worked example annotates a service account with vault.hashicorp.com/alias-metadata-env: demo/app and writes a policy that allows read on env-kv/data/{{identity.entity.aliases.<mount accessor>.metadata.env}}. The mount accessor, such as auth_kubernetes_bcecb1e1, comes from vault auth list.

The security trade-off is that the annotation now decides which secret path the workload reaches. Anyone who can edit that service account can point it at another team's path. If you use this pattern:

  • Restrict update and patch on service accounts to your deployment pipeline, not to developers directly.
  • Use admission policy to check that the annotation value matches the namespace, for example that a service account in payments can only carry a payments/ prefix.
  • Keep the templated path narrow, such as read-only on one KV subtree, rather than a broad prefix.

Logging, review and detection

Kubernetes auth gives you strong identity signals, so make sure you collect them. Every successful login returns metadata including service account name, namespace and UID, and Vault's audit device records the login request and the token accessor issued. Useful detections:

  • Logins for a role from a service account or namespace you did not expect, which usually points to a wildcard binding or a selector match.
  • A sudden rise in logins or permission-denied responses from one namespace, which may indicate a stolen pod token being tried against several roles.
  • Changes to auth/<mount>/config or auth/<mount>/role/* outside your change process.
  • On the Kubernetes side, creation of long-lived service account token secrets and new bindings to system:auth-delegator, both covered in our Kubernetes Audit Log Detection Guide.

Review roles at least quarterly with vault list auth/<mount>/role and vault read on each, looking for wildcards, missing audiences, long TTLs and policies that grew over time. Our guide on How to audit HashiCorp Vault tokens, policies and auth methods gives a fuller review method.

These controls map to MITRE ATT&CK T1552.007 Container API, where adversaries pull credentials from container platform APIs, and T1528 Steal Application Access Token, both of which describe ways a pod token can be taken and reused. On the control side they support NIST SP 800-53 AC-6 Least Privilege and IA-5 Authenticator Management.

Common failure patterns

  • Wildcard roles. bound_service_account_names=* and bound_service_account_namespaces=* on a role with real policies, often created during a proof of concept and never tightened.
  • Namespace selector plus a namespace list. Teams assume both must match, but the conditions are ORed, so the selector widens access.
  • Reviewer token stored and forgotten. A long-lived reviewer secret with no owner and no rotation, sometimes bound to more than system:auth-delegator.
  • Short-lived reviewer token that expires. A projected token pasted into token_reviewer_jwt works on day one and breaks every login when it expires or the source pod is deleted.
  • No audience. Roles without audience accept any valid token for the service account, including the default one used for Kubernetes API calls.
  • Default token lifetimes. Vault tokens left at a 32-day lease, far outliving the pod and its service account token.
  • Name-based aliases. alias_name_source=serviceaccount_name chosen for convenience, so a re-created service account inherits an old identity.
  • Old mounts missed on upgrade. Pre-1.9 mounts still validating the issuer, breaking logins after a Kubernetes upgrade.
  • Annotation-driven policies without guardrails. Templated policies whose annotations any namespace admin can change.

Practitioner checklist

  • One Kubernetes auth mount per cluster, with production and non-production separated.
  • Write access to auth/<mount>/config and auth/<mount>/role/* limited to Vault administrators and managed as code.
  • Reviewer credential is the Vault pod's local token or the client JWT; any long-lived reviewer secret has an owner and a rotation date.
  • Reviewer service account bound only to system:auth-delegator.
  • TLS to the API server verified with kubernetes_ca_cert or the local CA.
  • Every role names specific service accounts and namespaces, with no double wildcard.
  • Every role sets an audience, and pods mount a projected token with that audience and a short expiry.
  • token_ttl one hour or less and token_max_ttl set explicitly on each role.
  • alias_name_source left at serviceaccount_uid.
  • Pods that do not call the Kubernetes API have default token automounting disabled.
  • Issuer settings checked on every mount before each Kubernetes upgrade.
  • Vault audit device enabled, with alerts on role and config changes and on unexpected namespaces.
  • Quarterly role review recorded, with findings tracked to closure.

Standards and references

Related NHI Mgmt Group resources: HashiCorp Vault Guide · Kubernetes Service Account Token Guide · Kubernetes NHI Security Guide · How to authenticate GitHub Actions to HashiCorp Vault with JWT

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.