-
-
Notifications
You must be signed in to change notification settings - Fork 18k
Improve security.audit{,d}
#429553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve security.audit{,d}
#429553
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,13 @@ | |
| options.security.auditd.enable = lib.mkEnableOption "the Linux Audit daemon"; | ||
|
|
||
| config = lib.mkIf config.security.auditd.enable { | ||
| boot.kernelParams = [ "audit=1" ]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might need a release note? Not sure. I am a little bit out of the loop what the kernel param does. I assume it causes the audit subsystem to start before userspace even starts up. Does it buffer the events?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll try to look into this soon. Ideally there'd be a VM test to actually test this stuff and get immediate results. My approach to looking into this will be trying to break it (i.e. try to audit pid 1), and if that breaks see whether adding that kernel parameter fixes it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should just add the kernelParam back. But to the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh? No that makes little sense.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc you can attach audit to existing processes using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, our audit module enables the audit subsystem in the kernel right now (via the IMO the audit module is there to (a) enable the audit subsystem and (b) load the rules. You can then use whatever audit daemon you like (go-audit, auditd, etc.). That's why I also think this module should set the kernelParam. The auditd module needs the audit module (to enable the audit subsystem) to receive any audit logs from the kernel. We shouldn't couple enabling the audit subsystem direclty to the daemon used.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyways, let's finish this discussion here and take it elsewhere. |
||
| # Starting auditd should also enable loading the audit rules.. | ||
| security.audit.enable = lib.mkDefault true; | ||
|
|
||
| environment.systemPackages = [ pkgs.audit ]; | ||
|
|
||
| systemd.services.auditd = { | ||
| description = "Linux Audit daemon"; | ||
| description = "Security Audit Logging Service"; | ||
| documentation = [ "man:auditd(8)" ]; | ||
| wantedBy = [ "sysinit.target" ]; | ||
| after = [ | ||
|
|
@@ -28,16 +29,26 @@ | |
| conflicts = [ "shutdown.target" ]; | ||
|
|
||
| unitConfig = { | ||
| ConditionVirtualization = "!container"; | ||
| ConditionSecurity = [ "audit" ]; | ||
| DefaultDependencies = false; | ||
| RefuseManualStop = true; | ||
| ConditionVirtualization = "!container"; | ||
| ConditionKernelCommandLine = [ | ||
| "!audit=0" | ||
| "!audit=off" | ||
| ]; | ||
| }; | ||
|
|
||
| path = [ pkgs.audit ]; | ||
|
|
||
| serviceConfig = { | ||
| ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/log/audit"; | ||
| LogsDirectory = "audit"; | ||
| ExecStart = "${pkgs.audit}/bin/auditd -l -n -s nochange"; | ||
| Restart = "on-failure"; | ||
| # Do not restart for intentional exits. See EXIT CODES section in auditd(8). | ||
| RestartPreventExitStatus = "2 4 6"; | ||
|
|
||
| # Upstream hardening settings | ||
| MemoryDenyWriteExecute = true; | ||
| LockPersonality = true; | ||
| RestrictRealtime = true; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
nikstur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| name = "audit"; | ||
nikstur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| nodes = { | ||
| machine = | ||
| { lib, pkgs, ... }: | ||
| { | ||
| security.audit = { | ||
| enable = true; | ||
| rules = [ | ||
| "-a always,exit -F exe=${lib.getExe pkgs.hello} -k nixos-test" | ||
nikstur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]; | ||
| }; | ||
| 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") | ||
| ''; | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.