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
- Policy blocks have a
pathand acapabilitieslist. *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.
How it works
Path matching
| Pattern | Meaning |
|---|---|
secret/foo | Matches exactly secret/foo |
secret/bar/* | Glob: prefix match, so secret/bar/zip and secret/bar/zip/zap, but not secret/bars/zip |
secret/+/teamb | The + 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 path | Result | Reason |
|---|---|---|
secret/data/app/web | Read allowed | Matches the first block |
secret/data/app/admin | Denied | The exact path is more specific and says deny |
secret/data/team/db-prod | Read allowed | + matches team, and db-* matches db-prod |
secret/data/team/x/db-prod | Denied | + covers only one segment, so nothing matches |
secret/data/hr/salaries | Denied | No 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
| Capability | HTTP verb | Meaning |
|---|---|---|
create | POST or PUT | Create data at a path |
read | GET | Read data at a path |
update | POST or PUT | Change data at a path |
patch | PATCH | Partially update data |
delete | DELETE | Delete data at a path |
list | LIST | List keys at a path |
sudo | none | Access root protected paths |
deny | none | Block access, overriding every other capability |
subscribe | none | Subscribe 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, thencfg_followed by anything. - "A token must read secrets but never change them." Grant
readonly. - "Which capability is needed to seal Vault?"
sudoonsys/seal.
What to remember for the exam
- Policy blocks have a
pathand acapabilitieslist. *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.
denyoverrides all other capabilities, evensudo.
+ 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/*matchsecret/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 includingsudo.What does
+match insecret/+/teamb?Exactly one path segment, such as the
devinsecret/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.