1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix issue with plugin scanner going to deep

The plugin spec says that plugins can live in one of:

- /var/run/docker/plugins/<name>.sock
- /var/run/docker/plugins/<name>/<name>.sock
- /etc/docker/plugins/<name>.[json,spec]
- /etc/docker/plugins/<name>/<name>.<json,spec>
- /usr/lib/docker/plugins/<name>.<json,spec>
- /usr/lib/docker/plugins/<name>/<name>.<json,spec>

However, the plugin scanner which is used by the volume list API was
doing `filepath.Walk`, which will walk the entire tree for each of the
supported paths.
This means that even v2 plugins in
`/var/run/docker/plugins/<id>/<name>.sock` were being detected as a v1
plugin.
When the v1 plugin loader tried to load such a plugin it would log an
error that it couldn't find it because it doesn't match one of the
supported patterns... e.g. when in a subdir, the subdir name must match
the plugin name for the socket.

There is no behavior change as the error is only on the `Scan()` call,
which is passing names to the plugin registry when someone calls the
volume list API.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2018-01-25 17:41:45 -08:00
parent 99cfb5f31a
commit b27f70d45a
3 changed files with 101 additions and 22 deletions

View file

@ -97,7 +97,63 @@ func TestScan(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(pluginNamesNotEmpty) != 1 {
t.Fatalf("expected 1 plugin entry: %v", pluginNamesNotEmpty)
}
if p.Name() != pluginNamesNotEmpty[0] {
t.Fatalf("Unable to scan plugin with name %s", p.name)
}
}
func TestScanNotPlugins(t *testing.T) {
tmpdir, unregister := Setup(t)
defer unregister()
// not that `Setup()` above sets the sockets path and spec path dirs, which
// `Scan()` uses to find plugins to the returned `tmpdir`
notPlugin := filepath.Join(tmpdir, "not-a-plugin")
if err := os.MkdirAll(notPlugin, 0700); err != nil {
t.Fatal(err)
}
// this is named differently than the dir it's in, so the scanner should ignore it
l, err := net.Listen("unix", filepath.Join(notPlugin, "foo.sock"))
if err != nil {
t.Fatal(err)
}
defer l.Close()
// same let's test a spec path
f, err := os.Create(filepath.Join(notPlugin, "foo.spec"))
if err != nil {
t.Fatal(err)
}
defer f.Close()
names, err := Scan()
if err != nil {
t.Fatal(err)
}
if len(names) != 0 {
t.Fatalf("expected no plugins, got %v", names)
}
// Just as a sanity check, let's make an entry that the scanner should read
f, err = os.Create(filepath.Join(notPlugin, "not-a-plugin.spec"))
if err != nil {
t.Fatal(err)
}
defer f.Close()
names, err = Scan()
if err != nil {
t.Fatal(err)
}
if len(names) != 1 {
t.Fatalf("expected 1 entry in result: %v", names)
}
if names[0] != "not-a-plugin" {
t.Fatalf("expected plugin named `not-a-plugin`, got: %s", names[0])
}
}