Running Sparewall as a VM#

A mini PC with two 2.5 GbE ports and 16 GB of RAM is far more than a firewall needs. To run other services on it, put a hypervisor on the bare metal (Proxmox, or libvirt on a general-purpose Linux host) and run Sparewall as one VM among others. VMs are a first-class target: the release ships a .qcow2 disk image, the CI suites run Sparewall in VMs, and the image carries the QEMU guest agent.

It is easy to get wrong, though, in ways that quietly bypass the firewall. This guide is about doing it safely, on the usual two-port hardware with no VLANs (getting started): the WAN on one port, the LAN, management and (in a pair) sync on the other.

The trade-off#

The firewall now depends on the hypervisor. A hypervisor exploit, a misconfigured bridge, or a host that holds an address on the WAN puts the host, and everything on it, past the firewall. Keep the hypervisor patched, keep its own management off the WAN, and treat its admin access like the firewall's. If that is more than you want to own, run Sparewall on its own hardware.

Keep the host's services off the WAN#

The one rule that matters: the host has no address and no route on the WAN. The host's own management (its web UI, SSH, updates) is on the LAN, behind Sparewall, like any other machine, so nothing on the host answers anyone on the internet.

That limits what the host exposes; it does not keep the WAN out of the host. With a bridge, the host's kernel owns the physical WAN port and forwards its frames: it still handles the WAN's layer 2 traffic (broadcasts, multicast, every frame it bridges), and a compromised host could watch or tamper with it. Only PCI passthrough, below, keeps WAN frames out of the host's network stack entirely.

Check it on the host:

ip -br addr show            # the WAN port and its bridge: no IPv4 or global IPv6 address
ip route show default       # the host's default route is via Sparewall's LAN address

An IPv6 link-local address (fe80::) on the WAN bridge is harmless only if nothing listens on it; better, turn IPv6 off on that bridge (net.ipv6.conf.<bridge>.disable_ipv6 = 1 in /etc/sysctl.d/).

Passthrough or bridges#

On a two-NIC mini PC, bridges are the usual choice: a WAN bridge on one port with no host address, and a LAN bridge on the other carrying the host's own management and the other VMs.

Proxmox#

The bridges, in /etc/network/interfaces (the port names are examples):

auto vmbr0                   # the LAN: the host's management lives here
iface vmbr0 inet static
    address 192.168.1.5/24
    gateway 192.168.1.1      # Sparewall's LAN address
    bridge-ports enp2s0
    bridge-stp off
    bridge-fd 0

auto vmbr1                   # the WAN: no address at all
iface vmbr1 inet manual
    bridge-ports enp1s0
    bridge-stp off
    bridge-fd 0

The VM, from the release's .qcow2 (identity.json as in getting started, its management NIC the LAN NIC's MAC):

qm create 100 --name fw1 --memory 2048 --cores 2 --machine q35 \
    --bios ovmf --efidisk0 local-lvm:1,efitype=4m,pre-enrolled-keys=0 \
    --tpmstate0 local-lvm:1,version=v2.0 \
    --net0 virtio=52:54:00:aa:00:01,bridge=vmbr1,firewall=0 \
    --net1 virtio=52:54:00:aa:00:02,bridge=vmbr0,firewall=0 \
    --agent enabled=1 \
    --onboot 1 --startup order=1,up=60 \
    --args "-smbios type=11,value=io.systemd.credential.binary:sparewall.identity=$(base64 -w0 identity.json)"
qm importdisk 100 sparewall-VERSION-x86_64.qcow2 local-lvm   # prints the disk's name
qm set 100 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-100-disk-N --boot order=scsi0
qm start 100

libvirt#

Bridges br-wan (no address) and br-lan (the host's management), made with NetworkManager, systemd-networkd or /etc/network/interfaces, then:

virt-install --name fw1 --memory 2048 --vcpus 2 \
    --import --disk sparewall-VERSION-x86_64.qcow2,bus=virtio \
    --boot uefi --tpm emulator,model=tpm-crb,version=2.0 \
    --network bridge=br-wan,model=virtio,mac=52:54:00:aa:00:01 \
    --network bridge=br-lan,model=virtio,mac=52:54:00:aa:00:02 \
    --channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
    --sysinfo type=fwcfg,entry0.name=opt/io.systemd.credentials/sparewall.identity,entry0.file=identity.json \
    --osinfo linux2022 --noautoconsole
virsh autostart fw1

Keep clean-traffic and any other <filterref> off both interfaces. libvirt starts autostarted domains in no particular order: to start Sparewall before VMs that need the network, start those from a systemd unit ordered after it, or delay their autostart.

Start and stop order#

The other VMs' networks depend on the firewall: start it first and stop it last. On a host that reboots for updates, that keeps the LAN's gateway, DHCP and DNS up for as long as anything uses them.

Pairs#

This page on GitHub, at v0.7.0