# `vmTests..tuwunel-fallocate-probe`: runs the hive's real tuwunel # fallocate probe (../host-modules/lib/tuwunel-fallocate-probe.nix) in a VM, # under the sandbox of nixpkgs' tuwunel unit, which the module-eval suite can # only read. That sandbox denies the `@ipc` group (`SystemCallFilter`), which # has `pipe`, so a probe that makes a pipe (a command substitution) fails there # and says nothing. # # `tuwunel-probe-check` is tuwunel's own `serviceConfig`, with the probe and # the environment file the hive adds, and `env` as the command: its journal # shows what `ExecStart` would be given. `tuwunel-pipe-control` is the same # sandbox around a command substitution, and has to log that bash cannot make # a pipe (bash still exits 0): it shows the sandbox in this VM does filter # pipes. Two nodes: `cow` has a btrfs at `/mnt/cow`, which the probe answers # with the override; `plain` is probed at `/var/lib` on the root filesystem and # gets none. { pkgs }: let probeLib = import ../host-modules/lib/tuwunel-fallocate-probe.nix { inherit pkgs; }; pipeControl = pkgs.writeShellScript "pipe-control" '' x=$(true) ''; node = dir: { config, lib, ... }: let sandbox = removeAttrs config.systemd.services.tuwunel.serviceConfig [ "ExecStart" "ExecStartPre" "Restart" "RestartSec" ]; in { services.matrix-tuwunel = { enable = true; settings.global.server_name = "t.local"; }; # The real unit stays stopped: only the sandbox is wanted from it. systemd.services.tuwunel.wantedBy = lib.mkForce [ ]; systemd.services.tuwunel-probe-check.serviceConfig = sandbox // { Type = "oneshot"; ExecStart = "${pkgs.coreutils}/bin/env"; } // probeLib.serviceConfig dir; systemd.services.tuwunel-pipe-control.serviceConfig = sandbox // { Type = "oneshot"; ExecStart = "${pipeControl}"; }; }; in pkgs.testers.runNixOSTest { name = "tuwunel-fallocate-probe"; # Without this the driver allows an hour, the runner's whole job limit. globalTimeout = 900; nodes.cow = { imports = [ (node "/mnt/cow") ]; virtualisation.emptyDiskImages = [ 256 ]; boot.supportedFilesystems = [ "btrfs" ]; }; nodes.plain = node "/var/lib"; testScript = '' start_all() cow.wait_for_unit("multi-user.target") plain.wait_for_unit("multi-user.target") def journal(m, unit: str) -> str: return m.succeed(f"journalctl -u {unit} --no-pager -o cat") with subtest("the sandbox filters pipes: a command substitution cannot make one in it"): # bash exits 0 after a failed pipe, so the unit starts: its journal has the verdict. for m in (cow, plain): m.succeed("systemctl start tuwunel-pipe-control") out = journal(m, "tuwunel-pipe-control") assert "cannot make pipe for command substitution: Operation not permitted" in out, out with subtest("on btrfs the probe sets the override, and the unit's command is given it"): cow.succeed("mkfs.btrfs -q /dev/vdb && mkdir -p /mnt/cow && mount /dev/vdb /mnt/cow") cow.succeed("systemctl start tuwunel-probe-check") out = journal(cow, "tuwunel-probe-check") assert "tuwunel-fallocate-probe: /mnt/cow is on filesystem type 9123683e" in out, out assert "TUWUNEL_ROCKSDB_ALLOW_FALLOCATE=false" in out, out with subtest("elsewhere the probe reads the type and leaves the default"): plain.succeed("systemctl start tuwunel-probe-check") out = journal(plain, "tuwunel-probe-check") assert "tuwunel-fallocate-probe: /var/lib is on filesystem type " in out, out assert "TUWUNEL_ROCKSDB_ALLOW_FALLOCATE" not in out, out ''; }