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

plugin: fix panic on router.MatchingSystemView if backend is nil #7991

Merged
merged 3 commits into from
Dec 10, 2019
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
41 changes: 41 additions & 0 deletions vault/logical_system_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,47 @@ func TestSystemBackend_Plugin_auth(t *testing.T) {
}
}

func TestSystemBackend_Plugin_MissingBinary(t *testing.T) {
cluster := testSystemBackendMock(t, 1, 1, logical.TypeLogical)
defer cluster.Cleanup()

core := cluster.Cores[0]

// Make a request to lazy load the plugin
req := logical.TestRequest(t, logical.ReadOperation, "mock-0/internal")
req.ClientToken = core.Client.Token()
resp, err := core.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp == nil {
t.Fatalf("bad: response should not be nil")
}

// Seal the cluster
cluster.EnsureCoresSealed(t)

// Simulate removal of the plugin binary. Use os.Args to determine file name
// since that's how we create the file for catalog registration in the test
// helper.
pluginFileName := filepath.Base(os.Args[0])
err = os.Remove(filepath.Join(cluster.TempDir, pluginFileName))
if err != nil {
t.Fatal(err)
}

// Unseal the cluster
cluster.UnsealCores(t)

// Make a request against on tune after it is removed
req = logical.TestRequest(t, logical.ReadOperation, "sys/mounts/mock-0/tune")
req.ClientToken = core.Client.Token()
resp, err = core.HandleRequest(namespace.RootContext(nil), req)
if err == nil {
t.Fatalf("expected error")
}
}

func TestSystemBackend_Plugin_MismatchType(t *testing.T) {
cluster := testSystemBackendMock(t, 1, 1, logical.TypeLogical)
defer cluster.Cleanup()
Expand Down
2 changes: 1 addition & 1 deletion vault/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (r *Router) MatchingSystemView(ctx context.Context, path string) logical.Sy
r.l.RLock()
_, raw, ok := r.root.LongestPrefix(path)
r.l.RUnlock()
if !ok {
if !ok || raw.(*routeEntry).backend == nil {
return nil
}
return raw.(*routeEntry).backend.System()
Expand Down