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

Strip leading slashes in policies. #1170

Merged
merged 1 commit into from Mar 3, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions vault/policy.go
Expand Up @@ -74,6 +74,12 @@ func Parse(rules string) (*Policy, error) {

// Validate the path policy
for _, pc := range p.Paths {
// Strip a leading '/' as paths in Vault start after the / in the API
// path
if len(pc.Prefix) > 0 && pc.Prefix[0] == '/' {
pc.Prefix = pc.Prefix[1:]
}

// Strip the glob character if found
if strings.HasSuffix(pc.Prefix, "*") {
pc.Prefix = strings.TrimSuffix(pc.Prefix, "*")
Expand Down
3 changes: 2 additions & 1 deletion vault/policy_test.go
Expand Up @@ -80,7 +80,8 @@ path "prod/version" {
}

# Read access to foobar
path "foo/bar" {
# Also tests stripping of leading slash
path "/foo/bar" {
policy = "read"
}

Expand Down