From b050c6af6aedbe78201addb4abe2636ab075d14e Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 01:59:29 +0000 Subject: host: harden against users turning on the host or each other - denyDestinations (default: loopback, private, link-local, CGNAT, multicast, ...): no user's rules can open those, neither tcp:// and udp:// rules nor the proxy, whatever a name resolves to: nginx's own outgoing connections may only go to port 443 outside them, and not to the host. tcp:// rules no longer open anything on the host itself. - fcbr0-firewall no longer runs as root, but with only CAP_NET_ADMIN, doesn't follow symlinks, and gets started per user when that user's rules change, so one user can't stop the others' updates. Rules files are read up to 64k only, by egress.lua, too. - Limits per guest (maxConnections open, maxNewConnections per second), and per user in nginx, so one user can't starve the others. - tcp:// and udp:// connections, and refused ones, get logged (rate-limited) with the user; fc-egress log shows them. - The run script keeps its lock files in a directory of the user's own, not in /tmp, where others could take them first. --- pkgs/run-firecracker-vm/default.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pkgs') diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index 37047b0..b6e5387 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -374,10 +374,17 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # 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. + # Lock files in a directory of the user's own: in /tmp, another user + # could take them first. + lockdir=''${XDG_RUNTIME_DIR:-/run/user/$(id -u)} + if ! test -d "$lockdir" -a -O "$lockdir"; then + echo "$0: $lockdir isn't a directory of $(id -un)'s; set XDG_RUNTIME_DIR" >&2 + exit 1 + fi 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" + exec {lock}>"$lockdir/run-firecracker-vm.$t.lock" if flock -n "$lock"; then tap=$t break -- cgit v1.3.1