From 86d6f7341fedd5e0e78969d2c37829a0012dc3ae Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 21 Nov 2026 04:10:08 +0000 Subject: host: static addresses for VMs, by name, on whichever tap they run A VM got the first free tap of its user's, and a tap's address came from its number, so a VM's address depended on what else ran, and on the users before it, and a reverse proxy on the host could only guess it (172.16.0.2, i.e. fctap0, for hermes). Now addresses are the VMs': the host module takes vms, VM name -> user and address (vms = { hermes = { user = "tv"; ip = "172.16.0.2"; }; }), any number of them, and a VM takes any free tap of its user's, which gets its address while it runs, so at most as many run at the same time as the user has taps. Taps have addresses of their own, for VMs without one: from 172.16.0.200 on, so they stand out (but for VMs' there). The MAC address, which dnsmasq hands out every address by, is 06:00 and the address (06:00:ac:10:00:02 for 172.16.0.2), and with it the IPv6 addresses; the run script takes the VM's from /etc/fc-vms, or the tap's own from /etc/fc-taps. The VMs' addresses are also in config.fc.vms.NAME (user, ip, ip6), for the host's configuration, e.g. proxyPass = "http://${config.fc.vms.hermes.ip}:9120"; Which address a tap has is up to fcbr0-firewall, which now also runs when a tap's VM's name (/run/fc-egress/TAP.name, which the run script writes) changes: the VM's, if it's one of the tap's user's in vms and on none of their other taps, too, else the tap's own. It puts it into the tap's new nftables sets addr_TAP and addr6_TAP, in the bridge's table, which lets the tap send from nothing else (instead of the static set guests), and in the other, whose per-tap rules go by them (instead of the tap's fixed addresses); and into /run/fcbr0-addr, ADDRESS: TAP and TAP: ADDRESS, where egress.lua finds a guest's tap (as long as both agree, and the address and the tap are the same user's), and the run script waits for its address before starting the guest. fc-egress vms shows the taps' addresses, too. --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 422d100..5b81928 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,26 @@ imports = [ that many tap devices. This sets up a bridge `fcbr0` (172.16.0.1/24, and fdfc:fc::1/64) with the taps, DHCP and DNS for the guests, the egress proxy, and nftables rules that keep the guests from reaching anything else, on the -host, beyond, or each other. Each tap has a fixed address, and the bridge -drops anything a guest sends from another, so the proxy knows whose a -connection is. It needs `networking.nftables` (and enables it). +host, beyond, or each other. Each running VM has a fixed address, and +the bridge drops anything a guest sends from another, so the proxy knows +whose a connection is. It needs `networking.nftables` (and enables it). Optional arguments: +- `vms`: static addresses for VMs, by name and user (172.16.0.2 to .254), + e.g. for the host to reach them with a reverse proxy: + `vms = { hermes = { user = "tv"; ip = "172.16.0.2"; }; };`. Any + number of them; the user's VM of that name (`--name hermes`) gets its + address on whichever of the user's taps it runs, so at most as many of + them run at the same time as the user has taps. Taps have addresses of + their own, for VMs without one: from 172.16.0.200 on, so they stand + out (but for VMs' there; at most 55 taps in all). The VMs' + addresses are also in `config.fc.vms.NAME` (`user`, `ip`, `ip6`): + + ```nix + services.nginx.virtualHosts."hermes.example".locations."/".proxyPass = + "http://${config.fc.vms.hermes.ip}:9120"; + ``` - `proxyPort` (default 10443): where the proxy listens; the guests' port 443 gets redirected there. - `prefix6` (default `fdfc:fc::`): the guests' IPv6 /64. Each guest @@ -122,7 +136,8 @@ Who may log in goes in a layer, e.g.: { users.users.root.openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAA..." ]; } ``` -A guest on tap fctapN is 172.16.0.(N+2) (see `fc-egress vms`). +A guest's address is its VM's, by name (`vms`, see host setup), or else +its tap's own (see `fc-egress vms`). The guest's system can be built in layers, each a NixOS module on top of the ones before (the first on top of the base system): @@ -175,7 +190,7 @@ named like the VM, else (no name) `default`: fc-egress -l box allow https://cache.nixos.org ./result/bin/run-firecracker-vm --name box # list box ./result/bin/run-firecracker-vm --name box2 --egress box # list box, too -fc-egress vms # running VMs: tap (as in the log), name, list +fc-egress vms # running VMs: tap (as in the log), address, name, list fc-egress -v box allow https://example.org # the list box uses fc-egress use box default # switch box to another list ``` -- cgit v1.3.1