Ravindra BagaleCourses & study guides मराठी

Chapter 94: HashiCorp Vault and Secrets Management

DevOps

94.8 Policies — capabilities, default deny and least privilege

Story (fictional teaching scenario). At a fictional Jaipur shop, Elena from Berlin wants a web app to read one path but not edit prices or inspect other teams.

Policies — capabilities, default deny and least privilege
Policies — capabilities, default deny and least privilege

Why

A small path rule is easier to review than a broad wildcard permission.

What

  • Policy declares allowed or denied operations on paths, in HCL or JSON.
  • Capability is an operation such as read, create, update, patch, delete or list.
  • Default deny means an unmatched protected path is not allowed.
  • Explicit deny overrides grants on the matching rule.
  • Path matching has specificity rules; a glob is not a general regular expression.

How

  1. Start from the exact API path.

  2. Grant only the required capabilities.

  3. Test an allowed and a denied operation.

  4. Do not assume read on data also grants list on metadata.

Example 1: One read rule

  1. Read the command or request.
path "secret/data/shop" {
  capabilities = ["read"]
}
  1. Read the result.

Output (illustrative; NOT executed against Vault)

Read shop: permitted by this rule.
Update shop: not granted.
Read other: not granted.
  1. Line by line: path names the v2 data endpoint without /v1/. capabilities is a list even for one operation. The token’s complete policy set and Vault matching rules determine the final result; the local model later supports exact paths only.

Example 2: List is separate

  1. Read the command or request.
path "secret/metadata/team/" {
  capabilities = ["list"]
}
  1. Read the result.

Output (illustrative; NOT executed against Vault)

List response can include key names, not their values.
  1. Line by line: KV v2 listing uses the metadata prefix. Returned names are not individually filtered by secret-read permissions. Do not put personal information or secret values in key names.

Example 3: Check policy requirements without granting more

  1. Read the command or request.
vault kv get -mount=secret -output-policy shop
  1. Read the result.

Output (illustrative; NOT executed against Vault)

Policy requirement includes read on secret/data/shop.
  1. Line by line: -output-policy asks the CLI to display the required policy rather than perform the normal operation, where supported. Consult the installed CLI help. No permission is changed by reading a requirement.

Ravindra Bagale's Tip

Do not fix permission denied with a root token in the application.

Did you understand? Let us try it once more.