summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordelusionalai <delusionalai@users.noreply.git.jnsn.dev>2026-11-16 22:09:56 +0000
committerdelusionalai <delusionalai@users.noreply.git.jnsn.dev>2026-11-16 22:09:56 +0000
commitf2fd518c16eec93bebc846db9341ee5831a41bed (patch)
treeac8486fdbfeff096213e2bae59e1e10c55540c38
parente237acf0f5161db48b9553db541e91e02b191f97 (diff)
downloaddevbox-f2fd518c16eec93bebc846db9341ee5831a41bed.tar.gz
devbox-f2fd518c16eec93bebc846db9341ee5831a41bed.zip
login.sh: give nested podman the devices, modules and cgroup tree it asks for
- /dev/net/tun, which rootless podman opens for the container network, and /dev/fuse for the fuse-overlayfs fallback. Both world-readable, since it is the dev user who opens them; mknod alone would leave them 0600 root. - modprobe of loop, overlay, veth and bridge. Nothing else does this: there is no systemd in the guest, so no systemd-modules-load.service, and a kata guest kernel does not necessarily have them built in. - delegation of the cgroup tree. Without systemd there is no user@1000.service and nothing performs the delegation rootless podman needs to create a cgroup for a container, which shows up as "Failed to add conmon to cgroupfs sandbox cgroup" and no --memory/--cpus/--pids-limit. Enabling the controllers for children and chowning /sys/fs/cgroup is all delegation is. Guarded on /proc/self/cgroup being 0::/, so it never hands over a host tree visible through --cgroupns=host. Co-Authored-By: pi <pi@pi.dev>
-rw-r--r--login.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/login.sh b/login.sh
index ac838f4..00d1206 100644
--- a/login.sh
+++ b/login.sh
@@ -10,6 +10,21 @@ fi
for i in {0..7}; do
[ -e "/dev/loop$i" ] || mknod "/dev/loop$i" b 7 $i
done
+# Rootless podman also opens /dev/net/tun (container network) and /dev/fuse
+# (fuse-overlayfs fallback). They have to be world-readable, since the dev user
+# is the one opening them.
+[ -d /dev/net ] || mkdir -p /dev/net
+[ -e /dev/net/tun ] || mknod /dev/net/tun c 10 200
+[ -e /dev/fuse ] || mknod /dev/fuse c 10 236
+chmod 0666 /dev/net/tun /dev/fuse
+
+# Nothing loads modules in a kata guest: there is no systemd, so no
+# systemd-modules-load.service. These are what nested podman needs, and
+# modprobe is a no-op for any of them that is built into the guest kernel.
+for mod in loop overlay veth bridge; do
+ modprobe -q "$mod" 2>/dev/null || true
+done
+
# Podman's overlay storage driver cannot live on virtiofs, so those graphroots
# get a loop-mounted ext4 instead. Runs as root and hands the result to owner,
# who is the user that will run podman on it.
@@ -53,6 +68,17 @@ function overlay_fs() {
overlay_fs "/var/lib/containers/storage" "/var/tmp/containers.img" "root:root"
overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" "dev:dev"
+# Without systemd nothing delegates the cgroup tree to dev, and rootless podman
+# then cannot create a cgroup for a container. This is all delegation is; it is
+# only safe when this container owns the tree it can see, which is the case with
+# its own cgroup namespace (podman's default) and not with --cgroupns=host.
+if [ "$(cat /proc/self/cgroup 2>/dev/null)" = "0::/" ] && [ -w /sys/fs/cgroup ]; then
+ for ctrl in $(cat /sys/fs/cgroup/cgroup.controllers 2>/dev/null); do
+ echo "+$ctrl" >/sys/fs/cgroup/cgroup.subtree_control 2>/dev/null || true
+ done
+ chown -R dev:dev /sys/fs/cgroup 2>/dev/null || true
+fi
+
su dev
# if [[ -z "${PASEO_PASSWORD:-}" ]]; then