I have no permission to access the tokens if the secret is located at secret/username1234. However, if I change the path to secret/* I get access. Is this intentional?
Could policy path templates be the solution to my problem here? Unfortunately I don’t know which field could be the best substitute since many fields are n/a for batch tokens.
Yes because secret/username1234 literally does not match secret/username1234/* - it does not have a slash after username1234 like the pattern requires.
Hi max, thanks for the information. I believe I have to clarify my initial post. When I said that the secret is located at secret/username1234 I didn’t share the full secret path. The full secret path is secret/username1234/foo and the secret data is key-test=value-test.
Here is the order of commands of a newly created docker image, with the policy from above:
In a new terminal, I log in with the new printed token:
$ export VAULT_ADDR='http://0.0.0.0:8200'
$ vault login # with the new token
$ vault kv get -mount=secret username1234/foo
Error making API request.
URL: GET http://0.0.0.0:8200/v1/sys/internal/ui/mounts/secret
Code: 403. Errors:
* preflight capability check returned 403, please ensure client's policies grant access to path "secret/"
Any idea what I am doing wrong?
Regarding the policy path templates, it is slightly unrelated to the original problem but it is related to the topic. Instead of creating plenty of policies for each users, I prefer to have a single policy that restricts batch tokens to its username path.
First, you have not actually applied the policy you intended to, to the batch token.
You have shown the exact commands you used - this is great for clearing up confusion! - but you haven’t shown the output produced. When I attempt to replicate your commands, I get different results. Had you actually granted the token you used to make the last request access to anything within secret/, you would get a different error message.
Second, even if you had applied that policy, it still would not have worked - the policy you have is appropriate for a KV v1, but it is now clear you are working with a KV v2. The KV v2 secret engine inserts an extra URL path segment between the mount point, and the internal path to the secret. Please refer to a previous reply I wrote on this subject, here: Policies not working on more levels. OICD Auth - #2 by maxb
Thanks a lot! I completely missed that the secret path is secret/data/username1234/foo and not secret/username1234/foo. If I adjust the policy and add data/ as well then it works. As feedback, the UI doesn’t display the data/ component, so that’s why I didn’t notice.
Btw, you said:
First, you have not actually applied the policy you intended to, to the batch token.
Isn’t this what I did with vault token create ... -policy=my_policy? To me it looks this policy is attached to the batch token.