Hi Vault community,
Forgive me as I am very new to vault and have only to this point built a failover cluster Vault environment with a consul backend (yes I know this is now no longer required) deployed using terraform and ansible on a vsphere environment using CI/CD.
Now I am at the point of learning how to actually use Vault. However, I am a bit confused about vault paths and wondering if someone could clarify how wildcards work in policies and PUT operations?
I set up a test on my vault environment:
# vault secrets enable -path=ops/data/vault-test/* kv
I then created a policy:
# vault policy write vault-test - <<EOF
path "ops/data/vault-test/*" {
capabilities = ["create", "read", "update", "patch", "delete", "list"]
}
I then created a role:
# vault write auth/jwt/role/vault-test - <<EOF > {
> "role_type": "jwt",
> "policies": ["vault-test"],
> "token_explicit_max_ttl": 60,
> "user_claim": "user_email",
> "bound_claim_type": "glob",
> "bound_claims": {
> "project_id": "42",
> "ref_protected": "true",
> "ref_type": "tag",
> "ref": "auto-deploy-*"
> }
> }
> EOF
and then set a token to use that role:
# export VAULT_TOKEN="$(vault token create -field token -policy=vault-test)"
Then I tried to create a secret in kv using that path:
# vault kv put -mount=ops/data/vault-test/secret kv test_secret=password123
Error making API request.
URL: GET https://127.0.0.1:8200/v1/sys/internal/ui/mounts/ops/data/vault-test/secret
Code: 403. Errors:
* preflight capability check returned 403, please ensure client's policies grant access to path "ops/data/vault-test/secret/"
It was my belief that “ops/data/vault-test/secret/” would be acceptable since there is a wildcard in the policy and the path would be created.
Even odder, this works hence my confusion:
# vault kv put -mount=ops/data/vault-test/* kv test_secret=password123
Success! Data written to: ops/data/vault-test/*/kv
It’s taking the wildcard literally!
Can someone please explain is this a bug or a misunderstanding? How is a wildcard supposed to work? Or should I be using a /+/ there instead?
Also, what are the best practices around setting paths? My intuition tells me that I should set something like:
/<project or department>/<application>/<environment>/<what-it-is (secret etc)>/
Or should you put what it is at the beginning i.e beginning with /kv/?
Thanks
Andy