Skip to content

Commit

Permalink
More Mount Conflict Detection
Browse files Browse the repository at this point in the history
Ensure that we are not creating a "submount" underneath an already
existing mountpoint. This (hopefully) fixes hashicorp#2878
  • Loading branch information
Jonathan Freedman committed Jun 24, 2017
1 parent af593dd commit ff650e5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vault/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ 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 != "" {
var existing string = ""
fn := func(existing_path string, _v interface{}) bool {
if strings.HasPrefix(existing_path, prefix) {
existing = existing_path
return true
}
return false
}
r.root.WalkPrefix(prefix, fn)
if existing != "" {
return fmt.Errorf("cannot mount under existing mount '%s'", existing)
}
}

// Build the paths
paths := backend.SpecialPaths()
Expand Down
15 changes: 15 additions & 0 deletions vault/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ func TestRouter_Mount(t *testing.T) {
t.Fatalf("err: %v", err)
}

meUUID, err = uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}

subMountEntry := &MountEntry{
Path: "prod/",
UUID: meUUID,
}

err = r.Mount(n, "prod/", subMountEntry, view)
if !strings.Contains(err.Error(), "cannot mount under existing mount") {
t.Fatalf("err: %v", err)
}

if path := r.MatchingMount("prod/aws/foo"); path != "prod/aws/" {
t.Fatalf("bad: %s", path)
}
Expand Down

0 comments on commit ff650e5

Please sign in to comment.