git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests: add tests for exercising various hardening features

This test exercises the linux_hardened kernel along with the various hardening features (enabled via the hardened profile). Move hidepid test from misc, so that misc can go back to testing a vanilla configuration.

commitffa83edf4a29b21f12eb96d5eb7b63e1ebae7a5f authorJoachim Fasting <joachifm@fastmail.fm> dateSun 30 Apr 2017, 08:38 (10 years ago) parentab4fa1c
3 files changed+32−9
nixos/release.nix+1 nixos/tests/hardened.nix+31 nixos/tests/misc.nix−9
nixos/release.nix+1
@@ -248,6 +248,7 @@ in rec {
248248 tests.gocd-server = callTest tests/gocd-server.nix {};
249249 tests.gnome3 = callTest tests/gnome3.nix {};
250250 tests.gnome3-gdm = callTest tests/gnome3-gdm.nix {};
251+ tests.hardened = callTest tests/hardened.nix { };
251252 tests.hibernate = callTest tests/hibernate.nix {};
252253 tests.hound = callTest tests/hound.nix {};
253254 tests.i3wm = callTest tests/i3wm.nix {};
nixos/tests/hardened.nixnew file+31
@@ -0,0 +1,31 @@
1+import ./make-test.nix ({ pkgs, ...} : {
2+ name = "hardened";
3+ meta = with pkgs.stdenv.lib.maintainers; {
4+ maintainers = [ joachifm ];
5+ };
6+
7+ machine =
8+ { config, lib, pkgs, ... }:
9+ with lib;
10+ { users.users.alice = { isNormalUser = true; extraGroups = [ "proc" ]; };
11+ users.users.sybil = { isNormalUser = true; group = "wheel"; };
12+ imports = [ ../modules/profiles/hardened.nix ];
13+ };
14+
15+ testScript =
16+ ''
17+ # Test hidepid
18+ subtest "hidepid", sub {
19+ $machine->succeed("grep -Fq hidepid=2 /proc/mounts");
20+ $machine->succeed("[ `su - sybil -c 'pgrep -c -u root'` = 0 ]");
21+ $machine->succeed("[ `su - alice -c 'pgrep -c -u root'` != 0 ]");
22+ };
23+
24+ # Test kernel module hardening
25+ subtest "lock-modules", sub {
26+ $machine->waitForUnit("multi-user.target");
27+ # note: this better a be module we normally wouldn't load ...
28+ $machine->fail("modprobe dccp");
29+ };
30+ '';
31+})
nixos/tests/misc.nix−9
@@ -25,8 +25,6 @@ import ./make-test.nix ({ pkgs, ...} : {
2525 };
2626 users.users.sybil = { isNormalUser = true; group = "wheel"; };
2727 security.sudo = { enable = true; wheelNeedsPassword = false; };
28− security.hideProcessInformation = true;
29− users.users.alice = { isNormalUser = true; extraGroups = [ "proc" ]; };
3028 };
3129
3230 testScript =
@@ -119,12 +117,5 @@ import ./make-test.nix ({ pkgs, ...} : {
119117 subtest "sudo", sub {
120118 $machine->succeed("su - sybil -c 'sudo true'");
121119 };
122−
123− # Test hidepid
124− subtest "hidepid", sub {
125− $machine->succeed("grep -Fq hidepid=2 /proc/mounts");
126− $machine->succeed("[ `su - sybil -c 'pgrep -c -u root'` = 0 ]");
127− $machine->succeed("[ `su - alice -c 'pgrep -c -u root'` != 0 ]");
128− };
129120 '';
130121})