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: Intermediate ClaudeChatGPT

Vault Least-Privilege Policy Design Prompt

Turn a set of plain-English access requirements into reviewed HashiCorp Vault policy HCL that grants the minimum capabilities on the minimum paths, with templated paths for multi-tenant scoping.

Target user
Platform and security engineers running HashiCorp Vault
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior secrets-platform engineer who writes Vault policies for a living and has learned that every extra capability and every `*` eventually becomes an incident.

I will provide:
- The access requirements in plain English (who needs what, for which app/team/environment)
- The mounts involved and their types (kv-v2, database, pki, transit, ssh) and mount paths
- How the identities authenticate (Kubernetes SA, AppRole, JWT/OIDC, cloud IAM) and what metadata their entity aliases carry
- My Vault version and whether I'm on Community or Enterprise

Your job — build the smallest policy that satisfies the requirement:

1. **Restate each requirement as a path + capability matrix.** Before writing HCL, produce a table of subject, exact API path, and the capabilities needed (`create`, `read`, `update`, `patch`, `delete`, `list`, `sudo`, `deny`). Force me to justify anything beyond `read`. Call out that `list` leaks key names even without `read`, and that `deny` always wins over any other rule.

2. **Map logical secrets to real API paths.** Translate CLI-shaped thinking into the actual paths policies match on — for kv-v2 that means `secret/data/<path>` for values, `secret/metadata/<path>` for listing/versions/deletion, and the separate `secret/delete/`, `secret/undelete/`, `secret/destroy/` endpoints. Flag the classic mistake of writing a policy against `secret/<path>` on a v2 mount and wondering why it does nothing.

3. **Write the policy HCL.** Emit complete, paste-ready policies with a comment above each stanza saying which requirement it satisfies. Prefer exact paths; use the single-level `+` wildcard over a trailing `*` where it's enough; never use a bare `path "*"`. Use `patch` instead of `update` where the caller only needs to merge fields into an existing kv-v2 secret.

4. **Scope multi-tenancy with templated policies instead of one policy per team.** Show templated paths using `{{identity.entity.id}}`, `{{identity.entity.aliases.<mount_accessor>.name}}`, or `{{identity.entity.metadata.<key>}}`, and tell me exactly how to get the `mount_accessor` (`vault auth list -detailed`). Explain the failure mode where a templated policy silently matches nothing because the metadata key is absent.

5. **Constrain the request body, not just the path.** Where the endpoint takes parameters that change the blast radius, use `required_parameters`, `allowed_parameters`, and `denied_parameters` — for example pinning `ttl` on a PKI issue endpoint or denying `common_name` values outside a set. Note that parameter constraints only apply to write-style operations.

6. **Decide token attachment and TTLs.** Recommend whether the policy is attached via the auth role's `token_policies` or via an identity group, and set `token_ttl`/`token_max_ttl` on the role to match the workload's real session length. Prefer short TTLs with renewal over long-lived tokens; recommend batch tokens where the workload is high-volume and doesn't need renewal or lease tracking.

7. **Prove it before shipping.** Give me the verification steps: `vault policy write` into a non-production namespace or mount, mint a token with only that policy (`vault token create -policy=<name>`), then run both the operations that must succeed and the ones that must fail. Include `vault token capabilities <token> <path>` as the fast check, and remind me that a passing test on a root-token session proves nothing.

8. **Note the Enterprise-only escape hatches** if I'm licensed — Sentinel EGP/RGP policies and Control Groups for dual-authorization on sensitive paths — but design the Community-edition solution first and treat these as additive.

Output as: (a) the requirement-to-path-and-capability table, (b) the complete policy HCL with per-stanza comments, (c) the auth-role or identity-group binding with TTLs, (d) a positive/negative test plan with exact commands, (e) a short list of the capabilities you deliberately did NOT grant and what would have to change to justify them.

Never grant `sudo` or root-equivalent capability to solve a permission error — diagnose the actual missing path first. If a requirement can only be met with a broad wildcard, say so explicitly and propose a narrower redesign rather than quietly widening the policy.

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

Writing the capability matrix before the HCL is what keeps policies small. Going straight to HCL means starting from a template someone else wrote, which arrives pre-loaded with capabilities the requirement never asked for. Restating each requirement as subject, exact path, and capability list forces a justification for anything past read, and surfaces the two facts people design around rather than with: list exposes secret key names even where read is denied, and deny beats every other matching rule regardless of specificity.

The path-mapping step targets the single most common Vault policy bug. Operators think in vault kv get secret/myapp and write a policy against secret/myapp, which on a kv-v2 mount matches nothing at all, because values live at secret/data/myapp and listing and version operations live under secret/metadata/. The symptom is a policy that appears correct and grants nothing, and the usual response is to widen it until something works — often all the way to a trailing wildcard. Naming the mistake explicitly short-circuits that loop, and separating delete, undelete, and destroy makes destructive capability a deliberate grant rather than a side effect.

Templated policies and the verification step handle scale and proof respectively. One policy per team is where multi-tenant Vault installations go to die, so the prompt pushes identity-templated paths and calls out the failure where a missing metadata key makes the template match nothing silently. And the test plan matters because the obvious way to verify a policy is to try it while still holding an admin session, which proves only that root works — minting a token carrying only the new policy and running both the must-succeed and must-fail operations is the difference between a tested policy and an assumed one. Asking for the capabilities deliberately withheld gives the next reviewer the reasoning, so the policy does not quietly grow the first time someone hits a 403.

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.