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

Warn on upper case in policy name #14670

Merged
merged 7 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/14670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli/vault: warn when policy name contains upper-case letter
```
11 changes: 8 additions & 3 deletions command/policy_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func (c *PolicyWriteCommand) Run(args []string) int {
}

// Policies are normalized to lowercase
name := strings.TrimSpace(strings.ToLower(args[0]))
name := args[0]
digivava marked this conversation as resolved.
Show resolved Hide resolved
formattedName := strings.TrimSpace(strings.ToLower(name))
path := strings.TrimSpace(args[1])

// Get the policy contents, either from stdin of a file
Expand Down Expand Up @@ -119,11 +120,15 @@ func (c *PolicyWriteCommand) Run(args []string) int {
}
rules := buf.String()

if err := client.Sys().PutPolicy(name, rules); err != nil {
if err := client.Sys().PutPolicy(formattedName, rules); err != nil {
c.UI.Error(fmt.Sprintf("Error uploading policy: %s", err))
return 2
}

c.UI.Output(fmt.Sprintf("Success! Uploaded policy: %s", name))
if name != formattedName {
c.UI.Warn(fmt.Sprintf("Policy name was converted to %s", formattedName))
digivava marked this conversation as resolved.
Show resolved Hide resolved
}

c.UI.Output(fmt.Sprintf("Success! Uploaded policy: %s", formattedName))
return 0
}
8 changes: 7 additions & 1 deletion vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2435,14 +2435,19 @@ func (b *SystemBackend) handlePoliciesSet(policyType PolicyType) framework.Opera
return nil, err
}

name := data.Get("name").(string)
digivava marked this conversation as resolved.
Show resolved Hide resolved
policy := &Policy{
Name: strings.ToLower(data.Get("name").(string)),
Name: strings.ToLower(name),
Type: policyType,
namespace: ns,
}
if policy.Name == "" {
return logical.ErrorResponse("policy name must be provided in the URL"), nil
}
if name != policy.Name {
resp = &logical.Response{}
resp.AddWarning(fmt.Sprintf("policy name was converted to %s", policy.Name))
}

policy.Raw = data.Get("policy").(string)
if policy.Raw == "" && policyType == PolicyTypeACL && strings.HasPrefix(req.Path, "policy") {
Expand Down Expand Up @@ -2485,6 +2490,7 @@ func (b *SystemBackend) handlePoliciesSet(policyType PolicyType) framework.Opera
if err := b.Core.policyStore.SetPolicy(ctx, policy); err != nil {
return handleError(err)
}

return resp, nil
}
}
Expand Down