From bfd6efeebc6a081b57f3696aeaa1dac3bb0cdbda Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 29 Sep 2026 00:13:44 +0200 Subject: [PATCH] fix(containers): mask the preset units that escape a privileged systemd container These images boot systemd with `privileged: true`, so /dev is the host's. getty-static.service is enabled by preset and its only conditions are that /dev/tty0 exists and dbus does not, both of which hold here, so it claims tty2 through tty6 and hangs up whatever owns them. It is masked in each image that boots systemd this way: the root image every runner and swarm node derives from, the docs test machine, and the matrix runner, which masked the neighbouring getty units but not the one that does the claiming. In the root image the getty mask shared an `|| true` with the firstboot and binfmt masks, so a mask that failed would have shipped silently. It gets its own RUN; the optional masks keep theirs. tmp.mount is enabled by the same preset and guarded only by `ConditionPathIsSymbolicLink=!/tmp`, with nothing about virtualisation. The docs machine therefore mounted a fresh tmpfs over /tmp during boot and shadowed the work bind, whose source lives there. The directory was present when the container was created and gone once systemd had booted, so the replay's `-w` failed with "chdir to cwd ... no such file or directory" while the src mount, reached through the identical mechanism, worked. Masking it keeps the bind visible on both sides, which is what the nested `docker run` in the replayed block requires. The machine image also declares `container=docker` and STOPSIGNAL SIGRTMIN+3, the documented way to tell systemd it is containerised; the root image already did. Co-Authored-By: Claude Opus 5 (1M context) --- Dockerfile | 3 +++ roles/web-app-docs/files/test/Dockerfile | 3 +++ roles/web-app-docs/files/test/init.sh | 10 +++++++++- .../files/flavor/ansible/runner/Dockerfile | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4f5673972c..0c0333d7de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,6 +67,9 @@ RUN set -euo pipefail; \ proc-sys-fs-binfmt_misc.mount || true; \ systemd-machine-id-setup || true +RUN set -euo pipefail; \ + systemctl mask getty.target console-getty.service getty-static.service getty@.service + ENV container=docker STOPSIGNAL SIGRTMIN+3 diff --git a/roles/web-app-docs/files/test/Dockerfile b/roles/web-app-docs/files/test/Dockerfile index 3fe1cf46bb..e952978e6b 100644 --- a/roles/web-app-docs/files/test/Dockerfile +++ b/roles/web-app-docs/files/test/Dockerfile @@ -4,4 +4,7 @@ FROM ${MACHINE_BASE_IMAGE} COPY init.sh /tmp/docs-guide-init.sh RUN /bin/sh /tmp/docs-guide-init.sh && rm -f /tmp/docs-guide-init.sh +ENV container=docker +STOPSIGNAL SIGRTMIN+3 + ENTRYPOINT ["/sbin/init"] diff --git a/roles/web-app-docs/files/test/init.sh b/roles/web-app-docs/files/test/init.sh index 3b5bd176f0..1907caf44d 100644 --- a/roles/web-app-docs/files/test/init.sh +++ b/roles/web-app-docs/files/test/init.sh @@ -6,7 +6,14 @@ set -e -[ -e /sbin/init ] && exit 0 +mask_units_that_escape_the_container() { + systemctl mask getty.target console-getty.service getty-static.service getty@.service tmp.mount +} + +if [ -e /sbin/init ]; then + mask_units_that_escape_the_container + exit 0 +fi APT_OPTS="-o Acquire::Retries=5 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30" @@ -31,3 +38,4 @@ fi grep -q myhostname /etc/nsswitch.conf || sed -i "s/^hosts:.*/& myhostname/" /etc/nsswitch.conf [ -e /sbin/init ] || ln -sf /lib/systemd/systemd /sbin/init +mask_units_that_escape_the_container diff --git a/roles/web-app-matrix/files/flavor/ansible/runner/Dockerfile b/roles/web-app-matrix/files/flavor/ansible/runner/Dockerfile index 21e8583a2d..b8f1959298 100644 --- a/roles/web-app-matrix/files/flavor/ansible/runner/Dockerfile +++ b/roles/web-app-matrix/files/flavor/ansible/runner/Dockerfile @@ -49,6 +49,7 @@ RUN systemctl mask \ kmod-static-nodes.service \ console-getty.service \ getty.target \ + getty-static.service \ getty@.service RUN python3 -m venv "$VIRTUAL_ENV" \