2016-10-31 16:14:00 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-09 04:17:53 -05:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2016-10-31 16:14:00 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-01-05 16:55:43 -05:00
|
|
|
authzPluginName = "riyaz/authz-no-volume-plugin"
|
2016-10-31 16:14:00 -04:00
|
|
|
authzPluginTag = "latest"
|
|
|
|
authzPluginNameWithTag = authzPluginName + ":" + authzPluginTag
|
2017-01-05 16:55:43 -05:00
|
|
|
authzPluginBadManifestName = "riyaz/authz-plugin-bad-manifest"
|
2016-10-31 16:14:00 -04:00
|
|
|
nonexistentAuthzPluginName = "riyaz/nonexistent-authz-plugin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerAuthzV2Suite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerAuthzV2Suite struct {
|
|
|
|
ds *DockerSuite
|
2016-12-09 04:17:53 -05:00
|
|
|
d *daemon.Daemon
|
2016-10-31 16:14:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerAuthzV2Suite) SetUpTest(c *check.C) {
|
2016-11-09 20:49:09 -05:00
|
|
|
testRequires(c, DaemonIsLinux, Network)
|
2016-12-09 04:17:53 -05:00
|
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
2017-01-13 11:23:28 -05:00
|
|
|
Experimental: testEnv.ExperimentalDaemon(),
|
2016-12-09 04:17:53 -05:00
|
|
|
})
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
2016-10-31 16:14:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerAuthzV2Suite) TearDownTest(c *check.C) {
|
2016-11-21 12:37:13 -05:00
|
|
|
if s.d != nil {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Stop(c)
|
2016-11-21 12:37:13 -05:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
2016-10-31 16:14:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerAuthzV2Suite) TestAuthZPluginAllowNonVolumeRequest(c *check.C) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2016-10-31 16:14:00 -04:00
|
|
|
// Install authz plugin
|
|
|
|
_, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
// start the daemon with the plugin and load busybox, --net=none build fails otherwise
|
|
|
|
// because it needs to pull busybox
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c, "--authorization-plugin="+authzPluginNameWithTag)
|
2016-10-31 16:14:00 -04:00
|
|
|
c.Assert(s.d.LoadBusybox(), check.IsNil)
|
|
|
|
|
|
|
|
// defer disabling the plugin
|
|
|
|
defer func() {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
2016-10-31 16:14:00 -04:00
|
|
|
_, err = s.d.Cmd("plugin", "disable", authzPluginNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
_, err = s.d.Cmd("plugin", "rm", authzPluginNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Ensure docker run command and accompanying docker ps are successful
|
|
|
|
out, err := s.d.Cmd("run", "-d", "busybox", "top")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("ps")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(assertContainerList(out, []string{id}), check.Equals, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerAuthzV2Suite) TestAuthZPluginRejectVolumeRequests(c *check.C) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2016-10-31 16:14:00 -04:00
|
|
|
// Install authz plugin
|
|
|
|
_, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// restart the daemon with the plugin
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c, "--authorization-plugin="+authzPluginNameWithTag)
|
2016-10-31 16:14:00 -04:00
|
|
|
|
|
|
|
// defer disabling the plugin
|
|
|
|
defer func() {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
2016-10-31 16:14:00 -04:00
|
|
|
_, err = s.d.Cmd("plugin", "disable", authzPluginNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
_, err = s.d.Cmd("plugin", "rm", authzPluginNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("volume", "create")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "ls")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))
|
|
|
|
|
|
|
|
// The plugin will block the command before it can determine the volume does not exist
|
|
|
|
out, err = s.d.Cmd("volume", "rm", "test")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "inspect", "test")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "prune", "-f")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerAuthzV2Suite) TestAuthZPluginBadManifestFailsDaemonStart(c *check.C) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2016-10-31 16:14:00 -04:00
|
|
|
// Install authz plugin with bad manifest
|
|
|
|
_, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginBadManifestName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// start the daemon with the plugin, it will error
|
2016-12-09 17:20:14 -05:00
|
|
|
c.Assert(s.d.RestartWithError("--authorization-plugin="+authzPluginBadManifestName), check.NotNil)
|
2016-10-31 16:14:00 -04:00
|
|
|
|
|
|
|
// restarting the daemon without requiring the plugin will succeed
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
2016-10-31 16:14:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerAuthzV2Suite) TestNonexistentAuthZPluginFailsDaemonStart(c *check.C) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, Network)
|
2016-10-31 16:14:00 -04:00
|
|
|
// start the daemon with a non-existent authz plugin, it will error
|
2016-12-09 17:20:14 -05:00
|
|
|
c.Assert(s.d.RestartWithError("--authorization-plugin="+nonexistentAuthzPluginName), check.NotNil)
|
2016-10-31 16:14:00 -04:00
|
|
|
|
|
|
|
// restarting the daemon without requiring the plugin will succeed
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
2016-10-31 16:14:00 -04:00
|
|
|
}
|