Skip to content

graphdriver/overlay: make-private overlay's home - #13852

Closed
vbatts wants to merge 1 commit into
moby:masterfrom
vbatts:vbatts-make_overlay_private
Closed

vbatts wants to merge 1 commit into
moby:masterfrom
vbatts:vbatts-make_overlay_private

Conversation

@vbatts

@vbatts vbatts commented Jun 10, 2015

Copy link
Copy Markdown
Contributor

Found when investigating #13775 (comment)

AUFS, btrfs, and devicemapper already do this as well.

Signed-off-by: Vincent Batts [email protected]

@calavera

Copy link
Copy Markdown
Contributor

@vbatts

vbatts commented Jun 10, 2015

Copy link
Copy Markdown
Contributor Author

@calavera that needs the input of someone with knowledge and ability to test zfs.

@burke

burke commented Jun 10, 2015

Copy link
Copy Markdown
Contributor

I'm not sure what to expect exactly, but here's what I get for mount calls with this. I though I'd likely see a mention of MS_PRIVATE, but I don't:

[pid 19183] mount("overlay", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531-init/merged", "overlay", 0, "lowerdir=/u/lib/docker/overlay/d"...) = 0
[pid 19183] mount("overlay", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged", "overlay", 0, "lowerdir=/u/lib/docker/overlay/d"...) = 0
[pid 19183] mount("overlay", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged", "overlay", 0, "lowerdir=/u/lib/docker/overlay/d"...) = 0
[pid 15174] mount("/proc/self/ns/net", "/var/run/docker/netns/63b850f1d641", 0xc20802c6f0, MS_BIND, NULL) = 0
[pid 15215] mount("", "/", "", MS_REC|MS_SLAVE, NULL) = 0
[pid 15215] mount("/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged", 0xc208073640, MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("proc", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/proc", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL) = 0
[pid 15215] mount("tmpfs", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/dev", "tmpfs", MS_NOSUID|MS_STRICTATIME, "mode=755") = 0
[pid 15215] mount("devpts", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/dev/pts", "devpts", MS_NOSUID|MS_NOEXEC, "newinstance,ptmxmode=0666,mode=0"...) = 0
[pid 15215] mount("shm", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/dev/shm", "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, "mode=1777,size=65536k") = 0
[pid 15215] mount("mqueue", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/dev/mqueue", "mqueue", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL) = 0
[pid 15215] mount("sysfs", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/sys", "sysfs", MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL) = 0
[pid 15215] mount("/bug", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/bug", 0xc208073715, MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("/u/lib/docker/containers/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/resolv.conf", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/etc/resolv.conf", 0xc208073728, MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("/u/lib/docker/containers/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/hostname", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/etc/hostname", 0xc208073789, MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("/u/lib/docker/containers/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/hosts", "/u/lib/docker/overlay/63b850f1d6418fca50a55f08a796315280106bc746910a24410c63d79d244531/merged/etc/hosts", 0xc2080737fa, MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("", "/proc/asound", 0xc2080738d9, MS_RDONLY|MS_REMOUNT, NULL) = -1 ENOENT (No such file or directory)
[pid 15215] mount("", "/proc/bus", 0xc20807392c, MS_RDONLY|MS_REMOUNT, NULL) = -1 EINVAL (Invalid argument)
[pid 15215] mount("/proc/bus", "/proc/bus", 0xc208073948, MS_BIND, NULL) = 0
[pid 15215] mount("/proc/bus", "/proc/bus", 0xc208073949, MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("", "/proc/fs", 0xc208073999, MS_RDONLY|MS_REMOUNT, NULL) = -1 EINVAL (Invalid argument)
[pid 15215] mount("/proc/fs", "/proc/fs", 0xc2080739b8, MS_BIND, NULL) = 0
[pid 15215] mount("/proc/fs", "/proc/fs", 0xc2080739b9, MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("", "/proc/irq", 0xc208073a0a, MS_RDONLY|MS_REMOUNT, NULL) = -1 EINVAL (Invalid argument)
[pid 15215] mount("/proc/irq", "/proc/irq", 0xc208073a28, MS_BIND, NULL) = 0
[pid 15215] mount("/proc/irq", "/proc/irq", 0xc208073a29, MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("", "/proc/sys", 0xc208073a7a, MS_RDONLY|MS_REMOUNT, NULL) = -1 EINVAL (Invalid argument)
[pid 15215] mount("/proc/sys", "/proc/sys", 0xc208073a98, MS_BIND, NULL) = 0
[pid 15215] mount("/proc/sys", "/proc/sys", 0xc208073a99, MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("", "/proc/sysrq-trigger", 0xc208073a9b, MS_RDONLY|MS_REMOUNT, NULL) = -1 EINVAL (Invalid argument)
[pid 15215] mount("/proc/sysrq-trigger", "/proc/sysrq-trigger", 0xc208073af8, MS_BIND, NULL) = 0
[pid 15215] mount("/proc/sysrq-trigger", "/proc/sysrq-trigger", 0xc208073af9, MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND|MS_REC, NULL) = 0
[pid 15215] mount("/dev/null", "/proc/kcore", 0xc208073afa, MS_BIND, NULL) = 0
[pid 15215] mount("/dev/null", "/proc/latency_stats", 0xc208073b2a, MS_BIND, NULL) = -1 ENOENT (No such file or directory)
[pid 15215] mount("/dev/null", "/proc/timer_stats", 0xc208073b4a, MS_BIND, NULL) = 0
$ docker version
Client version: 1.7.0-dev
Client API version: 1.20
Go version (client): go1.4.2
Git commit (client): 2943aa3
OS/Arch (client): linux/amd64
Server version: 1.7.0-dev
Server API version: 1.20
Go version (server): go1.4.2
Git commit (server): 2943aa3
OS/Arch (server): linux/amd64

@vbatts

vbatts commented Jun 10, 2015

Copy link
Copy Markdown
Contributor Author

@burke this PR would be on the "home" of overlay (e.g. /var/lib/docker/overlay) only during initialization of the daemon.
And the /proc/self/mountinfo in the container ought to inherit from this.

@burke

burke commented Jun 10, 2015

Copy link
Copy Markdown
Contributor

Oh, that makes sense -- I didn't read the change carefully, clearly.

host:~$ grep overlay /proc/self/mountinfo
132 39 252:1 /lib/docker/overlay /u/lib/docker/overlay rw,noatime shared:2 - ext4 /dev/mapper/lvroot-u rw,data=ordered

host:~$ docker run ubuntu:14.04 cat /proc/self/mountinfo
356 197 0:102 / / rw,relatime - overlay overlay rw,lowerdir=/u/lib/docker/overlay/d0955f21bf24f5bfffd32d2d0bb669d0564701c271bc3dfc64cfc5adfdec2d07/root,upperdir=/u/lib/docker/overlay/b35f6d4e5437d44feb4f8ef634dafe051f673b98afc4f9bdb4492935a19ba90d/upper,workdir=/u/lib/docker/overlay/b35f6d4e5437d44feb4f8ef634dafe051f673b98afc4f9bdb4492935a19ba90d/work
357 356 0:104 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw
358 356 0:105 / /dev rw,nosuid - tmpfs tmpfs rw,mode=755
359 358 0:106 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666
360 358 0:107 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k
361 358 0:103 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw
362 356 0:108 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs ro
363 356 252:1 /lib/docker/containers/b35f6d4e5437d44feb4f8ef634dafe051f673b98afc4f9bdb4492935a19ba90d/resolv.conf /etc/resolv.conf rw,noatime master:2 - ext4 /dev/mapper/lvroot-u rw,data=ordered
364 356 252:1 /lib/docker/containers/b35f6d4e5437d44feb4f8ef634dafe051f673b98afc4f9bdb4492935a19ba90d/hostname /etc/hostname rw,noatime master:2 - ext4 /dev/mapper/lvroot-u rw,data=ordered
365 356 252:1 /lib/docker/containers/b35f6d4e5437d44feb4f8ef634dafe051f673b98afc4f9bdb4492935a19ba90d/hosts /etc/hosts rw,noatime master:2 - ext4 /dev/mapper/lvroot-u rw,data=ordered
199 357 0:104 /bus /proc/bus ro,nosuid,nodev,noexec,relatime - proc proc rw
200 357 0:104 /fs /proc/fs ro,nosuid,nodev,noexec,relatime - proc proc rw
229 357 0:104 /irq /proc/irq ro,nosuid,nodev,noexec,relatime - proc proc rw
230 357 0:104 /sys /proc/sys ro,nosuid,nodev,noexec,relatime - proc proc rw
231 357 0:104 /sysrq-trigger /proc/sysrq-trigger ro,nosuid,nodev,noexec,relatime - proc proc rw
232 357 0:105 /null /proc/kcore rw,nosuid - tmpfs tmpfs rw,mode=755
233 357 0:105 /null /proc/timer_stats rw,nosuid - tmpfs tmpfs rw,mode=755

@rhvgoyal

Copy link
Copy Markdown
Contributor

@vbatts

So why do we do that. What's the rationale behind making home private?

@vbatts

vbatts commented Jun 11, 2015

Copy link
Copy Markdown
Contributor Author

initially it was due to devicemapper. not letting the devices for
containers propagate up to the host. Then there was some use case (sorry, i
forget now), that encouraged it to be in other drivers as well.

On Thu, Jun 11, 2015 at 10:08 AM, Vivek Goyal [email protected]
wrote:

@vbatts https://github.com/vbatts

So why do we do that. What's the rationale behind making home private?

—
Reply to this email directly or view it on GitHub
#13852 (comment).

@rhvgoyal

Copy link
Copy Markdown
Contributor

devices are visible everywhere anyway. For mounts under /var/lib/docker/devicemapper/ they are not visible to containers anyway as container binds mounts to a subdir. /var/lib/docker/devicemapper/mnt/foo.

So I am not sure what purpose does it serve. I am sure there should be something. Just want to understand it better.

So you have received a problem report somewhere or doing this change just to emulate other drivers?

@rhvgoyal

Copy link
Copy Markdown
Contributor

By default I noticed that libcontainer makes its mount hierarchy MS_PRIVATE. That means anything container mounts will not propagate back to daemon/host anyway.

@rhvgoyal

Copy link
Copy Markdown
Contributor

If we want to protect ourselves against container mount (and not relying on libcontainer), then will MS_SLAVE be a better mount. Where we don't want to receive mount events from container but might want to propgate any mounting host does in /var/lib/docker/mnt/continer-id/ to container?

@vbatts

vbatts commented Jun 11, 2015

Copy link
Copy Markdown
Contributor Author

sorry, the mounted device to be propagated in the mountinfo. The issue was when the mounted device propagated up, then another pid on the host unshares mount namespace. that pid would hold reference to the mounted device in its mountinfo, even though it has nothing to do with that mount. Then when the container exits and docker cleans it up, the device would return EBUSY. I know your deferred removal will mitigate this, but the private mount also addressed this particular issue.

@rhvgoyal

Copy link
Copy Markdown
Contributor

Ok, so two things.

  • For solving the issue of container device being visible in host namespace, we started to launch docker daemon in a separate namespace with SLAVE relationship. So that any container docker daemon launches that device will not be visible in host namespace. And we will not face the issue of a process cloning namespace.
  • If docker daemon is running in hostname space (and not a separate namespace), then above patch will not do anything to fix this issue. All the containers docker starts, these will be visible to host and a process can clone namespace and block container release.

@rhvgoyal

Copy link
Copy Markdown
Contributor

MS_PRIVATE will make sense only if we don't want to have any future mount point propagation with container in either direction.

As libcontainer makes his whole hierarchy private by default, I think that communication does not happen already. So this patch might not be having any affect to begin with.

That's why I am curious to know in what use case does it help.

@rhvgoyal

Copy link
Copy Markdown
Contributor

I noticed following comment from alex larsson. May be that's the reason to make /var/lib/docker/devmapper/ private.

#12273 (comment)

But if that's the case probably we should have made /var/lib/docker/devmapper/mnt/ as private and not the one directory above it?

@alexlarsson CC

@icecrime

Copy link
Copy Markdown
Contributor

@vbatts @rhvgoyal Any agreement on this?

@rhvgoyal

Copy link
Copy Markdown
Contributor

@icecrime Not yet. If performance is the reason for making directory private, then I think /var/lib/docker/devmapper/mnt/ should be made private.

I think we can leave this code untouched till somebody complains. Once we have better understanding that why should we make a directory private and which directory should be made private then we can make the change.

@icecrime

Copy link
Copy Markdown
Contributor

SGTM, tentatively closing.

@icecrime icecrime closed this Jul 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants