infrastructure/modules/nixos/dgn-audit.nix
catvayor a1fc8f8cfe
Some checks failed
Check meta / check_dns (pull_request) Successful in 16s
Check meta / check_dns (push) Successful in 16s
Check meta / check_meta (pull_request) Successful in 16s
Check workflows / check_workflows (push) Successful in 17s
Check workflows / check_workflows (pull_request) Successful in 18s
Check meta / check_meta (push) Successful in 19s
Build all the nodes / netcore00 (pull_request) Successful in 23s
Build all the nodes / netaccess01 (pull_request) Successful in 24s
Build all the nodes / ap01 (pull_request) Successful in 38s
Build all the nodes / netcore02 (pull_request) Successful in 22s
Build all the nodes / netcore01 (pull_request) Successful in 23s
Run pre-commit on all files / pre-commit (pull_request) Successful in 31s
Build all the nodes / bridge01 (pull_request) Successful in 1m14s
Build all the nodes / hypervisor02 (pull_request) Successful in 1m20s
Build all the nodes / hypervisor01 (pull_request) Successful in 1m20s
Build all the nodes / geo02 (pull_request) Successful in 1m21s
Build all the nodes / build01 (pull_request) Successful in 1m21s
Build all the nodes / storage01 (pull_request) Failing after 1m6s
Build all the nodes / hypervisor03 (pull_request) Successful in 1m23s
Build all the nodes / cof02 (pull_request) Successful in 1m25s
Build all the nodes / tower01 (pull_request) Successful in 1m7s
Build the shell / build-shell (pull_request) Successful in 48s
Build all the nodes / rescue01 (pull_request) Successful in 1m13s
Build all the nodes / web02 (pull_request) Successful in 1m3s
Build all the nodes / geo01 (pull_request) Successful in 1m33s
Build all the nodes / compute01 (pull_request) Successful in 1m54s
Build all the nodes / web01 (pull_request) Successful in 1m29s
Build all the nodes / web03 (pull_request) Successful in 1m42s
Build all the nodes / vault01 (pull_request) Successful in 2m2s
Build all the nodes / netcore02 (push) Successful in 22s
Build all the nodes / netcore00 (push) Successful in 22s
Build all the nodes / netaccess01 (push) Successful in 23s
Build all the nodes / netcore01 (push) Successful in 24s
Build the shell / build-shell (push) Successful in 27s
Run pre-commit on all files / pre-commit (push) Successful in 32s
Build all the nodes / ap01 (push) Successful in 36s
Build all the nodes / bridge01 (push) Successful in 55s
Build all the nodes / geo02 (push) Successful in 1m13s
Build all the nodes / hypervisor01 (push) Successful in 1m15s
Build all the nodes / storage01 (push) Failing after 1m14s
Build all the nodes / tower01 (push) Successful in 1m18s
Build all the nodes / geo01 (push) Successful in 1m19s
Build all the nodes / hypervisor02 (push) Successful in 1m20s
Build all the nodes / rescue01 (push) Successful in 1m21s
Build all the nodes / cof02 (push) Successful in 1m22s
Build all the nodes / build01 (push) Successful in 1m24s
Build all the nodes / web03 (push) Successful in 1m23s
Build all the nodes / hypervisor03 (push) Successful in 1m56s
Build all the nodes / web02 (push) Successful in 2m2s
Build all the nodes / vault01 (push) Successful in 2m9s
Build all the nodes / web01 (push) Successful in 2m50s
Build all the nodes / compute01 (push) Successful in 2m52s
feat(modules/dgn-audit): init
2025-04-16 07:54:17 +02:00

88 lines
2.5 KiB
Nix

# SPDX-FileCopyrightText: 2025 Lubin Bailly <lubin.bailly@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{
config,
lib,
pkgs,
...
}:
let
inherit (lib)
mkIf
mkMerge
mkOption
;
inherit (lib.types)
enum
;
cfg = config.dgn-audit;
in
{
options.dgn-audit = {
audit-level = mkOption {
type = enum [
"disabled"
"normal"
"high"
];
default = "normal";
description = ''
Level of auditing configuration.
'';
};
};
config = mkIf (cfg.audit-level != "disabled") {
security.audit = mkMerge [
{
backlogLimit = 8192;
rules = [
# toute les modifs de /etc
"-a exit,always -F arch=b64 -F dir=/etc -F perm=wa"
"-a exit,always -F arch=b32 -F dir=/etc -F perm=wa"
# toute les executions des binaires de kmod
"-a exit,always -F dir=${pkgs.kmod} -F perm=x"
# tout les mount/umount (on ignore systemd-executor qui en fait mass pour les credentials)
"-a exit,always -F exe!=${pkgs.systemd}/lib/systemd/systemd-executor -S mount,umount2"
# monitor des syscalls "louche", ou qui devrait rester rare
"-a exit,always -S ioperm,modify_ldt,get_kernel_syms,ptrace"
"-a exit,always -F arch=b64 -S init_module,delete_module,finit_module"
# TODO: filter on operation for prctl, else it's too hard on logging
# look PR_PAC_RESET_KEYS PR_SET_VMA PR_SET_PTRACER
# "-a exit,always -S prctl"
];
}
(mkIf (cfg.audit-level == "high") {
enable = "lock";
failureMode = "panic";
rules = [
# tout les execve
"-a exit,always -F arch=b64 -S execve,execveat"
"-a exit,always -F arch=b32 -S execve,execveat"
# tout les unlink, renomage de truc ou suppression de dossier
"-a exit,always -F arch=b64 -S unlink,rmdir,rename"
# toute les creation/ouverture/troncature de fichier qui ont raté faute de droit
"-a exit,always -F arch=b64 -S creat,open,openat,truncate,ftruncate -F exit=-EACCES"
];
})
(mkIf (cfg.audit-level == "normal") {
enable = true;
rules = [
# les execve priviligé
"-a exit,always -F arch=b64 -F uid=0 -S execve,execveat"
"-a exit,always -F arch=b32 -F uid=0 -S execve,execveat"
"-a exit,always -F arch=b64 -F euid=0 -S execve,execveat"
"-a exit,always -F arch=b32 -F euid=0 -S execve,execveat"
];
})
];
services.journald.audit = true;
};
}