container: Set container_engine_t SELinux label

Set the `container_engine_t` SELinux on the **outer** Podman container,
so that gVisor does not break on systems where SELinux is enforcing.
This label is provided for container engines running within a container,
which fits our `runsc` within `crun` situation.

We have considered using the more permissive `label=disable` option, to
disable SELinux labels altogether, but we want to take advantage of as
many SELinux protections as we can, even for the **outer** container.

Cherry-picked from e1e63d14f8

Fixes #880
This commit is contained in:
Alex Pyrgiotis 2024-07-26 16:27:40 +03:00
parent 756945931f
commit 0a181a3342
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA

View file

@ -103,6 +103,9 @@ class Container(IsolationProvider):
running gVisor. running gVisor.
* Do not allow access to the network stack. * Do not allow access to the network stack.
* Run the container as the unprivileged `dangerzone` user. * Run the container as the unprivileged `dangerzone` user.
* Set the `container_engine_t` SELinux label, which allows gVisor to work on
SELinux-enforcing systems
(see https://github.com/freedomofpress/dangerzone/issues/880).
For Podman specifically, where applicable, we also add the following: For Podman specifically, where applicable, we also add the following:
* Do not log the container's output. * Do not log the container's output.
@ -138,6 +141,7 @@ class Container(IsolationProvider):
security_args += ["--cap-drop", "all"] security_args += ["--cap-drop", "all"]
security_args += ["--cap-add", "SYS_CHROOT"] security_args += ["--cap-add", "SYS_CHROOT"]
security_args += ["--security-opt", "label=type:container_engine_t"]
security_args += ["--network=none"] security_args += ["--network=none"]
security_args += ["-u", "dangerzone"] security_args += ["-u", "dangerzone"]