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 1 commit
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
56 changes: 56 additions & 0 deletions vault/logical_system_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -102,6 +103,61 @@ 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")
}

files, err := ioutil.ReadDir(cluster.TempDir)
if err != nil {
t.Fatal(err)
}

// Seal the cluster
cluster.EnsureCoresSealed(t)

// Simulate removal of the plugin binary
var pluginBinFile string
for _, file := range files {
if strings.Contains(file.Name(), t.Name()) {
pluginBinFile = file.Name()
break
}
}

if pluginBinFile == "" {
t.Fatal("unable to find plugin binary in the plugin directory")
}

err = os.Remove(filepath.Join(cluster.TempDir, pluginBinFile))
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