Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VAULT-3519] Return no_default_policy on token role read #12565

Merged
merged 6 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/12565.txt
@@ -0,0 +1,3 @@
```release-note:improvement
core/token: Return the token_no_default_policy config on token role read if set
```
4 changes: 4 additions & 0 deletions vault/token_store.go
Expand Up @@ -3208,6 +3208,10 @@ func (ts *TokenStore) tokenStoreRoleRead(ctx context.Context, req *logical.Reque
resp.Data["token_num_uses"] = role.TokenNumUses
}

if role.TokenNoDefaultPolicy {
resp.Data["token_no_default_policy"] = true
pmmukh marked this conversation as resolved.
Show resolved Hide resolved
}

return resp, nil
}

Expand Down
27 changes: 19 additions & 8 deletions vault/token_store_test.go
Expand Up @@ -3211,12 +3211,13 @@ func TestTokenStore_RoleCRUD(t *testing.T) {
// automatically due to the existence check
req.Operation = logical.CreateOperation
req.Data = map[string]interface{}{
"period": "79h",
"allowed_policies": "test3",
"path_suffix": "happenin",
"renewable": false,
"explicit_max_ttl": "80h",
"token_num_uses": 0,
"period": "79h",
"allowed_policies": "test3",
"path_suffix": "happenin",
"renewable": false,
"explicit_max_ttl": "80h",
"token_num_uses": 0,
"token_no_default_policy": true,
}

resp, err = core.HandleRequest(namespace.RootContext(nil), req)
Expand Down Expand Up @@ -3263,6 +3264,10 @@ func TestTokenStore_RoleCRUD(t *testing.T) {
}
delete(resp.Data, "token_bound_cidrs")

if resp.Data["token_no_default_policy"].(bool) != true {
t.Fatal("unexpected no_default_policy config")
}
delete(resp.Data, "token_no_default_policy")
if diff := deep.Equal(expected, resp.Data); diff != nil {
t.Fatal(diff)
}
Expand Down Expand Up @@ -3313,15 +3318,21 @@ func TestTokenStore_RoleCRUD(t *testing.T) {
}
delete(resp.Data, "token_bound_cidrs")

if resp.Data["token_no_default_policy"].(bool) != true {
t.Fatal("unexpected no_default_policy config")
}
delete(resp.Data, "token_no_default_policy")

if diff := deep.Equal(expected, resp.Data); diff != nil {
t.Fatal(diff)
}

// Update path_suffix and bound_cidrs with empty values
req.Operation = logical.CreateOperation
req.Data = map[string]interface{}{
"path_suffix": "",
"bound_cidrs": []string{},
"path_suffix": "",
"bound_cidrs": []string{},
"token_no_default_policy": false,
}
resp, err = core.HandleRequest(namespace.RootContext(nil), req)
if err != nil || (resp != nil && resp.IsError()) {
Expand Down