1 import ./make-test-python.nix ({ pkgs, ... } : {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ joachifm ];
8 { lib, pkgs, config, ... }:
9 { users.users.alice = { isNormalUser = true; extraGroups = [ "proc" ]; };
10 users.users.sybil = { isNormalUser = true; group = "wheel"; };
11 imports = [ ../modules/profiles/hardened.nix ];
12 environment.memoryAllocator.provider = "graphene-hardened";
13 nix.settings.sandbox = false;
16 dhcpcd = super.dhcpcd.override { enablePrivSep = false; };
19 virtualisation.emptyDiskImages = [ 4096 ];
20 boot.initrd.postDeviceCommands = ''
21 ${pkgs.dosfstools}/bin/mkfs.vfat -n EFISYS /dev/vdb
23 virtualisation.fileSystems = {
25 device = "/dev/disk/by-label/EFISYS";
27 options = [ "noauto" ];
30 boot.extraModulePackages =
31 pkgs.lib.optional (pkgs.lib.versionOlder config.boot.kernelPackages.kernel.version "5.6")
32 config.boot.kernelPackages.wireguard;
33 boot.kernelModules = [ "wireguard" ];
38 hardened-malloc-tests = pkgs.graphene-hardened-malloc.ld-preload-tests;
41 machine.wait_for_unit("multi-user.target")
44 with subtest("AppArmor profiles are loaded"):
45 machine.succeed("systemctl status apparmor.service")
49 with subtest("AppArmor securityfs is mounted"):
50 machine.succeed("mountpoint -q /sys/kernel/security")
51 machine.succeed("cat /sys/kernel/security/apparmor/profiles")
54 # Test loading out-of-tree modules
55 with subtest("Out-of-tree modules can be loaded"):
56 machine.succeed("grep -Fq wireguard /proc/modules")
59 # Test kernel module hardening
60 with subtest("No more kernel modules can be loaded"):
61 # note: this better a be module we normally wouldn't load ...
62 machine.wait_for_unit("disable-kernel-module-loading.service")
63 machine.fail("modprobe dccp")
67 with subtest("User namespaces are restricted"):
68 machine.succeed("unshare --user true")
69 machine.fail("su -l alice -c 'unshare --user true'")
72 # Test dmesg restriction
73 with subtest("Regular users cannot access dmesg"):
74 machine.fail("su -l alice -c dmesg")
77 # Test access to kcore
78 with subtest("Kcore is inaccessible as root"):
79 machine.fail("cat /proc/kcore")
83 with subtest("Deferred mounts work"):
84 machine.fail("mountpoint -q /efi") # was deferred
85 machine.execute("mkdir -p /efi")
86 machine.succeed("mount /dev/disk/by-label/EFISYS /efi")
87 machine.succeed("mountpoint -q /efi") # now mounted
90 # Test Nix dæmon usage
91 with subtest("nix-daemon cannot be used by all users"):
92 machine.fail("su -l nobody -s /bin/sh -c 'nix --extra-experimental-features nix-command ping-store'")
93 machine.succeed("su -l alice -c 'nix --extra-experimental-features nix-command ping-store'")
96 # Test kernel image protection
97 with subtest("The kernel image is protected"):
98 machine.fail("systemctl hibernate")
99 machine.fail("systemctl kexec")
102 with subtest("The hardened memory allocator works"):
103 machine.succeed("${hardened-malloc-tests}/bin/run-tests")