Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for HashiCorp Vault Difficulty: Advanced ClaudeChatGPT

Vault Kubernetes Auth Setup and Troubleshooting Prompt

Stand up HashiCorp Vault Kubernetes auth end to end — TokenReview permissions, audience binding, roles and policies — and systematically diagnose the permission-denied and invalid-claim failures that block pod logins.

Target user
Platform engineers running HashiCorp Vault alongside Kubernetes
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior platform engineer who has wired Vault Kubernetes auth into clusters in every topology — Vault in-cluster, Vault external, and Vault serving many clusters — and can read a login failure and name the cause.

I will provide:
- Where Vault runs relative to the cluster (in-cluster, external, one Vault serving N clusters) and both versions
- The current `vault read auth/kubernetes/config` output and the role definition
- The workload's namespace, ServiceAccount, and how its token is projected
- The exact error text and, if I have it, the Vault server log line and audit entry for the failed login

Your job:

1. **Choose the verification mode first.** Explain the two ways Vault validates a pod's ServiceAccount JWT: calling the cluster's TokenReview API (requires a reviewer identity with the `system:auth-delegator` ClusterRole and network reachability to the API server), or validating the JWT offline against the cluster's public keys using `disable_local_ca_jwt` plus configured issuer and JWKS material. Recommend one for my topology and say what each costs operationally.

2. **Configure the auth mount correctly.** Give me the exact commands for `vault auth enable kubernetes` and `vault write auth/kubernetes/config`, covering `kubernetes_host`, `kubernetes_ca_cert`, and — where TokenReview is used from outside the cluster — `token_reviewer_jwt`. Explain that a `token_reviewer_jwt` bound to a short-lived projected token will expire and break every login later, and give the durable alternative.

3. **Define the role with real binding.** Show `vault write auth/kubernetes/role/<name>` with `bound_service_account_names`, `bound_service_account_namespaces` (and `bound_service_account_namespace_selector` where supported), `audience`, `token_policies`, `token_ttl`, and `token_max_ttl`. Insist on naming specific ServiceAccounts and namespaces — treat `bound_service_account_names="*"` as a finding, not a shortcut.

4. **Get audience binding right.** Explain how the `audience` on the Vault role must match the `audience` in the pod's projected ServiceAccount token volume, show the pod spec fragment for a projected token with an explicit audience and short `expirationSeconds`, and describe the mismatch symptom precisely.

5. **Walk the failure decision tree.** For each classic error, give the cause and the check: TokenReview `permission denied` (missing `system:auth-delegator` binding, or a reviewer JWT that has expired); `service account name not authorized` (role bindings don't include this SA or namespace); invalid `iss` claim (issuer mismatch between the cluster's actual issuer and what Vault expects); `invalid audience`; x509 or TLS errors reaching the API server or reaching Vault; and a login that succeeds but every subsequent read is denied (the role's policies are wrong, not the auth).

6. **Prescribe the diagnostic commands in order.** Read the auth config and role back, confirm the reviewer identity's RBAC, decode the pod's projected token claims to compare `iss`, `aud`, `sub`, and expiry against the role, then attempt a login from inside the pod with the actual token and capture the full error. Include checking the Vault audit log for the login attempt, since the client-side message is often less specific than the server's.

7. **Design multi-cluster cleanly.** For one Vault serving several clusters, recommend a separate Kubernetes auth mount per cluster with distinct mount paths, explain why sharing one mount across clusters is fragile, and cover the policy and entity-alias implications of per-mount accessors.

8. **Specify how the workload consumes the token.** Compare the Vault Agent Injector, the Vault Secrets Operator, and the Secrets Store CSI driver for this workload: what each writes where, how renewal works, restart-on-rotation behavior, and which one keeps the secret out of the container image and off durable disk. Recommend one and give the annotations or CR outline.

Output as: (a) the topology decision and why, (b) the exact auth enable/config/role commands, (c) the pod spec fragment with the projected token and matching audience, (d) an error-to-cause-to-fix table for the failures above, (e) the ordered diagnostic command list, (f) the consumption-mechanism recommendation.

Do not resolve TLS or certificate errors by disabling verification, and do not resolve claim-validation errors by turning validation off — fix the CA bundle, the issuer, or the audience. Keep `token_ttl` short and let the client re-authenticate rather than issuing long-lived tokens to avoid renewal work.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Why this prompt works

Kubernetes auth failures all surface as some variation of “permission denied”, and the causes behind that string are unrelated to each other. Choosing the verification mode first is what makes the rest diagnosable: TokenReview means Vault must reach the API server and hold a reviewer identity with system:auth-delegator, while offline JWKS validation means Vault needs the issuer and public keys and no network path at all. Those two topologies fail in entirely different places, so establishing which one you are in converts a vague error into a short list of things to check.

The token_reviewer_jwt warning is called out specifically because it is a delayed failure, and delayed failures are the ones that get misdiagnosed. Setup works, logins succeed for weeks, and then every pod in the cluster stops authenticating at once — because the reviewer JWT was copied from a short-lived projected token that has now expired. Nothing changed in the deployment that day, so the investigation starts in the wrong place. Naming the trap and requiring the durable alternative saves an outage that looks, from the client side, exactly like a Vault problem.

The error-to-cause-to-fix table and the ordered diagnostic sequence exist because the client-side message is systematically less informative than what Vault logged. Decoding the pod’s projected token to compare iss, aud, and sub against the role definition resolves most claim mismatches in one step, and checking the audit log catches the rest. The closing constraint does the security work: disable_local_ca_jwt, skipping TLS verification, and turning off issuer validation all make a failing login succeed, which is precisely why they are so tempting under deadline — and each one removes the check the auth method exists to perform, leaving something that authenticates everyone equally well.

Related prompts

More HashiCorp Vault prompts & error guides

Browse every HashiCorp Vault prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.