-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
nixos: add grsecurity module (RFC) #1875
Conversation
GRKERNSEC_SYSCTL ${boolToKernOpt cfg.config.sysctl} | ||
GRKERNSEC_CHROOT_CHMOD ${boolToKernOpt cfg.config.denyChrootChmod} | ||
GRKERNSEC_NO_RBAC ${boolToKernOpt cfg.config.disableRBAC} | ||
GRKERNSEC_RANDSTRUCT ${boolToKernOpt cfg.config.randstruct} |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
inherit grversion kversion revision; | ||
patch = fetchurl { | ||
url = "http://grsecurity.net/${branch}/grsecurity-${grversion}-${kversion}-${revision}.patch"; | ||
sha256 = sha256; |
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 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 <[email protected]>
This module implements a significant refactoring in grsecurity configuration for NixOS, making it far more usable by default and much easier to configure. - New security.grsecurity NixOS attributes. - All grsec kernels supported - Allows default 'auto' grsec configuration, or custom config - Supports custom kernel options through kernelExtraConfig - Defaults to high-security - user must choose server/desktop mode, and any virtualisation software. That's all. - kptr_restrict is fixed under grsecurity (it's unwriteable) - grsecurity patch creation is now significantly abstracted - only need revision, version, and SHA1 - kernel version requirements are asserted for sanity - built kernels can have the uname specify the exact grsec version for development or bug reports. Off by default (requires `security.grsecurity.config.verboseVersion = true;`) - grsecurity sysctl support - By default, disabled. - For people who enable it, NixOS deploys a 'grsec-lock' systemd service which runs at startup. You are expected to configure sysctl through NixOS like you regularly would, which will occur before the service is started. As a result, changing sysctl settings requires a reboot. - New default group: 'grsecurity' - Root is a member by default - GRKERNSEC_PROC_GID is implicitly set to the 'grsecurity' GID, making it possible to easily add users to this group for /proc access - AppArmor is now automatically enabled where it wasn't before, despite implying features.apparmor = true The most trivial example of enabling grsecurity in your kernel is by specifying: security.grsecurity.enable = true; security.grsecurity.testing = true; # enable testing 3.13 kernel security.grsecurity.config.priority = "performance" # or "security" security.grsecurity.config.system = "desktop"; # or "server" This specifies absolutely no virtualisation support. In general, you probably at least want KVM host support, which is a little more work. So: security.grsecurity.enable = true; security.grsecurity.stable = true; # enable stable 3.2 kernel security.grsecurity.config = { system = "server"; priority = "security"; virtualisationConfig = "host"; virtualisationSoftware = "kvm"; hardwareVirtualisation = true; } This configuration has primarily been tested on a Hetzner EX40 & VQ7 with NixOps. Signed-off-by: Austin Seipp <[email protected]>
This module implements a significant refactoring in grsecurity configuration for NixOS, making it far more usable by default and much easier to configure. - New security.grsecurity NixOS attributes. - All grsec kernels supported - Allows default 'auto' grsec configuration, or custom config - Supports custom kernel options through kernelExtraConfig - Defaults to high-security - user must choose kernel, server/desktop mode, and any virtualisation software. That's all. - kptr_restrict is fixed under grsecurity (it's unwriteable) - grsecurity patch creation is now significantly abstracted - only need revision, version, and SHA1 - kernel version requirements are asserted for sanity - built kernels can have the uname specify the exact grsec version for development or bug reports. Off by default (requires `security.grsecurity.config.verboseVersion = true;`) - grsecurity sysctl support - By default, disabled. - For people who enable it, NixOS deploys a 'grsec-lock' systemd service which runs at startup. You are expected to configure sysctl through NixOS like you regularly would, which will occur before the service is started. As a result, changing sysctl settings requires a reboot. - New default group: 'grsecurity' - Root is a member by default - GRKERNSEC_PROC_GID is implicitly set to the 'grsecurity' GID, making it possible to easily add users to this group for /proc access - AppArmor is now automatically enabled where it wasn't before, despite implying features.apparmor = true The most trivial example of enabling grsecurity in your kernel is by specifying: security.grsecurity.enable = true; security.grsecurity.testing = true; # testing 3.13 kernel security.grsecurity.config.system = "desktop"; # or "server" This specifies absolutely no virtualisation support. In general, you probably at least want KVM host support, which is a little more work. So: security.grsecurity.enable = true; security.grsecurity.stable = true; # enable stable 3.2 kernel security.grsecurity.config = { system = "server"; priority = "security"; virtualisationConfig = "host"; virtualisationSoftware = "kvm"; hardwareVirtualisation = true; } This module has primarily been tested on Hetzner EX40 & VQ7 servers using NixOps. Signed-off-by: Austin Seipp <[email protected]>
This is now merged in HEAD. |
See #2213 for the follow up for kernel configuration options. |
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
(asgradm
will use/update the policy files). There are also needed udev rules for/dev/grsec
. Furthermore, some options likeGRKERNSEC_CHROOT_CHMOD
are 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_RANDSTRUCT
breaks the virtualbox guest networking drivers (a bug I need to send to grsec upstream), andGRKERNSEC_LINK
breaks on the 3.13.5 testing kernel (but not the 3.2 stable kernel). Also, if you disablesysctl
support, things likesystemd-sysctl
must 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.enable
gets shadowed rather than cleanly disabled it appears, meaning I probably got this wrong somehow.systemd-sysctl
config) if specified withnull
.kptr_restrict
isnull
if grsecurity is enabled../locaversion-grsec
after patchinggrsec-lock
service for configurations that enable sysctl supportgradm
module for RBAC control. Ideally most of this could be declarative.RANDSTRUCT
andGRKERNSEC_LINKS
common-config
kernel options optional/cc @wizeman