Vault Policies · Topic 2 of 3

Policy Syntax, Paths and Capabilities

Vault Associate (003): write policy path blocks, use the * glob and + segment wildcard correctly, and pick capabilities such as read, list, sudo and deny.

  • 4 min
In a nutshell
  • Policy blocks have a path and a capabilities list.
  • * is a prefix glob allowed only at the end; + matches one segment.
  • The most specific path wins, and exact beats glob.

What it is

A policy is written in HCL as one or more path blocks. Each block names a path and lists the capabilities allowed on it.

path "secret/data/app/web" {
  capabilities = ["read"]
}

The path says where the rule applies. The capabilities say which operations are permitted there.

Requestpath and operationmatched againstPolicy path blocksmost specific winsCapabilitiesallow or denyResult

How it works

Path matching

PatternMeaning
secret/fooMatches exactly secret/foo
secret/bar/*Glob: prefix match, so secret/bar/zip and secret/bar/zip/zap, but not secret/bars/zip
secret/+/teambThe + matches exactly one path segment

The * glob is not a regular expression and is supported only as the last character of the path. The + wildcard works within a single segment and can be used more than once.

Worked example

path "secret/data/app/*" {
  capabilities = ["read"]
}
path "secret/data/app/admin" {
  capabilities = ["deny"]
}
path "secret/data/+/db-*" {
  capabilities = ["read"]
}
Request pathResultReason
secret/data/app/webRead allowedMatches the first block
secret/data/app/adminDeniedThe exact path is more specific and says deny
secret/data/team/db-prodRead allowed+ matches team, and db-* matches db-prod
secret/data/team/x/db-prodDenied+ covers only one segment, so nothing matches
secret/data/hr/salariesDeniedNo block matches, and Vault is deny by default

Which rule wins

The most specific matching path wins. That is either an exact match or the longest prefix glob. If different patterns match, only the highest priority one applies.

If the same pattern appears in several policies, their capabilities are combined. A wildcard earlier in the path gives lower priority, and a path ending in * ranks below one that does not.

Capabilities

CapabilityHTTP verbMeaning
createPOST or PUTCreate data at a path
readGETRead data at a path
updatePOST or PUTChange data at a path
patchPATCHPartially update data
deleteDELETEDelete data at a path
listLISTList keys at a path
sudononeAccess root protected paths
denynoneBlock access, overriding every other capability
subscribenoneSubscribe to events for the path

Capabilities usually map to the HTTP verb and not to the action behind it. Generating database credentials is a GET, so it needs read. Very few parts of Vault distinguish create from update, so most operations need both.

Special capabilities

sudo is needed, together with the usual capabilities, for root protected paths such as sys/seal, sys/audit and sys/raw. A token cannot seal Vault without sudo on sys/seal.

deny always takes precedence, including over sudo. Use it to carve an exception out of a broader rule.

list works on prefixes. For a KV v2 mount at secret/, secret values live under secret/data/ and keys are listed under secret/metadata/, so write the policy for the path you are actually calling.

The keys a list returns are not filtered by policy, so do not put sensitive information in key names. Not all backends support listing.

Path constraints

Parameter constraints refine a block. required_parameters, allowed_parameters and denied_parameters restrict which request parameters are accepted, and the path's capabilities still apply first. denied_parameters takes precedence over allowed_parameters.

How the exam asks about this

  • "Which request paths does secret/+/cfg_* allow?" Count segments: + matches exactly one segment, then cfg_ followed by anything.
  • "A token must read secrets but never change them." Grant read only.
  • "Which capability is needed to seal Vault?" sudo on sys/seal.

What to remember for the exam

  • Policy blocks have a path and a capabilities list.
  • * is a prefix glob allowed only at the end; + matches one segment.
  • The most specific path wins, and exact beats glob.
  • The core capabilities are create, read, update, patch, delete, list, sudo and deny.
  • Capabilities usually follow the HTTP verb, not the underlying action.
  • deny overrides all other capabilities, even sudo.
Watch out

+ never spans a slash. A path with an extra segment, like secret/data/team/x/db-prod above, does not match secret/data/+/db-*.

Common mistakes

Putting * in the middle of a path. A glob works only as the last character. Use + when you need to match a whole segment in the middle.

Granting read and expecting to list. Listing is a separate list capability, applied to the prefix being listed.

Assuming deny and allow merge. If a more specific block says deny, that path is blocked even when a broader block grants access.

Check yourself

  • Does secret/bar/* match secret/bar/zip/zap?

    Yes, a trailing glob is a prefix match, so it covers everything below secret/bar/.

  • Which capability beats all others on a path?

    deny, which takes precedence over every other capability including sudo.

  • What does + match in secret/+/teamb?

    Exactly one path segment, such as the dev in secret/dev/teamb.

Topic 2 of 3 in Vault Policies

Test yourself on Vault Policies

The full HashiCorp Vault Associate 003 question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by HashiCorp. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.