User and network namespaces › Network Namespaces [net-ns]

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