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

Fix regexes for sys/raw/ and sys/leases/lookup/ to match prevailing conventions #21760

Merged
merged 7 commits into from
Jul 21, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions api/sudo_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ var sudoPaths = map[string]*regexp.Regexp{
// This entry is a bit wrong... sys/leases/lookup does NOT require sudo. But sys/leases/lookup/ with a trailing
// slash DOES require sudo. But the part of the Vault CLI that uses this logic doesn't pass operation-appropriate
// trailing slashes, it always strips them off, so we end up giving the wrong answer for one of these.
"/sys/leases/lookup": regexp.MustCompile(`^/sys/leases/lookup/?$`),
"/sys/leases/lookup/{prefix}": regexp.MustCompile(`^/sys/leases/lookup/.+$`),
"/sys/leases/lookup/{prefix}": regexp.MustCompile(`^/sys/leases/lookup(?:/.+)?$`),
"/sys/leases/revoke-force/{prefix}": regexp.MustCompile(`^/sys/leases/revoke-force/.+$`),
"/sys/leases/revoke-prefix/{prefix}": regexp.MustCompile(`^/sys/leases/revoke-prefix/.+$`),
"/sys/plugins/catalog/{name}": regexp.MustCompile(`^/sys/plugins/catalog/[^/]+$`),
"/sys/plugins/catalog/{type}": regexp.MustCompile(`^/sys/plugins/catalog/[\w-]+$`),
"/sys/plugins/catalog/{type}/{name}": regexp.MustCompile(`^/sys/plugins/catalog/[\w-]+/[^/]+$`),
"/sys/raw": regexp.MustCompile(`^/sys/raw$`),
"/sys/raw/{path}": regexp.MustCompile(`^/sys/raw/.+$`),
"/sys/raw/{path}": regexp.MustCompile(`^/sys/raw(?:/.+)?$`),
"/sys/remount": regexp.MustCompile(`^/sys/remount$`),
"/sys/revoke-force/{prefix}": regexp.MustCompile(`^/sys/revoke-force/.+$`),
"/sys/revoke-prefix/{prefix}": regexp.MustCompile(`^/sys/revoke-prefix/.+$`),
Expand Down
3 changes: 3 additions & 0 deletions changelog/21760.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
core: Fix regexes for `sys/raw/` and `sys/leases/lookup/` to match prevailing conventions
```
11 changes: 1 addition & 10 deletions vault/logical_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (b *RawBackend) existenceCheck(ctx context.Context, request *logical.Reques
func rawPaths(prefix string, r *RawBackend) []*framework.Path {
return []*framework.Path{
{
Pattern: prefix + "(raw/?$|raw/(?P<path>.+))",
Pattern: prefix + "raw/" + framework.MatchAllRegex("path"),

Fields: map[string]*framework.FieldSchema{
"path": {
Expand All @@ -322,7 +322,6 @@ func rawPaths(prefix string, r *RawBackend) []*framework.Path {
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "raw",
OperationVerb: "read",
OperationSuffix: "|path",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Expand All @@ -342,7 +341,6 @@ func rawPaths(prefix string, r *RawBackend) []*framework.Path {
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "raw",
OperationVerb: "write",
OperationSuffix: "|path",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Expand All @@ -353,11 +351,6 @@ func rawPaths(prefix string, r *RawBackend) []*framework.Path {
},
logical.CreateOperation: &framework.PathOperation{
Callback: r.handleRawWrite,
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "raw",
OperationVerb: "write",
OperationSuffix: "|path",
},
averche marked this conversation as resolved.
Show resolved Hide resolved
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: "OK",
Expand All @@ -370,7 +363,6 @@ func rawPaths(prefix string, r *RawBackend) []*framework.Path {
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "raw",
OperationVerb: "delete",
OperationSuffix: "|path",
},
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Expand All @@ -384,7 +376,6 @@ func rawPaths(prefix string, r *RawBackend) []*framework.Path {
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "raw",
OperationVerb: "list",
OperationSuffix: "|path",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Expand Down
3 changes: 1 addition & 2 deletions vault/logical_system_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -2696,12 +2696,11 @@ func (b *SystemBackend) capabilitiesPaths() []*framework.Path {
func (b *SystemBackend) leasePaths() []*framework.Path {
return []*framework.Path{
{
Pattern: "leases/lookup/(?P<prefix>.+?)?",
Pattern: "leases/lookup/" + framework.MatchAllRegex("prefix"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "leases",
OperationVerb: "look-up",
OperationSuffix: "|with-prefix",
},

Fields: map[string]*framework.FieldSchema{
Expand Down