nixos/tests/audit: init

This commit is contained in:
nikstur 2025-07-30 01:55:44 +02:00
parent 50243c5d78
commit ddefab0839
3 changed files with 40 additions and 0 deletions

View File

@ -226,6 +226,7 @@ in
atticd = runTest ./atticd.nix;
atuin = runTest ./atuin.nix;
ax25 = runTest ./ax25.nix;
audit = runTest ./audit.nix;
audiobookshelf = runTest ./audiobookshelf.nix;
auth-mysql = runTest ./auth-mysql.nix;
authelia = runTest ./authelia.nix;

37
nixos/tests/audit.nix Normal file
View File

@ -0,0 +1,37 @@
{
name = "audit";
nodes = {
machine =
{ lib, pkgs, ... }:
{
security.audit = {
enable = true;
rules = [
"-a always,exit -F exe=${lib.getExe pkgs.hello} -k nixos-test"
];
};
security.auditd.enable = true;
environment.systemPackages = [ pkgs.hello ];
};
};
testScript = ''
machine.wait_for_unit("audit-rules.service")
machine.wait_for_unit("auditd.service")
with subtest("Audit subsystem gets enabled"):
assert "enabled 1" in machine.succeed("auditctl -s")
with subtest("Custom rule produces audit traces"):
machine.succeed("hello")
print(machine.succeed("ausearch -k nixos-test -sc exit_group"))
with subtest("Stopping audit-rules.service disables the audit subsystem"):
machine.succeed("systemctl stop audit-rules.service")
assert "enabled 0" in machine.succeed("auditctl -s")
'';
}

View File

@ -17,6 +17,7 @@
enablePython ? stdenv.hostPlatform == stdenv.buildPlatform,
nix-update-script,
testers,
nixosTests,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "audit";
@ -90,6 +91,7 @@ stdenv.mkDerivation (finalAttrs: {
tests = {
musl = pkgsCross.musl64.audit;
pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
audit = nixosTests.audit;
};
};