| 
									
										
										
										
											2017-04-30 08:38:47 +02:00
										 |  |  | import ./make-test.nix ({ pkgs, ...} : { | 
					
						
							|  |  |  |   name = "hardened"; | 
					
						
							|  |  |  |   meta = with pkgs.stdenv.lib.maintainers; { | 
					
						
							|  |  |  |     maintainers = [ joachifm ]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   machine = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |     { lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2017-04-30 08:38:47 +02:00
										 |  |  |     with lib; | 
					
						
							|  |  |  |     { users.users.alice = { isNormalUser = true; extraGroups = [ "proc" ]; }; | 
					
						
							|  |  |  |       users.users.sybil = { isNormalUser = true; group = "wheel"; }; | 
					
						
							|  |  |  |       imports = [ ../modules/profiles/hardened.nix ]; | 
					
						
							| 
									
										
										
										
											2017-09-22 23:20:42 +02:00
										 |  |  |       virtualisation.emptyDiskImages = [ 4096 ]; | 
					
						
							|  |  |  |       boot.initrd.postDeviceCommands = ''
 | 
					
						
							|  |  |  |         ${pkgs.dosfstools}/bin/mkfs.vfat -n EFISYS /dev/vdb | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |       fileSystems = lib.mkVMOverride { | 
					
						
							|  |  |  |         "/efi" = { | 
					
						
							|  |  |  |           device = "/dev/disk/by-label/EFISYS"; | 
					
						
							|  |  |  |           fsType = "vfat"; | 
					
						
							|  |  |  |           options = [ "noauto" ]; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-04-30 08:38:47 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = | 
					
						
							|  |  |  |     ''
 | 
					
						
							| 
									
										
										
										
											2018-05-19 08:42:15 +02:00
										 |  |  |       $machine->waitForUnit("multi-user.target"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-30 08:38:47 +02:00
										 |  |  |       # Test hidepid | 
					
						
							|  |  |  |       subtest "hidepid", sub { | 
					
						
							|  |  |  |           $machine->succeed("grep -Fq hidepid=2 /proc/mounts"); | 
					
						
							| 
									
										
										
										
											2018-05-19 08:42:15 +02:00
										 |  |  |           # cannot use pgrep -u here, it segfaults when access to process info is denied | 
					
						
							|  |  |  |           $machine->succeed("[ `su - sybil -c 'ps --no-headers --user root | wc -l'` = 0 ]"); | 
					
						
							|  |  |  |           $machine->succeed("[ `su - alice -c 'ps --no-headers --user root | wc -l'` != 0 ]"); | 
					
						
							| 
									
										
										
										
											2017-04-30 08:38:47 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Test kernel module hardening | 
					
						
							|  |  |  |       subtest "lock-modules", sub { | 
					
						
							|  |  |  |           # note: this better a be module we normally wouldn't load ... | 
					
						
							|  |  |  |           $machine->fail("modprobe dccp"); | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-04-30 14:41:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Test userns | 
					
						
							|  |  |  |       subtest "userns", sub { | 
					
						
							|  |  |  |           $machine->fail("unshare --user"); | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-09-16 11:46:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Test dmesg restriction | 
					
						
							|  |  |  |       subtest "dmesg", sub { | 
					
						
							|  |  |  |           $machine->fail("su -l alice -c dmesg"); | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Test access to kcore | 
					
						
							|  |  |  |       subtest "kcore", sub { | 
					
						
							|  |  |  |           $machine->fail("cat /proc/kcore"); | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-09-22 23:20:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Test deferred mount | 
					
						
							|  |  |  |       subtest "mount", sub { | 
					
						
							|  |  |  |         $machine->fail("mountpoint -q /efi"); # was deferred | 
					
						
							|  |  |  |         $machine->execute("mkdir -p /efi"); | 
					
						
							|  |  |  |         $machine->succeed("mount /dev/disk/by-label/EFISYS /efi"); | 
					
						
							|  |  |  |         $machine->succeed("mountpoint -q /efi"); # now mounted | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-04-30 08:38:47 +02:00
										 |  |  |     '';
 | 
					
						
							|  |  |  | }) |