Vault Policies · Topic 3 of 3
Choosing and Configuring Policies in the UI and CLI
Vault Associate (003): pick the right policy for a requirement, then write, list, read, test and delete ACL policies with the CLI, API and UI.
- 4 min
- Choose the narrowest paths and fewest capabilities that meet the requirement.
vault policy write,list,readanddeletemanage policies in the CLI.- The API path is
sys/policies/acl/:namewith apolicyfield.
What it is
Choosing a policy means reading a requirement and finding the one with the right paths and the fewest capabilities that satisfy it. Configuring a policy means getting that HCL into Vault and attaching it to a token or role.
How it works
Reading a requirement
Ask three questions: which paths, which operations, and anything to block. Then give only that.
| Requirement | Policy that fits |
|---|---|
| App reads one secret path | read on that exact path |
| App reads everything under a prefix | read on prefix/* |
| App browses keys under a prefix | add list on the prefix |
| Team members each get their own area | A templated path using {{identity.entity.id}} |
| Everyone except one sub path | Broad grant plus deny on the exact sub path |
| Administrator seals Vault | sudo on sys/seal plus the needed capability |
For KV v2 secrets, remember the data/ and metadata/ parts of the path.
Worked example
Requirement: an app may read and list keys under myapp on a KV v2 mount at secret/, and nothing else.
path "secret/data/myapp/*" {
capabilities = ["read"]
}
path "secret/metadata/myapp/*" {
capabilities = ["list"]
}
The first block lets the app read values below secret/data/myapp/. The second lets it list keys below secret/metadata/myapp/. A request to secret/data/other/db matches neither, so it is denied.
Adding create or update would be wrong here, since the app never writes. The extra power would cost nothing today and risk much later.
Configure with the CLI
vault policy write myapp-read myapp-read.hcl
vault policy list
vault policy read myapp-read
vault token create -policy=myapp-read
vault token capabilities secret/data/myapp/db
vault policy delete myapp-read
vault policy write NAME FILE uploads the policy, and - as the file reads from standard input. vault policy list shows every policy, including default and root. vault policy fmt formats a policy file.
vault token capabilities PATH shows what your current token can do on a path. With the token above, it prints read for secret/data/myapp/db. A path the policy does not cover prints deny.
Configure with the API
| Action | Request |
|---|---|
| List policies | LIST /sys/policies/acl |
| Read a policy | GET /sys/policies/acl/:name |
| Create or update | POST /sys/policies/acl/:name with {"policy": "<HCL string>"} |
| Delete | DELETE /sys/policies/acl/:name |
Changes apply immediately to everything using the policy.
Configure with the UI
Open the policies area, choose Create ACL policy, enter a name, paste or upload the HCL, and select Create Policy. Selecting a policy name later shows its contents.
The UI also has a CLI shell, so vault write auth/token/create policies=myapp-read works there too.
Attaching a policy
A policy does nothing until it is attached. Attach it to a userpass user, to an auth method role such as an AppRole, to a token at creation, or to an entity or group.
How the exam asks about this
- "An application must read
secret/data/app/configand nothing else." Choose the policy withreadon that exact path. - "Which command uploads a policy file?"
vault policy write NAME FILE. - "How do you check what a token can do on a path?"
vault token capabilities.
What to remember for the exam
- Choose the narrowest paths and fewest capabilities that meet the requirement.
vault policy write,list,readanddeletemanage policies in the CLI.- The API path is
sys/policies/acl/:namewith apolicyfield. - A policy must be attached to a token, role, user, entity or group to matter.
- Use
vault token capabilitiesto test a result. - A policy that does not cover a path leaves that path denied.
Token creation with -policy attaches the named policies plus default, unless you opt out of default. Do not assume a token has only the policy you named.
Common mistakes
Forgetting the KV v2 path. A policy for secret/myapp/* does not cover secret/data/myapp/*. Match the path that the API actually calls.
Writing a policy and not attaching it. Storing it makes it available, but no token has it until you attach it to a user, role, token, entity or group.
Granting only create or only update for a write. Very few parts of Vault distinguish them, so most write operations need both. Check the path's documentation when a path does treat them differently.
Check yourself
Which command uploads an HCL file as a policy named
ops?vault policy write ops FILE, where FILE is the path of the HCL file.A requirement says the app can list keys under
myappbut not read values. Which capability?Only
list, applied to the prefix being listed, with noread.How do you confirm what a token may do on
secret/data/myapp/db?Run
vault token capabilities secret/data/myapp/dbwith that token, which prints the capabilities ordeny.
Topic 3 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.