2015-12-30 04:52:24 -05:00
# qubes-mirage-firewall
2016-01-01 10:21:28 -05:00
A unikernel that can run as a QubesOS ProxyVM, replacing `sys-firewall` .
2015-12-30 04:52:24 -05:00
It uses the [mirage-qubes][] library to implement the Qubes protocols.
2016-01-02 03:34:39 -05:00
See [A Unikernel Firewall for QubesOS][] for more details.
2018-01-06 07:09:26 -05:00
## Binary releases
Pre-built binaries are available from the [releases page][].
2019-04-26 07:38:36 -04:00
See the [Deploy ](#deploy ) section below for installation instructions.
2018-01-06 07:09:26 -05:00
## Build from source
2017-01-09 11:45:16 -05:00
2023-12-26 05:12:06 -05:00
Note: The most reliable way to build is using Docker or Podman.
2023-11-07 07:47:12 -05:00
Fedora 38 works well for this, Debian 12 also works, but you'll need to follow the instructions at [docker.com][debian-docker] to get Docker
2020-10-26 11:38:14 -04:00
(don't use Debian's version).
2019-12-13 19:24:55 -05:00
2023-11-08 06:13:11 -05:00
Create a new Fedora-38 AppVM (or reuse an existing one). In the Qube's Settings (Basic / Disk storage), increase the private storage max size from the default 2048 MiB to 8192 MiB. Open a terminal.
2019-11-27 11:01:58 -05:00
2023-12-26 05:12:06 -05:00
Clone this Git repository and run the `build-with.sh` script with either `docker` or `podman` as argument (Note: The `chcon` call is mandatory on Fedora with new SELinux policies which do not allow to standardly keep the docker images in homedir):
2017-01-09 11:45:16 -05:00
2019-07-28 07:33:43 -04:00
mkdir /home/user/docker
2019-05-30 23:50:33 -04:00
sudo ln -s /home/user/docker /var/lib/docker
2023-10-13 03:21:40 -04:00
sudo chcon -Rt container_file_t /home/user/docker
2018-11-04 09:33:47 -05:00
sudo dnf install docker
2017-01-09 11:45:16 -05:00
sudo systemctl start docker
2019-02-26 11:57:40 -05:00
git clone https://github.com/mirage/qubes-mirage-firewall.git
2017-01-09 11:45:16 -05:00
cd qubes-mirage-firewall
2023-12-26 05:12:06 -05:00
sudo ./build-with.sh docker
2017-01-09 11:45:16 -05:00
2023-12-26 05:12:06 -05:00
Or
sudo systemctl start podman
git clone https://github.com/mirage/qubes-mirage-firewall.git
cd qubes-mirage-firewall
./build-with.sh podman
2017-01-09 11:45:16 -05:00
2023-11-07 07:47:12 -05:00
This took about 15 minutes on my laptop (it will be much quicker if you run it again).
2023-12-26 05:12:06 -05:00
The symlink step at the start isn't needed if your build VM is standalone. It gives Docker more disk space and avoids losing the Docker image cache when you reboot the Qube.
It's not needed with Podman as the containers lives in your home directory by default.
2017-01-09 11:45:16 -05:00
2019-02-01 04:25:29 -05:00
Note: the object files are stored in the `_build` directory to speed up incremental builds.
If you change the dependencies, you will need to delete this directory before rebuilding.
2023-12-26 05:12:06 -05:00
It's OK to install the Docker or Podman package in a template VM if you want it to remain
2019-04-08 05:23:34 -04:00
after a reboot, but the build of the firewall itself should be done in a regular AppVM.
2023-12-26 05:12:06 -05:00
You can also build without that script, as for any normal Mirage unikernel;
2017-03-18 13:59:06 -04:00
see [the Mirage installation instructions ](https://mirage.io/wiki/install ) for details.
2016-01-01 10:21:28 -05:00
2023-12-26 05:12:06 -05:00
The build script fixes the versions of the libraries it uses, ensuring that you will get
exactly the same binary that is in the release. If you build without it, it will build
2019-04-08 05:23:34 -04:00
against the latest versions instead (and the hash will therefore probably not match).
However, it should still work fine.
2017-01-09 11:45:16 -05:00
## Deploy
2023-08-17 18:27:06 -04:00
### Manual deployment
2024-11-27 11:05:39 -05:00
If you want to deploy manually, you just need to download `qubes-firewall.xen` and
`qubes-firewall.sha256` in domU and check that the `.xen` file has a corresponding
hashsum. `qubes-firewall.xen` is the unikernel itself and should be copied to
`vmlinuz` in the `/var/lib/qubes/vm-kernels/mirage-firewall` directory in dom0, e.g.
(if `dev` is the AppVM where you built it):
2020-06-19 19:16:29 -04:00
[tal@dom0 ~]$ mkdir -p /var/lib/qubes/vm-kernels/mirage-firewall/
[tal@dom0 ~]$ cd /var/lib/qubes/vm-kernels/mirage-firewall/
2024-11-27 11:05:39 -05:00
[tal@dom0 mirage-firewall]$ qvm-run -p dev 'cat mirage-firewall/qubes-firewall.xen' > vmlinuz
2018-01-06 07:09:26 -05:00
2020-10-26 11:38:14 -04:00
Run this command in dom0 to create a `mirage-firewall` VM using the `mirage-firewall` kernel you added above
2018-01-06 07:09:26 -05:00
```
qvm-create \
--property kernel=mirage-firewall \
2020-10-24 06:43:08 -04:00
--property kernelopts='' \
2022-10-06 12:06:18 -04:00
--property memory=32 \
--property maxmem=32 \
2018-01-06 07:09:26 -05:00
--property netvm=sys-net \
--property provides_network=True \
--property vcpus=1 \
2020-10-26 11:38:14 -04:00
--property virt_mode=pvh \
2018-01-06 07:09:26 -05:00
--label=green \
--class StandaloneVM \
mirage-firewall
2020-06-19 04:56:33 -04:00
qvm-features mirage-firewall qubes-firewall 1
2020-10-26 11:38:14 -04:00
qvm-features mirage-firewall no-default-kernelopts 1
2018-01-06 07:09:26 -05:00
```
2023-08-17 18:27:06 -04:00
### Deployment using saltstack
2023-08-23 08:48:29 -04:00
If you're familiar how to run salt states in Qubes, you can also use the script `SaltScriptToDownloadAndInstallMirageFirewallInQubes.sls` to automatically deploy the latest version of mirage firewall in your Qubes OS. An introduction can be found [here ](https://forum.qubes-os.org/t/qubes-salt-beginners-guide/20126 ) and [here ](https://www.qubes-os.org/doc/salt/ ). Following the instructions from the former link, you can run the script in dom0 with the command `sudo qubesctl --show-output state.apply SaltScriptToDownloadAndInstallMirageFirewallInQubes saltenv=user` . The script checks the checksum from the integration server and compares with the latest version provided in the github releases. It might be necessary to adjust the VM templates in the script which are used for downloading of the mirage unikernel, if your default templates do not have the tools `curl` and `tar` installed by default. Also don't forget to change the VMs in which the uni kernel should be used or adjust the "Qubes Global Settings".
2023-08-17 18:27:06 -04:00
2020-10-26 11:38:14 -04:00
## Upgrading
2019-04-04 06:04:09 -04:00
To upgrade from an earlier release, just overwrite `/var/lib/qubes/vm-kernels/mirage-firewall/vmlinuz` with the new version and restart the firewall VM.
2018-01-06 07:09:26 -05:00
### Configure AppVMs to use it
2017-04-07 08:07:07 -04:00
You can run `mirage-firewall` alongside your existing `sys-firewall` and you can choose which AppVMs use which firewall using the GUI.
2018-01-06 07:09:26 -05:00
To configure an AppVM to use it, go to the app VM's settings in the GUI and change its `NetVM` from `default (sys-firewall)` to `mirage-firewall` .
You can also configure it by running this command in dom0 (replace `my-app-vm` with the AppVM's name):
```
qvm-prefs --set my-app-vm netvm mirage-firewall
```
Alternatively, you can configure `mirage-firewall` to be your default firewall VM.
2019-05-29 10:22:15 -04:00
Note that by default dom0 uses sys-firewall as its "UpdateVM" (a proxy for downloading updates).
mirage-firewall cannot be used for this, but any Linux VM should be fine.
https://www.qubes-os.org/doc/software-update-dom0/ says:
> The role of UpdateVM can be assigned to any VM in the Qubes VM Manager, and
> there are no significant security implications in this choice. By default,
> this role is assigned to the firewallvm.
2023-06-30 11:06:17 -04:00
### Configure firewall with OpenBSD-like netvm
OpenBSD is currently unable to be used as netvm, so if you want to use a BSD as your sys-net VM, you'll need to set its netvm to qubes-mirage-firewall (see https://github.com/mirage/qubes-mirage-firewall/issues/146 for more information).
That means you'll have `AppVMs -> qubes-mirage-firewall <- OpenBSD` with the arrow standing for the netvm property setting.
In that case you'll have to tell qubes-mirage-firewall which AppVM client should be used as uplink:
```
qvm-prefs --set mirage-firewall -- kernelopts '--ipv4=X.X.X.X --ipv4-gw=Y.Y.Y.Y'
```
with `X.X.X.X` the IP address for mirage-firewall and `Y.Y.Y.Y` the IP address of your OpenBSD HVM.
2019-05-03 05:45:15 -04:00
### Components
This diagram show the main components (each box corresponds to a source `.ml` file with the same name):
< p align = 'center' >
< img src = "./diagrams/components.svg" / >
< / p >
Ethernet frames arrives from client qubes (such as `work` or `personal` ) or from `sys-net` .
2020-05-19 10:48:48 -04:00
Internet (IP) packets are sent to `firewall` , which consults the NAT table and the rules from QubesDB to decide what to do with the packet.
2019-05-03 05:45:15 -04:00
If it should be sent on, it uses `router` to send it to the chosen destination.
`client_net` watches the XenStore database provided by dom0
to find out when clients need to be added or removed.
The boot process:
- `config.ml` describes the libraries used and static configuration settings (NAT table size).
The `mirage` tool uses this to generate `main.ml` .
- `main.ml` initialises the drivers selected by `config.ml`
and calls the `start` function in `unikernel.ml` .
- `unikernel.ml` connects the Qubes agents, sets up the networking components,
and then waits for a shutdown request.
2018-01-06 07:09:26 -05:00
### Easy deployment for developers
2016-01-01 10:21:28 -05:00
2022-03-30 03:12:01 -04:00
For development, use the [test-mirage][] scripts to deploy the unikernel (`qubes-firewall.xen`) from your development AppVM.
2018-01-06 07:09:26 -05:00
This takes a little more setting up the first time, but will be much quicker after that. e.g.
2015-12-30 04:52:24 -05:00
2023-10-13 03:21:40 -04:00
[user@dev ~]$ test-mirage dist/qubes-firewall.xen mirage-firewall
2015-12-30 04:52:24 -05:00
Waiting for 'Ready'... OK
2022-08-13 10:59:09 -04:00
Uploading 'dist/qubes-firewall.xen' (7454880 bytes) to "mirage-test"
2015-12-30 04:52:24 -05:00
Waiting for 'Booting'... OK
2022-08-13 10:59:09 -04:00
Connecting to mirage-test console...
Solo5: Xen console: port 0x2, ring @0x00000000FEFFF000
| ___|
__ | _ \ | _ \ __ \
\__ \ ( | | ( | ) |
____ /\___/ _|\___/____/
Solo5: Bindings version v0.7.3
2022-10-06 12:06:18 -04:00
Solo5: Memory map: 32 MB addressable:
2022-08-13 10:59:09 -04:00
Solo5: reserved @ (0x0 - 0xfffff)
2022-10-06 12:06:18 -04:00
Solo5: text @ (0x100000 - 0x319fff)
Solo5: rodata @ (0x31a000 - 0x384fff)
Solo5: data @ (0x385000 - 0x53ffff)
Solo5: heap >= 0x540000 < stack < 0x2000000
2022-08-13 10:59:09 -04:00
2022-08-13 14:55:38 -00:00: INF [qubes.rexec] waiting for client...
2022-08-13 14:55:38 -00:00: INF [qubes.db] connecting to server...
2022-08-13 14:55:38 -00:00: INF [qubes.db] connected
2022-08-13 14:55:38 -00:00: INF [qubes.db] got update: "/mapped-ip/10.137.0.20/visible-ip" = "10.137.0.20"
2022-08-13 14:55:38 -00:00: INF [qubes.db] got update: "/mapped-ip/10.137.0.20/visible-gateway" = "10.137.0.23"
2022-10-06 12:06:18 -04:00
2022-08-13 14:55:38 -00:00: INF [qubes.rexec] client connected, using protocol version 3
2022-08-13 10:59:09 -04:00
2022-08-13 14:55:38 -00:00: INF [unikernel] QubesDB and qrexec agents connected in 0.041 s
2022-08-13 14:55:38 -00:00: INF [dao] Got network configuration from QubesDB:
NetVM IP on uplink network: 10.137.0.4
Our IP on uplink network: 10.137.0.23
Our IP on client networks: 10.137.0.23
DNS resolver: 10.139.1.1
2022-10-06 12:06:18 -04:00
DNS secondary resolver: 10.139.1.2
2022-08-13 10:59:09 -04:00
2022-08-13 14:55:38 -00:00: INF [net-xen frontend] connect 0
2022-08-13 14:55:38 -00:00: INF [net-xen frontend] create: id=0 domid=1
2022-08-13 14:55:38 -00:00: INF [net-xen frontend] sg:true gso_tcpv4:true rx_copy:true rx_flip:false smart_poll:false
2022-08-13 14:55:38 -00:00: INF [net-xen frontend] MAC: 00:16:3e:5e:6c:00
2022-08-13 14:55:38 -00:00: INF [ethernet] Connected Ethernet interface 00:16:3e:5e:6c:00
2022-08-13 14:55:38 -00:00: INF [ARP] Sending gratuitous ARP for 10.137.0.23 (00:16:3e:5e:6c:00)
2022-08-13 14:55:38 -00:00: INF [ARP] Sending gratuitous ARP for 10.137.0.23 (00:16:3e:5e:6c:00)
2022-08-13 14:55:38 -00:00: INF [udp] UDP layer connected on 10.137.0.23
2022-08-13 14:55:38 -00:00: INF [dao] Watching backend/vif
2022-10-06 12:06:18 -04:00
2022-08-13 14:55:38 -00:00: INF [memory_pressure] Writing meminfo: free 20MiB / 27MiB (72.68 %)
2015-12-30 04:52:24 -05:00
2020-04-29 09:58:01 -04:00
# Testing if the firewall works
2020-05-19 10:48:48 -04:00
A unikernel which tests the firewall is available in the `test/` subdirectory.
To use it, run `test.sh` and follow the instructions to set up the test environment.
2020-04-29 09:58:01 -04:00
2019-04-26 07:38:36 -04:00
# Security advisories
See [issues tagged "security" ](https://github.com/mirage/qubes-mirage-firewall/issues?utf8=%E2%9C%93&q=label%3Asecurity+ ) for security advisories affecting the firewall.
2015-12-30 04:52:24 -05:00
2024-10-17 08:01:31 -04:00
# LICENSE
See [LICENSE.md ](https://github.com/mirage/qubes-mirage-firewall/blob/main/LICENSE.md )
2015-12-30 04:52:24 -05:00
[test-mirage]: https://github.com/talex5/qubes-test-mirage
2019-02-26 11:57:40 -05:00
[mirage-qubes]: https://github.com/mirage/mirage-qubes
2016-01-02 03:34:39 -05:00
[A Unikernel Firewall for QubesOS]: http://roscidus.com/blog/blog/2016/01/01/a-unikernel-firewall-for-qubesos/
2019-02-26 11:57:40 -05:00
[releases page]: https://github.com/mirage/qubes-mirage-firewall/releases
2019-04-08 05:23:34 -04:00
[debian-docker]: https://docs.docker.com/install/linux/docker-ce/debian/#install-using-the-repository