sector-f-linux

Sector F Linux
git clone https://git.sectorflabs.com/sector-f-linux.git
Log | Files | Refs | README | LICENSE

0003-apps-run-in-thin-jails.md (2877B)


      1 # 0003. Apps run in thin jails on their base
      2 
      3 Date: 2026-10-15
      4 
      5 ## Status
      6 
      7 Proposed; made the fallback by ADR-0005: only apps whose dependencies can't be bundled run
      8 this way, and it isn't built until one needs it.
      9 
     10 ## Context
     11 
     12 An app names the base it was built on, by digest (ADR-0002). Something has to run it on that
     13 base, whatever image the machine itself has booted, without root.
     14 
     15 FreeBSD has done this for 25 years with thin jails (as Bastille and iocage build them): a
     16 release (`14.3-RELEASE`) kept once and shared read-only into every jail with nullfs, each jail
     17 only its own files on top (often a ZFS clone), and upgrading the host leaves each jail on the
     18 release it was made with until it's moved. That is the shape wanted here: the base is the
     19 release, the app folder is the jail.
     20 
     21 On Linux the same is built from parts: user and mount namespaces, bind mounts and overlayfs, as
     22 bubblewrap, toolbox and rootless podman do. Unlike a jail, which is one kernel feature with its
     23 edge built in, the parts make it easy to leave holes.
     24 
     25 ## Decision
     26 
     27 - **A small, strict runner** starts each app in its own namespaces: the base's `/usr` as its
     28   system, its own folder, the user's home, and a fixed list of what else it gets: the Wayland,
     29   PipeWire and D-Bus sockets, fonts, the cursor and theme, locale, `/etc/resolv.conf`. Anything
     30   not on the list isn't there.
     31 - **On the base the machine booted**, the app's `/usr` is the system's own: nothing to fetch,
     32   no extra disk, next to no cost.
     33 - **On an older base**, its layers are fetched once into a user-level store
     34   (`~/.local/share/patina/layers` or similar) and shared by every app that names it. Stored with
     35   composefs (which bootc uses already), so two bases share every file they have in common, not
     36   just whole layers.
     37 - **GPU drivers always come from the running system**, whatever the base: Mesa has to be new
     38   enough for the hardware, and NVIDIA's userspace must match the kernel module exactly. Flatpak
     39   and nvidia-container-toolkit do the same.
     40 - **On FreeBSD the runner can be a jail**: the same `app.toml`, a jail there and namespaces on
     41   Linux. The base there is a FreeBSD release, so the app needs a FreeBSD binary (ADR-0002), or
     42   runs its Linux one through the Linuxulator.
     43 
     44 ## Consequences
     45 
     46 - Apps never break when the system updates; old bases are kept as long as an app names them.
     47 - Ubuntu (since 24.04) allows unprivileged user namespaces only to programs with an AppArmor
     48   profile that permits them; the runner ships with one in the image.
     49 - The list of what reaches an app is the security boundary, so it's short and changes only on
     50   purpose. A sandbox with permissions (as Flatpak's portals) can grow from it later.
     51 - Setting up the namespaces costs milliseconds, and mounts can be kept per base.
     52 - Old bases cost disk until no app names them; something has to notice and remove them.