nixos: add grsecurity module (RFC)#1875
Conversation
There was a problem hiding this comment.
First of all, again: great work!
Minor comment here: why have an option for RANDSTRUCT (and not the other grsec config options)?
I would rather let GRKERNSEC_CONFIG_AUTO determine whether to enable or disable RANDSTRUCT than let NixOS make the decision for me (unless there is a good reason).
And if some user wants to force-enable/force-disable this option he could just use kernelExtraConfig, right?
There was a problem hiding this comment.
This is sort of on an as-needed basis, at the moment. Should there be coverage for every option? Ideally, that would be the case. But there are a lot of options.
Second, RANDSTRUCT is here because as I said above it breaks the vbox guest networking drivers, meaning it's impossible to do things like test grsec kernels in VirtualBox with NixOps. I have not yet discovered why this is the case (in particular other modules are compiled with the correct entropy string as a part of RANDSTRUCT). However, it does not break other modules, meaning RANDSTRUCT can be deployed successfully e.g. on Hetzner (where it works great).
I don't know how to predicate this on whether or not we're being deployed inside a VirtualBox guest - does anyone know how to do that? Then RANDSTRUCT can be an option, but optionally toggled if it might break something for the moment.
This also brings up a good point in that duplicated kernelExtraConfig options will be ignored (or possibly error) the kernel configuration script. So maybe we should make everything an actual option...
There was a problem hiding this comment.
Perhaps it's not the best way (and it's certainly not fool-proof), but in most cases we can find out if the system is going to be running as a VirtualBox guest if config.services.virtualbox.enable == true.
But if we're not running as a VirtualBox guest, I would rather not define RANDSTRUCT in the kernel config unless the user specified it...
|
Bah, I'll just continue adding comments here otherwise this will get even more messy. Just to clarify one of your comments, if I'm reading the I think the option will be defined as "y", i.e., the later definitions override the earlier ones. |
|
BTW, this is why when you define these options in the module: ... they don't get ignored or error out, even though they are already defined in |
|
Comments as of the current state:
Apart from these issues, I would be OK with getting it merged, even if your TODO items are not all fixed yet. |
|
Current status:
|
|
👍 to your latest changes :) Of course, this is a large change and I'm also a bit unsure about the sysctl and kernel config changes, so we'll definitely have to get a more experienced person reviewing this as well. |
There was a problem hiding this comment.
I just noticed: sha256 = sha256 can be better written as inherit sha256
|
This looks really cool, guys! Thank you for doing this. |
|
Is there any way we can hook into |
|
And is there any way we can have something akin to |
|
Relaying some stuff I told Shea on IRC as answers to his questions:
|
|
Does this depend on the nixpkgs changes that were last-minute removed from @vcunat's stdenv branch to be useful? Or should it be merged as-is? |
|
This doesn't depend on #1187 at all - all the needed packages are already upstream, although obviously it's a bummer that PR wasn't merged. I just need to rebase these changes and squash them up a bit to make them more coherent. |
|
OK. Let me know when you do, I don't think github pings when new commits are pushed to a PR. |
|
Ok, for now I have pushed the gradm commits, as they are simple fixes. |
|
I just took another look at your latest changes and I think it looks good 👍 BTW, not sure what's up with the all the Haskell and the musl commits... Regarding the comments above, here's what I think:
|
Realistically, common-config is useful, but there are a lot of things in there that are non-optionally specified that aren't always useful. For example, when deploying grsecurity, I don't want the bluetooth, wireless, or input joystick/extra filesystem stack (XFS, etc), nor the staging drivers tree. The problem is that if you specify this in your own kernel config in the grsecurity module, by saying 'BT n' to turn off bluetooth, common-config turns on 'BT_HCIUART_BCSP y', which then becomes unused and errors out. This is really just an arbitrary picking at the moment, but it should be OK. Signed-off-by: Austin Seipp <aseipp@pobox.com>
This module is a work-in-progress which refactors grsecurity support into a module, which can be easily enabled from a users
configuration.nix.There are a few reasons for doing this: the current way of enabling grsec support is incredibly un-nix like, as it requires choosing a kernel package and then appropriate options. This is error prone, and requires a lot of work for users when they really want an easy way to do it.
Second, grsec naturally encompasses some other things that can only be handled by a module, that are beyond the kernel package: in particular, mutable files must be installed appropriately into
/etc/grsec(asgradmwill use/update the policy files). There are also needed udev rules for/dev/grsec. Furthermore, some options likeGRKERNSEC_CHROOT_CHMODare extremely incompatible with Nix, and make it impossible to install software. So by default, the module disables this (although it works great if you deploy with NixOps).Also, some options are incompatible in other ways: for example,
GRKERNSEC_RANDSTRUCTbreaks the virtualbox guest networking drivers (a bug I need to send to grsec upstream), andGRKERNSEC_LINKbreaks on the 3.13.5 testing kernel (but not the 3.2 stable kernel). Also, if you disablesysctlsupport, things likesystemd-sysctlmust be disabled as they won't work.Overall, having a module take care of this means there's a lot less pain. This module naturally takes control of
boot.kernelPackages- I'm not sure how much precedent there is for that, but I think it's reasonable given the purpose.This also moves the grsecurity overrides out of the kernel package and into the module itself, leaving only the patches in
pkgs, which I think is probably where it belongs anyway.Finally, as the grsecurity patches imply
config.apparmor=true, the module also turns apparmor on as the patches are included (which is easily overlooked).This is my first 'big' NixOS module that's not simply a service, so I'd appreciate input. If we can land this in some form, more exciting work can happen soon, including enforcement/management of RBAC policies and userspace hardening.
Here's an example of enabling the configuration:
I'm using this configuration with NixOps, and am successfully deploying Linux 3.13.5-grsec onto Hetzner with this module.
There are some things left TODO:
systemd.services.systemd-sysctl.enablegets shadowed rather than cleanly disabled it appears, meaning I probably got this wrong somehow.systemd-sysctlconfig) if specified withnull.kptr_restrictisnullif grsecurity is enabled../locaversion-grsecafter patchinggrsec-lockservice for configurations that enable sysctl supportgradmmodule for RBAC control. Ideally most of this could be declarative.RANDSTRUCTandGRKERNSEC_LINKScommon-configkernel options optional/cc @wizeman