aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/run-firecracker-vm/default.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 01:01:06 +0000
committertv <tv@krebsco.de>2026-11-17 01:01:06 +0000
commitff3dafcc0003ffc2d48244fcd6e98984b6a9174d (patch)
tree155a9ca9fed6d2ab3000665f724d98e8a0890937 /pkgs/run-firecracker-vm/default.nix
parent9d7f66b9cbdc203226ef919a4108706248d9779d (diff)
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.
Diffstat (limited to 'pkgs/run-firecracker-vm/default.nix')
-rw-r--r--pkgs/run-firecracker-vm/default.nix10
1 files changed, 6 insertions, 4 deletions
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}