mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-30 06:46:31 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
1 parent
301a9a3b04
commit
bfd6efeebc
4 files changed
+16
-1
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
@@ -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
|
||||
@@ -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" \
|
||||
|
||||
Reference in new issue
Block a user