From ff3dafcc0003ffc2d48244fcd6e98984b6a9174d Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 01:01:06 +0000 Subject: per-user egress rules The host module takes users = { NAME = TAPS; ... } instead of a single user: each user gets that many taps, and rules of their own, in /var/lib/fc-egress/USER/allowed, managed with fc-egress as before. The proxy tells whose a guest is by its address: each tap has a fixed one, handed out by dnsmasq by MAC address (derived from the tap's number, as the run script does), and the bridge drops anything a guest sends from another address. The decrypting server gets a socket per user, as it can't see the guest's address. The run script only takes the user's own taps. --- pkgs/run-firecracker-vm/default.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pkgs/run-firecracker-vm/default.nix') diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index 37423a8..37047b0 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -370,11 +370,13 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' args="$args systemd.tty.rows.ttyS0=$rows systemd.tty.columns.ttyS0=$cols" fi - # Take the first tap device (see modules/host) that no other VM holds. The - # lock is held until the script exits. The MAC address is derived from - # the tap's number, so the VM gets the same DHCP lease every time. + # Take the first tap device of the user's (see modules/host) that no other + # VM holds. The lock is held until the script exits. The MAC address is + # derived from the tap's number, as modules/host does, for the tap's + # fixed address. tap= for t in $(find /sys/class/net -maxdepth 1 -name 'fctap*' -printf '%f\n' | sort -V); do + test "$(cat /sys/class/net/$t/owner)" = "$(id -u)" || continue exec {lock}>"''${XDG_RUNTIME_DIR:-/tmp}/run-firecracker-vm.$t.lock" if flock -n "$lock"; then tap=$t @@ -383,7 +385,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' exec {lock}>&- done if test -z "$tap"; then - echo "$0: no free tap device fctap*, see modules/host" >&2 + echo "$0: no free tap device fctap* of $(id -un)'s, see modules/host" >&2 exit 1 fi n=''${tap#fctap} -- cgit v1.3.1