moby/cmd/dockerd
Kir Kolyshkin 7120976d74 Implement none, private, and shareable ipc modes
Since the commit d88fe447df ("Add support for sharing /dev/shm/ and
/dev/mqueue between containers") container's /dev/shm is mounted on the
host first, then bind-mounted inside the container. This is done that
way in order to be able to share this container's IPC namespace
(and the /dev/shm mount point) with another container.

Unfortunately, this functionality breaks container checkpoint/restore
(even if IPC is not shared). Since /dev/shm is an external mount, its
contents is not saved by `criu checkpoint`, and so upon restore any
application that tries to access data under /dev/shm is severily
disappointed (which usually results in a fatal crash).

This commit solves the issue by introducing new IPC modes for containers
(in addition to 'host' and 'container:ID'). The new modes are:

 - 'shareable':	enables sharing this container's IPC with others
		(this used to be the implicit default);

 - 'private':	disables sharing this container's IPC.

In 'private' mode, container's /dev/shm is truly mounted inside the
container, without any bind-mounting from the host, which solves the
issue.

While at it, let's also implement 'none' mode. The motivation, as
eloquently put by Justin Cormack, is:

> I wondered a while back about having a none shm mode, as currently it is
> not possible to have a totally unwriteable container as there is always
> a /dev/shm writeable mount. It is a bit of a niche case (and clearly
> should never be allowed to be daemon default) but it would be trivial to
> add now so maybe we should...

...so here's yet yet another mode:

 - 'none':	no /dev/shm mount inside the container (though it still
		has its own private IPC namespace).

Now, to ultimately solve the abovementioned checkpoint/restore issue, we'd
need to make 'private' the default mode, but unfortunately it breaks the
backward compatibility. So, let's make the default container IPC mode
per-daemon configurable (with the built-in default set to 'shareable'
for now). The default can be changed either via a daemon CLI option
(--default-shm-mode) or a daemon.json configuration file parameter
of the same name.

Note one can only set either 'shareable' or 'private' IPC modes as a
daemon default (i.e. in this context 'host', 'container', or 'none'
do not make much sense).

Some other changes this patch introduces are:

1. A mount for /dev/shm is added to default OCI Linux spec.

2. IpcMode.Valid() is simplified to remove duplicated code that parsed
   'container:ID' form. Note the old version used to check that ID does
   not contain a semicolon -- this is no longer the case (tests are
   modified accordingly). The motivation is we should either do a
   proper check for container ID validity, or don't check it at all
   (since it is checked in other places anyway). I chose the latter.

3. IpcMode.Container() is modified to not return container ID if the
   mode value does not start with "container:", unifying the check to
   be the same as in IpcMode.IsContainer().

3. IPC mode unit tests (runconfig/hostconfig_test.go) are modified
   to add checks for newly added values.

[v2: addressed review at https://github.com/moby/moby/pull/34087#pullrequestreview-51345997]
[v3: addressed review at https://github.com/moby/moby/pull/34087#pullrequestreview-53902833]
[v4: addressed the case of upgrading from older daemon, in this case
     container.HostConfig.IpcMode is unset and this is valid]
[v5: document old and new IpcMode values in api/swagger.yaml]
[v6: add the 'none' mode, changelog entry to docs/api/version-history.md]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2017-08-14 10:50:39 +03:00
..
hack review code about cmd/* and fix some easy typos :D 2017-02-10 15:52:33 +08:00
config.go Allow to set the control plane MTU 2017-07-28 13:52:03 -07:00
config_common_unix.go Deprecate --graph flag; Replace with --data-root 2017-03-30 11:24:56 +02:00
config_experimental.go Extract daemon configuration and discovery to their own package 2017-02-08 09:53:38 +01:00
config_solaris.go Extract daemon configuration and discovery to their own package 2017-02-08 09:53:38 +01:00
config_unix.go Implement none, private, and shareable ipc modes 2017-08-14 10:50:39 +03:00
config_unix_test.go Remove pkg/testutil/assert in favor of testify 2017-04-14 12:03:21 -07:00
config_windows.go Deprecate --graph flag; Replace with --data-root 2017-03-30 11:24:56 +02:00
daemon.go Move pkg/listeners away 2017-08-08 18:14:04 +02:00
daemon_freebsd.go Windows: Wait for OOBE to prevent crashing during host update 2017-02-15 14:01:54 -08:00
daemon_linux.go Windows: Wait for OOBE to prevent crashing during host update 2017-02-15 14:01:54 -08:00
daemon_solaris.go [project] change syscall to /x/sys/unix|windows 2017-07-11 08:00:32 -04:00
daemon_test.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
daemon_unix.go [project] change syscall to /x/sys/unix|windows 2017-07-11 08:00:32 -04:00
daemon_unix_test.go Disable legacy (v1) registries by default 2017-06-12 11:04:28 +02:00
daemon_windows.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
docker.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
docker_windows.go Windows: work around Go 1.6.2/Nano Server TP5 issue 2016-05-25 11:59:28 +02:00
metrics.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
options.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
options_test.go Remove cli/flags package 2017-06-01 13:34:31 -07:00
README.md Fix readme doc for dockerd 2016-09-01 14:47:51 +08:00
service_unsupported.go Windows: no pidfile when service 2017-03-08 15:18:30 -08:00
service_windows.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00

docker.go contains Docker daemon's main function.

This file provides first line CLI argument parsing and environment variable setting.