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
In a nutshell
  • Choose the narrowest paths and fewest capabilities that meet the requirement.
  • vault policy write, list, read and delete manage policies in the CLI.
  • The API path is sys/policies/acl/:name with a policy field.

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.

RequirementtranslatePaths and capabilitiesvault policy writeStored policyStored policyattached toToken or roletested withtoken capabilities

How it works

Reading a requirement

Ask three questions: which paths, which operations, and anything to block. Then give only that.

RequirementPolicy that fits
App reads one secret pathread on that exact path
App reads everything under a prefixread on prefix/*
App browses keys under a prefixadd list on the prefix
Team members each get their own areaA templated path using {{identity.entity.id}}
Everyone except one sub pathBroad grant plus deny on the exact sub path
Administrator seals Vaultsudo 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

ActionRequest
List policiesLIST /sys/policies/acl
Read a policyGET /sys/policies/acl/:name
Create or updatePOST /sys/policies/acl/:name with {"policy": "<HCL string>"}
DeleteDELETE /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/config and nothing else." Choose the policy with read on 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, read and delete manage policies in the CLI.
  • The API path is sys/policies/acl/:name with a policy field.
  • A policy must be attached to a token, role, user, entity or group to matter.
  • Use vault token capabilities to test a result.
  • A policy that does not cover a path leaves that path denied.
Watch out

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 myapp but not read values. Which capability?

    Only list, applied to the prefix being listed, with no read.

  • How do you confirm what a token may do on secret/data/myapp/db?

    Run vault token capabilities secret/data/myapp/db with that token, which prints the capabilities or deny.

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.