-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Conversation
|
fyi: i do have some changes to the auditd module in #420043. That said, those changes are not directly touching the service, so while a merge conflict will happen, the changes themselves seem orthogonal. |
|
Also: Audit is already part of every nixos closure, simply from being a dependency of systemd. These module changes don't actually change that fact. Its good to try and do some cleanup, but some of the motivation seems invalid to me. |
The |
|
I have now picked this onto my auditd testsuite branch at https://github.com/LordGrimmauld/nixpkgs/commits/audit-testing-full/ and will be building the nixos test. Compiling the packages will take a bit, but the upstream testsuite is quite exhaustive. I just recently adopted audit and am still in the process of cleaning it all up. Your help is appreciated, but this also means a lot of my changes are not yet merged (like #420043 and #429438) or even submitted for review (such as the |
|
So uh, something is very wrong. The relevant errors (as far as i can see): So it seems auditd starts too early, and this is indeed a regression. Please fix. |
Very cool! Glad that someone is taking care of it. I mostly care about being able to disable this to not rely on bash (i.e. this commit: 19d79d2b918969c4832276a5969464e01fb2e105) as part of the Bashless Activation initiative. Although I think all the changes make a lot of sense and are easy wins, I'd be willing to reduce the scope of this PR to only 19d79d2b918969c4832276a5969464e01fb2e105 if that helps you. |
|
Thanks! With the most recent push to https://github.com/LordGrimmauld/nixpkgs/commits/audit-testing-full/, the testsuite now passes. And fair enough, you couldn't have known about the additional testsuite work i was doing. The test suite complains about I'll take a look at the overall nix changes, now that the CI and unofficial tests pass. |
LordGrimmauld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple thoughts, mostly nits and a request for more testing. Overall looks good though, and the cleanup is long overdue! The last PR touching audit module significantly was back in 2016...
Please don't, your changes are good! This is for the better, just needs some care to not unknowingly break things, now that someone (me) actually cares. |
Align with upstream and also remove unnecessary dependency on bash along the way.
Remove config that doesn't make senes at all or on NixOS specifically.
LordGrimmauld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am almost happy with this, this is definitely moving in the right direction!
2b786b8 to
8429939
Compare
LordGrimmauld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this work, no complaints from me left
Thank you for the review. Learned a little more about audit on the way! |
|
One more thing that we didn't do in this PR due to mass rebuild but we do require to solve more race conditions : We should move the service to use Reason why we need Otherwise things like https://github.com/systemd/systemd/blob/922885e0a5b729a3faaba35676b37013f323d309/units/systemd-update-utmp.service.in#L16 are racey. |
|
I imagine that too would fall under respecting |
|
We should probably set |
|
I don't see how that'd fix all the hardcoded |
| options.security.auditd.enable = lib.mkEnableOption "the Linux Audit daemon"; | ||
|
|
||
| config = lib.mkIf config.security.auditd.enable { | ||
| boot.kernelParams = [ "audit=1" ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the auditd docs they do say:
A boot param of audit=1 should be added to ensure that all processes that run before the audit daemon starts is marked as auditable by the kernel. Not doing that will make a few processes impossible to properly audit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just add the kernelParam back. But to the audit module and not the auditd module!.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh? No that makes little sense. auditd is there for the userspace auditing, our audit module is only there for rules. And you can enable audit(d) without adding any rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc you can attach audit to existing processes using auditctl later, but only if those processes were started either after auditd or with the kernel flag. Which would mean that is entirely independent of our rule-loading module.
I might be mistaken, i have some reading to do to get this right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our audit module is only there for rules. And you can enable audit(d) without adding any rules.
No, our audit module enables the audit subsystem in the kernel right now (via the -e rule). This is what our test shows. Enabling just the audit daemon does not enable the audit subsystem (because of the -s nochange, see https://man.archlinux.org/man/auditd.8.en#s=).
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyways, let's finish this discussion here and take it elsewhere.
|
Update: since linux-audit/audit-userspace@4ade146, upstream now officially tries to respect |
|
Great stuff! |
The audit module behaved very weirdly. Instead of being guarded behind an
mkIfit would start a "disable" script if the service wasn't enabled. This would thus always pull in the service makingpkgs.audit(the bin output) a mandatory part of every NixOS system closure (the lib output has always been because of systemd).@arianvp also reported that this sometimes led to race conditions with journald which also tries to communicate with the audit subsystem. This PR fixes this behaviour and along the way gets rid of unnecessary (mandatory) bash script.
The
auditandauditdmodule are aligned with upstream and some weird options are removed. For exampleConditionSecurity = [ "audit" ];which doesn't make sense to set becauseaudit-rulesis supposed to enable the subsystem in the first place. The only reason this has ever worked in the past is because of some unfortunate misbehaviour of journald (which would enable the audit subsystem itself).To summarize:
security.auditis now responsible for loading the audit rules and enabling the audit subsystem.security.auditdis only responsible for starting auditd.Closes #11864
This isssue can now be closed from my perspective. Shipping default rules might be possible but can be tracked separately.
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.