3.0 KiB
3.0 KiB
Research: user-level containers with overlayfs
Measured on this machine: Ubuntu, kernel 7.0.0-38, AppArmor 5.0.2, slirp4netns 1.3.3, uid 1000, no root at runtime.
What works unprivileged
clone(CLONE_NEWUSER|NEWNS|NEWPID|NEWUTS|NEWIPC[|NEWNET]), then the parent writessetgroups=deny,uid_map,gid_map(single entry, own uid). No setuid helpers (newuidmap) needed.- overlayfs mounts inside the userns (kernel >= 5.11) with the
userxattroption. Upper and work dirs must be on a filesystem with user xattrs (ext4, tmpfs >= 6.6 verified for ours). - Mounts that work inside: tmpfs, proc (needs own pidns), devpts (new instance, no
gid=since gid 5 is unmapped), bind mounts of host/dev/{null,zero,full,random,urandom,tty}(nomknodin a userns), read-only remount of/procsubpaths (must copy locked flags fromstatvfs). pivot_root(".", ".")plus lazy unmount of the old root.
What does not
- Writing mapped uid ranges beyond own uid needs
newuidmap+/etc/subuid. Skipped: single mapping keeps the design dumb. Consequence: no chown/su to other uids inside, soapt installas non-root users does not work. - cgroups: no memory/cpu/pid limits without systemd delegation. Not implemented (gap).
- Ubuntu 24.04+:
kernel.apparmor_restrict_unprivileged_userns=1lets any binary create a userns but strips capabilities inside it. Measured: uid_map write succeeds, firstmountfails with EPERM. Fix is an AppArmor profile grantingusernsto the binary (apparmor/doos, install once with sudo). Turning the sysctl off is global and weaker.
Networking options
| Option | Result |
|---|---|
| slirp4netns (chosen default) | Works unprivileged. Needs only the netns of the child pid. --disable-host-loopback blocks the container from reaching host 127.0.0.1 (measured: blocked). DNS via 10.0.2.3 works (measured). |
| pasta | Installed here but not used: slirp4netns suffices, one dependency. |
| veth + bridge | Needs CAP_NET_ADMIN in the host netns. Not possible unprivileged. |
| host netns | Works, zero isolation. Offered as explicit --net host. |
Host safety design
- No host paths writable: overlay lower dirs are only reachable through overlay (writes copy up to the container upper). Verified: write to
/usrand/etcinside leaves host untouched. - Only
/usr /etc /optand compat dirs are exposed read-through./home,/var,/sys,/rootof the host are not present. - Old root detached after pivot,
no_new_privs,/prochardened, nosuid/nodev on tmpfs/devpts/overlay. - Residual exposure (gaps): host
/etcis readable inside (any world-readable secret in it); abstract unix sockets are shared in--net host; no resource cgroups, so a container can fill the disk through its upper dir or fork-bomb within the user'sRLIMIT_NPROC; kernel attack surface of userns is that of the host kernel.
Measurements (this machine, 5 sequential attach -- true)
| Mode | Per attach |
|---|---|
| slirp | ~26 ms |
| none | ~6 ms |
Single run set, one machine; no other hardware measured.