hi,
I am learning hashicorp vault and realised the cli and api bejavious is different when creating tokens. For instance:
$ vault token create -policy=devops-ws/gitlab/tds/secret
Key Value
--- -----
token s.tB1kPOEQ2NpeqYhQJSCuyCRv
token_accessor 1ISxMpxdU4NOiRFEv8rhnooZ
token_duration 768h
token_renewable true
token_policies ["default" "devops-ws/gitlab/tds/secret"]
identity_policies []
policies ["default" "devops-ws/gitlab/tds/secret"]
$ vault token lookup s.tB1kPOEQ2NpeqYhQJSCuyCRv
Key Value
--- -----
accessor 1ISxMpxdU4NOiRFEv8rhnooZ
creation_time 1633716193
creation_ttl 768h
display_name token
entity_id n/a
expire_time 2021-11-09T18:03:13.137257188Z
explicit_max_ttl 0s
id s.tB1kPOEQ2NpeqYhQJSCuyCRv
issue_time 2021-10-08T18:03:13.137270207Z
meta <nil>
num_uses 0
orphan false
path auth/token/create
policies [default devops-ws/gitlab/tds/secret]
renewable true
ttl 767h59m45s
type service
So I created a token and assigned it to the policy devops-ws/gitlab/tds/secret
Now I am going to attempt the same through api
$ cat create_token.json
{
"policies": ["devops-ws/gitlab/tds/secret"],
"ttl": "1h",
"renewable": true
}
$ curl --silent -X POST \
> -d create_token.json \
> $VAULT_ADDR/v1/auth/token/create \
> -H "X-Vault-Token: "$VAULT_ROOT_KEY
{"request_id":"d4905243-517c-16ae-fca0-ee847f054cc3","lease_id":"","renewable":false,"lease_duration":0,"data":null,"wrap_info":null,"warnings":null,"auth":{"client_token":"s.u0zfTQAbCVOOdzneuUuH7FLK","accessor":"NzdWSxLRuinBCWCUXTsaUF8u","policies":["root"],"token_policies":["root"],"metadata":null,"lease_duration":0,"renewable":false,"entity_id":"","token_type":"service","orphan":false}}
$ vault token lookup s.u0zfTQAbCVOOdzneuUuH7FLK
Key Value
--- -----
accessor NzdWSxLRuinBCWCUXTsaUF8u
creation_time 1633716240
creation_ttl 0s
display_name token
entity_id n/a
expire_time <nil>
explicit_max_ttl 0s
id s.u0zfTQAbCVOOdzneuUuH7FLK
issue_time 2021-10-08T18:04:00.757031672Z
meta <nil>
num_uses 0
orphan false
path auth/token/create
policies [root]
renewable false
ttl 0s
type service
In this case the API ignores the content of the payload.
What is the reason behind this behavior?
thank you