aboutsummaryrefslogtreecommitdiffstats
path: root/host.nix
Commit message (Collapse)AuthorAgeFilesLines
* move the host module to modules/hosttv10 days1-316/+0
| | | | | egress.lua goes along. The host now imports it as (import .../modules/host { user = ...; }).
* move the runner to pkgs/run-firecracker-vmtv10 days1-2/+2
| | | | | So default.nix (or shell.nix, flake.nix) at the top can become something else. kernel.nix goes along, as it's only an argument of the runner.
* host: only let the guests reach dnsmasq and nginxtv10 days1-2/+27
| | | | | | | | | Nothing got forwarded, but the host itself was wide open to the guests: its own services (sshd, ...) at 172.16.0.1, where DNS sends every name, or any of its other addresses, and ICMP. Now the input chain rejects everything from fcbr0 but DHCP and DNS to dnsmasq and the redirected TLS to nginx. And a bridge table drops frames between the taps, so the guests can't talk to each other either.
* host: make room for big response headerstv10 days1-0/+6
| | | | | | | github.com's response headers are bigger than nginx's default buffer for them, so requests got a 502 ("upstream sent too big header"). Give them 64k. Also remove a stale decrypt.sock before starting, else nginx can't bind to it.
* egress through nginx+lua, with path rulestv10 days1-80/+123
| | | | | | | | | | | | | | OpenResty replaces the plain nginx SNI proxy, and egress.lua decides by server name and the rules in /var/lib/fc-egress/allowed: DOMAIN passes the domain and its subdomains through without decrypting; DOMAIN/PREFIX decrypts, with certificates made on the fly from the host's own CA, and only forwards requests whose path starts with PREFIX. Upstream is always port 443 of the server name, as resolved by the host, and its certificate gets verified. The rules get read on every connection, so the path unit and reloads are gone. The CA certificate gets published as /var/lib/fcbr0-egress/ca.pem, and the guest trusts it when built on the host.
* host: run the SNI proxy on port 10443, redirect the guests' 443 theretv10 days1-7/+15
| | | | | | | The host's own web server listens on 0.0.0.0:443, which keeps nginx from binding to 172.16.0.1:443. nginx now listens on 172.16.0.1:proxyPort (default 10443), and nftables redirects the guests' tcp port 443 there, whatever address they connect to.
* host: make sure nginx gets to bind to 172.16.0.1tv10 days1-2/+8
| | | | | | | | With networkd, fcbr0 only got its address while it had carrier, i.e. while a VM was running, so nginx failed with "bind() to 172.16.0.1:443 failed (99: Cannot assign requested address)" and gave up after a few restarts. Configure fcbr0 without carrier, and let nginx retry without start limit until the address is there.
* make egress transparent: SNI proxy instead of squidtv10 days1-48/+95
| | | | | | | | | The guests' DNS now resolves every name to 172.16.0.1, where nginx reads the server name from the TLS ClientHello and, if it's allowed, connects to port 443 of that name as resolved by the host. The guests need no proxy settings any more, and a faked server name can't get them to any other address. fc-egress keeps managing the list (now plain domains), and a reload regenerates nginx's map from it.
* egress through squid with an allowlist managed by fc-egresstv10 days1-47/+135
| | | | | | | | | | | Instead of forwarding to addresses dnsmasq resolved for allowed names, nothing gets forwarded from fcbr0 any more (and no NAT). The guests use squid on 172.16.0.1:3128 as their proxy, which only allows CONNECT to port 443 of the domains in /var/lib/fc-egress/allowed. That list can be changed at any time with fc-egress (list, allow, deny, log); a path unit makes squid re-read it. DNS answers NXDOMAIN for everything. host.nix no longer takes allowedDomains.
* restrict the guests' egress to https to allowed domainstv10 days1-14/+55
| | | | | | | | | | host.nix takes allowedDomains (default none). The guests' dnsmasq only resolves those names and their subdomains, answers NXDOMAIN for anything else, and adds the addresses it resolves to an nftables set. The new table inet firecracker rejects everything from fcbr0 except tcp port 443 to addresses in that set. dnsmasq runs without cache, so it refills the set after an nftables reload, and without AAAA records, as the guests only have IPv4.
* let the guests' dnsmasq be their DNS resolver tootv10 days1-11/+13
| | | | | | It forwards to the servers in the host's resolv.conf and listens only on fcbr0, so it doesn't get in the way of a resolver on the host's loopback. The service is renamed from fcbr0-dhcp to fcbr0-dnsmasq.
* use the host's DNS resolvertv10 days1-2/+3
| | | | | The guest's resolv.conf and the DHCP server now point at 172.16.0.1, so the host's resolver has to answer there.
* get guest addresses via DHCP, one tap device per VMtv10 days1-7/+41
| | | | | | | | | | host.nix now makes a bridge fcbr0 with a number of tap devices (default 8) and runs a dnsmasq of its own for DHCP. The run script takes the first tap device it can lock and derives the guest MAC from its number. The guest uses DHCP, with the MAC as client identifier, as the machine-id (and thus the default DUID) is the same in every VM. host.nix now takes { user, taps ? 8 } instead of just the user.
* add networkingtv11 days1-0/+15
Give the guest a virtio-net interface backed by the host tap device fctap0, with a static address (172.16.0.2/24, gateway 172.16.0.1) set up by systemd-networkd, and 9.9.9.9 as nameserver. host.nix is a NixOS module for the host that creates fctap0, owned by the given user, and NATs it: imports = [ (import ./host.nix "tv") ]; Firecracker refuses to start if fctap0 doesn't exist.