User and network namespaces [weekly-2026-w47]
- November 30, 2026
- Patrick Ferris
The main goal of the week was to get Merry into shape to run some benchmarks and test it qualitatively against existing tools like Docker.
User namespaces
- November 30, 2026
- Patrick Ferris
In order to bring Merry closer to existing container runtimes, I added proper support for configuring user namespaces. This, in effect, means setting up UID maps (and GID maps). User namespaces are nested (to a maximum depth of 32) and users in child namespaces inherent their meaning from maps that translate UIDs from a child to their parent.
A freshly created child process in a new user namespace defaults to no map. This, in effect, results in any UID mapping to the overlow UID and you get nobody.
$ unshare --user /bin/sh -c "whoami; id"
nobody
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
This is how you get the "fake root" set up.
$ unshare --user --map-root-user /bin/sh -c "whoami; cat /proc/self/uid_map"
root
0 1000 1
Lines in /proc/self/uid_map are of the form <start user> <start host> <length>. In the example, this says "map the next <length> users in the user namespace, starting at <start user>, to the users on the host starting at <start host>".
With a length of 1, this reduces to a 1-1 mapping saying that the root user in the user namespace maps onto user 1000 (most likely the default user on the host). UID maps (and GID maps) can only be written to once. Moreover, users without CAP_SETUID can only map a single UID into the namespace (themselves).
This is why newuidmap and newgidmap exist, allowing "rootless" containers to be able to do more sophisticated mapping.
Void now supports setting up proper UID mappings, which in turn allows it to reuse more complicated OCI images like ocaml/opam:debian which require becoming the opam user.
A pause fork action [pause-fork-action]
- November 30, 2026
- Patrick Ferris
I have dicussed fork actions before. Unfortunately, they model a very simple fork+exec API model. For void, I need to call newuidmap passing in the PID of the child before the child (a) tries to setuid and (b) calls exec!
To cope with this, void comes with a new pause fork action.
val pause : Unix.file_descr -> Eio_unix.Private.Fork_action.t
(** [pause fd] will wait until a single byte is written to [fd] in the child.*)
This mostly works, although it does require changing some of how Eio would spawn a process as it expects certain actions to have run before returning; so I'm not sure how useful that would be to upstream.
Network Namespaces [net-ns]
- November 30, 2026
- Patrick Ferris
A goal, since the very beginning of this work, has been to monitor the network traffic of a shell session. See the vpnkit dicussion and experience report.
So, I started out by copying what the rootless container world does (e.g. Podman) and reused pasta to slirp ethernet frames from a configured TAP device in the new network namespace of the container. pasta is a sophisticated network proxy server that, rootlessly, bridges the container's network with the host's.
This could reuse the pause fork action as it requires the child process's PID.
With this, I could add as Pasta-network backend to void. Spawning an OCaml Debian image is now as "simple" as:
let () =
Eio_posix.run @@ fun env ->
Switch.run @@ fun sw ->
let fs = env#fs in
let proc = env#process_mgr in
let img = Image.get_image ~fs ~proc "ocaml/opam:debian" in
let open Void in
let args = [ "/bin/sh" ] in
let uids, gids =
Void.default_maps ~subuid:(env#fs / "/etc/subuid")
~subgid:(env#fs / "/etc/subgid")
in
let net = Network.pasta proc in
let void =
empty
|> rootfs ~mode:RW img
|> network net
|> fork_actions
[
Eio_unix.Private.Fork_action.setgid 1000;
Eio_unix.Private.Fork_action.setuid 1000;
]
|> uid_map uids
|> gid_map gids
|> exec args
in
let t = Void.spawn ~process_mgr:env#process_mgr ~sw void in
let status = Promise.await (Void.exit_status t) in
Eio.traceln "Status: %a" Void.pp_exit_status status