-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
More Mount Conflict Detection #2919
Changes from 4 commits
ff650e5
af30967
d848929
cf07549
e8f330e
f3136f0
b0fbfe8
bf02212
0f36271
6836698
314a032
23aa611
c03b662
e2c0f63
5b60f6b
51c948f
d70bcd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,13 @@ func (r *Router) Mount(backend logical.Backend, prefix string, mountEntry *Mount | |
if existing, _, ok := r.root.LongestPrefix(prefix); ok && existing != "" { | ||
return fmt.Errorf("cannot mount under existing mount '%s'", existing) | ||
} | ||
// If this is a secret backend, check to see if the prefix conflicts | ||
// with an existing mountpoint | ||
if prefix != "" { | ||
if match := r.MatchingPrefix(prefix); match != "" { | ||
return fmt.Errorf("cannot mount over existing mount '%s'", match) | ||
} | ||
} | ||
|
||
// Build the paths | ||
paths := backend.SpecialPaths() | ||
|
@@ -174,6 +181,31 @@ func (r *Router) MatchingMount(path string) string { | |
return mount | ||
} | ||
|
||
//MatchingPrefix returns a mount prefix that a path may be a part of | ||
func (r *Router) MatchingPrefix(path string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't get a read lock but should, as it can be called externally (via MountConflict from the mount code). However, it is called with a lock already held from the router's Mount function. The way to deal with this would be to have MatchingPrefix grab a read lock, then call matchingPrefixInternal which has the actual logic. The router's Mount function would then just call matchingPrefixInternal directly. |
||
var existing string = "" | ||
fn := func(existing_path string, _v interface{}) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this function executes at all wouldn't it mean that we've found a prefix? Is the |
||
if strings.HasPrefix(existing_path, path) { | ||
existing = existing_path | ||
return true | ||
} | ||
return false | ||
} | ||
r.root.WalkPrefix(path, fn) | ||
return existing | ||
} | ||
|
||
// MountConflict determines if there are potential path conflicts | ||
func (r *Router) MountConflict(path string) string { | ||
if exact_match := r.MatchingMount(path); exact_match != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really this function should grab a single read lock for the entire function and then call matchingMountInternal and matchingPrefixInternal. That way nothing can change between the two functions. |
||
return exact_match | ||
} | ||
if prefix_match := r.MatchingPrefix(path); prefix_match != "" { | ||
return prefix_match | ||
} | ||
return "" | ||
} | ||
|
||
// MatchingView returns the view used for a path | ||
func (r *Router) MatchingStorageView(path string) *BarrierView { | ||
r.l.RLock() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,28 @@ func TestRouter_Mount(t *testing.T) { | |
t.Fatalf("err: %v", err) | ||
} | ||
|
||
meUUID, err = uuid.GenerateUUID() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this to be placed just above the definition of subMountEntry? |
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
subMountEntry := &MountEntry{ | ||
Path: "prod/", | ||
UUID: meUUID, | ||
} | ||
|
||
if r.MountConflict("prod/aws/") == "" { | ||
t.Fatalf("bad: prod/aws/") | ||
} | ||
if r.MountConflict("prod/") == "" { | ||
t.Fatalf("bad: prod/") | ||
} | ||
|
||
err = r.Mount(n, "prod/", subMountEntry, view) | ||
if !strings.Contains(err.Error(), "cannot mount over existing mount") { | ||
t.Fatalf("err: %v", err) | ||
} | ||
|
||
if path := r.MatchingMount("prod/aws/foo"); path != "prod/aws/" { | ||
t.Fatalf("bad: %s", path) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,13 @@ Once a secret backend is mounted, you can interact with it directly | |
at its mount point according to its own API. You can use the `vault path-help` | ||
system to determine the paths it responds to. | ||
|
||
Note that mount point cannot conflict with each other in Vault. There are | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/point/points |
||
two broad implications of this fact. The first is that you cannot have | ||
a mount which is prefixed with an existing mount. The second is that you | ||
cannot create a mount point that is named as a prefix of an existing mount. | ||
As an example, the mounts `foo/bar` and `foo/baz` can peacefully coexist | ||
with each other whereas `foo` and `foo/baz` cannot | ||
|
||
## Barrier View | ||
|
||
An important concept around secret backends is that they receive a | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that we don't allow empty prefixes in the API calls or core mount function. Have you seen this? This
if
seems unnecessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this check appears unnecessary.