3

I created a user with a policy:

$ vault token create -renewable -policy=admin_policy    Key                  Value
---                  -----
token                s.kG0Kdb8d2DSOUHv3AMzw5tdO
token_accessor       Do57Fg9DpiMv1j6t3oysZoz9
token_duration       900h
token_renewable      true
token_policies       ["admin_policy" "default"]
identity_policies    []
policies             ["admin_policy" "default"]

And now I want to add policy to the token. How should I do it?

Or I created user:

vault write auth/userpass/users/test3 password=test -policy=admin_policy
Success! Data written to: auth/userpass/users/test3

And now I want add a policy to the user:

vault write auth/userpass/users/test3 password=test -policy=admin_policy -policy=crm_sales_policy
Success! Data written to: auth/userpass/users/test3

But nothing has changed.

Mahmoud Abdelsattar
  • 1,299
  • 1
  • 15
  • 31
Dmitriy Gr
  • 33
  • 1
  • 3

2 Answers2

4

At first I was also confusing about how to update policies on user, but I found the document has been updated, the API is /auth/userpass/users/:username/policies, so you can update the policies like this:

vault write auth/userpass/users/bob123/policies policies="foo,bar"

official reference

Winkee
  • 51
  • 3
1

You can't add policy to an existing token.

So you would have to create a new token with said policy(or policies).

Generally it's better if your upstream auth source(say LDAP, etc) would handle assigning policies to users, but you are welcome to do it at the vault level too.

Also note, tokens are tied to their parent, so they expire when their parent token expires, unless you add -orphan

Tokens generally should not have a very long life. Vault's claim to fame here is that secrets and tokens should be short-lived, so that if they do leak, the harm is minimal.

zie
  • 710
  • 4
  • 7
  • 1
    can i use the userpass? and add policies for the user? Or will I also have to recreate user every time? – Dmitriy Gr Mar 29 '21 at 11:41
  • Yes, userpass is fine. yes add policies for users with the userpass backend, no problem. Recreate user ever time? I don't understand this. – zie Apr 06 '21 at 15:57
  • How to add new user? Update policies of existing? Can you add some code to your answers please? – VityaSchel Mar 30 '22 at 11:02