Browse code

Don't make container mount unbindable

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2018/04/03 05:23:08
Showing 2 changed files
... ...
@@ -293,7 +293,6 @@ func (daemon *Daemon) createSecretsDir(c *container.Container) error {
293 293
 	if err := mount.Mount("tmpfs", dir, "tmpfs", "nodev,nosuid,noexec,"+tmpfsOwnership); err != nil {
294 294
 		return errors.Wrap(err, "unable to setup secret mount")
295 295
 	}
296
-
297 296
 	return nil
298 297
 }
299 298
 
... ...
@@ -400,15 +399,5 @@ func (daemon *Daemon) setupContainerMountsRoot(c *container.Container) error {
400 400
 	if err != nil {
401 401
 		return err
402 402
 	}
403
-
404
-	if err := idtools.MkdirAllAndChown(p, 0700, daemon.idMappings.RootPair()); err != nil {
405
-		return err
406
-	}
407
-
408
-	if err := mount.MakeUnbindable(p); err != nil {
409
-		// Setting unbindable is a precaution and is not neccessary for correct operation.
410
-		// Do not error out if this fails.
411
-		logrus.WithError(err).WithField("resource", p).WithField("container", c.ID).Warn("Error setting container resource mounts to unbindable, this may cause mount leakages, preventing removal of this container.")
412
-	}
413
-	return nil
403
+	return idtools.MkdirAllAndChown(p, 0700, daemon.idMappings.RootPair())
414 404
 }
... ...
@@ -1,7 +1,6 @@
1 1
 package container // import "github.com/docker/docker/integration/container"
2 2
 
3 3
 import (
4
-	"bytes"
5 4
 	"context"
6 5
 	"fmt"
7 6
 	"path/filepath"
... ...
@@ -13,8 +12,6 @@ import (
13 13
 	"github.com/docker/docker/api/types/network"
14 14
 	"github.com/docker/docker/client"
15 15
 	"github.com/docker/docker/integration/internal/request"
16
-	"github.com/docker/docker/internal/test/daemon"
17
-	"github.com/docker/docker/pkg/stdcopy"
18 16
 	"github.com/docker/docker/pkg/system"
19 17
 	"github.com/gotestyourself/gotestyourself/assert"
20 18
 	is "github.com/gotestyourself/gotestyourself/assert/cmp"
... ...
@@ -22,77 +19,6 @@ import (
22 22
 	"github.com/gotestyourself/gotestyourself/skip"
23 23
 )
24 24
 
25
-func TestContainerShmNoLeak(t *testing.T) {
26
-	skip.If(t, testEnv.IsRemoteDaemon(), "cannot start daemon on remote test run")
27
-	t.Parallel()
28
-	d := daemon.New(t)
29
-	client, err := d.NewClient()
30
-	if err != nil {
31
-		t.Fatal(err)
32
-	}
33
-	d.StartWithBusybox(t, "--iptables=false")
34
-	defer d.Stop(t)
35
-
36
-	ctx := context.Background()
37
-	cfg := container.Config{
38
-		Image: "busybox",
39
-		Cmd:   []string{"top"},
40
-	}
41
-
42
-	ctr, err := client.ContainerCreate(ctx, &cfg, nil, nil, "")
43
-	if err != nil {
44
-		t.Fatal(err)
45
-	}
46
-	defer client.ContainerRemove(ctx, ctr.ID, types.ContainerRemoveOptions{Force: true})
47
-
48
-	if err := client.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{}); err != nil {
49
-		t.Fatal(err)
50
-	}
51
-
52
-	// this should recursively bind mount everything in the test daemons root
53
-	// except of course we are hoping that the previous containers /dev/shm mount did not leak into this new container
54
-	hc := container.HostConfig{
55
-		Mounts: []mount.Mount{
56
-			{
57
-				Type:   mount.TypeBind,
58
-				Source: d.Root,
59
-				Target: "/testdaemonroot",
60
-			},
61
-		},
62
-	}
63
-	cfg.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("mount | grep testdaemonroot | grep containers | grep %s", ctr.ID)}
64
-	cfg.AttachStdout = true
65
-	cfg.AttachStderr = true
66
-	ctrLeak, err := client.ContainerCreate(ctx, &cfg, &hc, nil, "")
67
-	if err != nil {
68
-		t.Fatal(err)
69
-	}
70
-
71
-	attach, err := client.ContainerAttach(ctx, ctrLeak.ID, types.ContainerAttachOptions{
72
-		Stream: true,
73
-		Stdout: true,
74
-		Stderr: true,
75
-	})
76
-	if err != nil {
77
-		t.Fatal(err)
78
-	}
79
-
80
-	if err := client.ContainerStart(ctx, ctrLeak.ID, types.ContainerStartOptions{}); err != nil {
81
-		t.Fatal(err)
82
-	}
83
-
84
-	buf := bytes.NewBuffer(nil)
85
-
86
-	if _, err := stdcopy.StdCopy(buf, buf, attach.Reader); err != nil {
87
-		t.Fatal(err)
88
-	}
89
-
90
-	out := bytes.TrimSpace(buf.Bytes())
91
-	if !bytes.Equal(out, []byte{}) {
92
-		t.Fatalf("mount leaked: %s", string(out))
93
-	}
94
-}
95
-
96 25
 func TestContainerNetworkMountsNoChown(t *testing.T) {
97 26
 	// chown only applies to Linux bind mounted volumes; must be same host to verify
98 27
 	skip.If(t, testEnv.DaemonInfo.OSType != "linux" || testEnv.IsRemoteDaemon())