Skip to content

Commit

Permalink
allowed/disallowed_policies as TypeCommaStringSlice (#3641)
Browse files Browse the repository at this point in the history
Our docs apparently claim that this is a list, but the code is
string-only. This fixes that discrepancy.
  • Loading branch information
jefferai committed Dec 4, 2017
1 parent 291edb9 commit ee89aa1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
## 0.9.1 (Unreleased)

DEPRECATIONS/CHANGES:

* Token Auth Backend Roles parameter types: For `allowed_policies` and
`disallowed_policies` in role definitions in the token auth backend, input
can now be a comma-separated string or an array of strings. Reading a role
will now return arrays for these parameters.

IMPROVEMENTS:

* auth/token: `allowed_policies` and `disallowed_policies` can now be
specified as a comma-separated string or an array of strings

BUG FIXES:

* database/mysql: Allow the creation statement to use commands that are not
Expand Down
18 changes: 8 additions & 10 deletions vault/token_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,12 @@ func NewTokenStore(c *Core, config *logical.BackendConfig) (*TokenStore, error)
},

"allowed_policies": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Type: framework.TypeCommaStringSlice,
Description: tokenAllowedPoliciesHelp,
},

"disallowed_policies": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Type: framework.TypeCommaStringSlice,
Description: tokenDisallowedPoliciesHelp,
},

Expand Down Expand Up @@ -2465,18 +2463,18 @@ func (ts *TokenStore) tokenStoreRoleCreateUpdate(
return logical.ErrorResponse(fmt.Sprintf("error registering path suffix: %s", consts.ErrPathContainsParentReferences)), nil
}

allowedPoliciesStr, ok := data.GetOk("allowed_policies")
allowedPoliciesRaw, ok := data.GetOk("allowed_policies")
if ok {
entry.AllowedPolicies = policyutil.SanitizePolicies(strings.Split(allowedPoliciesStr.(string), ","), policyutil.DoNotAddDefaultPolicy)
entry.AllowedPolicies = policyutil.SanitizePolicies(allowedPoliciesRaw.([]string), policyutil.DoNotAddDefaultPolicy)
} else if req.Operation == logical.CreateOperation {
entry.AllowedPolicies = policyutil.SanitizePolicies(strings.Split(data.Get("allowed_policies").(string), ","), policyutil.DoNotAddDefaultPolicy)
entry.AllowedPolicies = policyutil.SanitizePolicies(data.Get("allowed_policies").([]string), policyutil.DoNotAddDefaultPolicy)
}

disallowedPoliciesStr, ok := data.GetOk("disallowed_policies")
disallowedPoliciesRaw, ok := data.GetOk("disallowed_policies")
if ok {
entry.DisallowedPolicies = strutil.ParseDedupLowercaseAndSortStrings(disallowedPoliciesStr.(string), ",")
entry.DisallowedPolicies = strutil.RemoveDuplicates(disallowedPoliciesRaw.([]string), true)
} else if req.Operation == logical.CreateOperation {
entry.DisallowedPolicies = strutil.ParseDedupLowercaseAndSortStrings(data.Get("disallowed_policies").(string), ",")
entry.DisallowedPolicies = strutil.RemoveDuplicates(data.Get("disallowed_policies").([]string), true)
}

// Store it
Expand Down

0 comments on commit ee89aa1

Please sign in to comment.