diff options
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index b6e5387..5b148da 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -306,6 +306,7 @@ in pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # usage: run-firecracker-vm [--store FILE] [--store-size SIZE] # [--nixpkgs DIR] [--nixpkgs-cache MODE] + # [--egress LIST] # The guest gets the host's store, read-only, via 9P over vsock, and the # directory xchg (in the current working directory) at /xchg, the same # way. VMs started in the same directory share it. Also the same way, @@ -319,15 +320,18 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # when the guest exits, or with --store, to FILE, which keeps it across # boots (created if it doesn't exist, of --store-size, default 16G; the # file is sparse, so that's only an upper limit). + # The guest's egress goes by the user's whitelist LIST (default: + # default), see modules/host and fc-egress. set -efu - export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.e2fsprogs pkgs.findutils pkgs.gnused pkgs.util-linux pkgs.firecracker pkgs.unpfs ]} + export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.e2fsprogs pkgs.findutils pkgs.gnugrep pkgs.gnused pkgs.util-linux pkgs.firecracker pkgs.unpfs ]} usage() { - echo "usage: $0 [--store FILE] [--store-size SIZE] [--nixpkgs DIR] [--nixpkgs-cache MODE]" + echo "usage: $0 [--store FILE] [--store-size SIZE] [--nixpkgs DIR] [--nixpkgs-cache MODE] [--egress LIST]" } args= rw_store= rw_store_size=16G + egress=default nixpkgs=${lib.escapeShellArg (toString pkgs.path)} while test $# -gt 0; do case $1 in @@ -336,6 +340,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' --store-size) rw_store_size=$2; shift 2 ;; --nixpkgs) nixpkgs=$2; shift 2 ;; --nixpkgs-cache) args="$args fc.9p566=cache=$2"; shift 2 ;; + --egress) egress=$2; shift 2 ;; -h|--help) usage; exit ;; *) usage >&2; exit 1 esac @@ -396,6 +401,21 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' exit 1 fi n=''${tap#fctap} + # The guest's whitelist: modules/host goes by the name in the tap's file + # in /run/fc-egress (emptied again when the guest exits, below). + vm=/run/fc-egress/$tap + if test -w "$vm"; then + if ! printf %s "$egress" | grep -qxE '[A-Za-z0-9_-]+'; then + echo "$0: bad list name: $egress" >&2 + exit 1 + fi + if ! test -f "/var/lib/fc-egress/$(id -un)/$egress"; then + echo "$0: no list $egress (see fc-egress), no egress" >&2 + fi + printf '%s\n' "$egress" > "$vm" + else + vm= + fi mac=$(printf '06:00:ac:10:%02x:%02x' $((n >> 8 & 255)) $((n & 255))) # The 9P servers, for the store, /xchg, and nixpkgs, one each per VM. @@ -415,7 +435,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' xchg=$! RUST_LOG=off unpfs "unix!$tmp/vsock!_566" "$nixpkgs" > /dev/null & nixpkgs_server=$! - trap 'kill $store $xchg $nixpkgs_server; rm -rf "$tmp"' EXIT + trap 'kill $store $xchg $nixpkgs_server; rm -rf "$tmp"; if test -n "$vm"; then : > "$vm"; fi' EXIT while ! test -S "$vsock"_565; do sleep 0.01; done sed \ |
