2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
|
|
|
|
let
|
2014-05-14 18:04:40 +01:00
|
|
|
customGrsecPkg =
|
|
|
|
(import ../../../pkgs/build-support/grsecurity
|
|
|
|
{ grsecOptions = config.security.grsecurity;
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
};
|
2014-05-14 18:04:40 +01:00
|
|
|
).grsecPackage;
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
security.grsecurity = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable grsecurity support. This enables advanced exploit
|
|
|
|
hardening for the Linux kernel, and adds support for
|
|
|
|
administrative Role-Based Acess Control (RBAC) via
|
|
|
|
<literal>gradm</literal>. It also includes traditional
|
|
|
|
utilities for PaX.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
stable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable the stable grsecurity patch, based on Linux 3.2.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vserver = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable the stable grsecurity/vserver patches, based on Linux 3.2.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
testing = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable the testing grsecurity patch, based on Linux 3.13.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
mode = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "auto";
|
|
|
|
example = "custom";
|
|
|
|
description = ''
|
|
|
|
grsecurity configuration mode. This specifies whether
|
|
|
|
grsecurity is auto-configured or otherwise completely
|
|
|
|
manually configured. Can either by
|
|
|
|
<literal>custom</literal> or <literal>auto</literal>.
|
|
|
|
|
|
|
|
<literal>auto</literal> is recommended.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
priority = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "security";
|
|
|
|
example = "performance";
|
|
|
|
description = ''
|
|
|
|
grsecurity configuration priority. This specifies whether
|
|
|
|
the kernel configuration should emphasize speed or
|
|
|
|
security. Can either by <literal>security</literal> or
|
|
|
|
<literal>performance</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
system = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "desktop";
|
|
|
|
description = ''
|
|
|
|
grsecurity system configuration. This specifies whether
|
|
|
|
the kernel configuration should be suitable for a Desktop
|
|
|
|
or a Server. Can either by <literal>server</literal> or
|
|
|
|
<literal>desktop</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisationConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "none";
|
|
|
|
example = "host";
|
|
|
|
description = ''
|
|
|
|
grsecurity virtualisation configuration. This specifies
|
|
|
|
the virtualisation role of the machine - that is, whether
|
|
|
|
it will be a virtual machine guest, a virtual machine
|
|
|
|
host, or neither. Can be one of <literal>none</literal>,
|
|
|
|
<literal>host</literal>, or <literal>guest</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hardwareVirtualisation = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
example = true;
|
|
|
|
description = ''
|
|
|
|
grsecurity hardware virtualisation configuration. Set to
|
|
|
|
<literal>true</literal> if your machine supports hardware
|
|
|
|
accelerated virtualisation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisationSoftware = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "kvm";
|
|
|
|
description = ''
|
|
|
|
grsecurity virtualisation software. Set this to the
|
|
|
|
specified virtual machine technology if the machine is
|
|
|
|
running as a guest, or a host.
|
|
|
|
|
|
|
|
Can be one of <literal>kvm</literal>,
|
|
|
|
<literal>xen</literal>, <literal>vmware</literal> or
|
|
|
|
<literal>virtualbox</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sysctl = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If true, then set <literal>GRKERN_SYSCTL y</literal>. If
|
|
|
|
enabled then grsecurity can be controlled using sysctl
|
|
|
|
(and turned off). You are advised to *never* enable this,
|
|
|
|
but if you do, make sure to always set the sysctl
|
|
|
|
<literal>kernel.grsecurity.grsec_lock</literal> to
|
|
|
|
non-zero as soon as all sysctl options are set. *THIS IS
|
|
|
|
EXTREMELY IMPORTANT*!
|
|
|
|
|
|
|
|
If disabled, this also turns off the
|
|
|
|
<literal>systemd-sysctl</literal> service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
denyChrootChmod = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If true, then set <literal>GRKERN_CHROOT_CHMOD
|
|
|
|
y</literal>. If enabled, this denies processes inside a
|
|
|
|
chroot from setting the suid or sgid bits using
|
|
|
|
<literal>chmod</literal> or <literal>fchmod</literal>.
|
|
|
|
|
|
|
|
By default this protection is disabled - it makes it
|
|
|
|
impossible to use Nix to build software on your system,
|
|
|
|
which is what most users want.
|
|
|
|
|
|
|
|
If you are using NixOps to deploy your software to a
|
|
|
|
remote machine, you're encouraged to enable this as you
|
|
|
|
won't need to compile code.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictProc = mkOption {
|
|
|
|
type = types.bool;
|
2014-04-12 17:16:03 +01:00
|
|
|
default = false;
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
description = ''
|
|
|
|
If true, then set <literal>GRKERN_PROC_USER
|
|
|
|
y</literal>. This restricts non-root users to only viewing
|
|
|
|
their own processes and restricts network-related
|
|
|
|
information, kernel symbols, and module information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-04-12 17:16:03 +01:00
|
|
|
restrictProcWithGroup = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
If true, then set <literal>GRKERN_PROC_USERGROUP
|
|
|
|
y</literal>. This is similar to
|
|
|
|
<literal>restrictProc</literal> except it allows a special
|
|
|
|
group (specified by <literal>unrestrictProcGid</literal>)
|
|
|
|
to still access otherwise classified information in
|
|
|
|
<literal>/proc</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
unrestrictProcGid = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = config.ids.gids.grsecurity;
|
|
|
|
description = ''
|
|
|
|
If set, specifies a GID which is exempt from
|
|
|
|
<literal>/proc</literal> restrictions (set by
|
2014-04-12 17:16:03 +01:00
|
|
|
<literal>GRKERN_PROC_USERGROUP</literal>). By default,
|
|
|
|
this is set to the GID for <literal>grsecurity</literal>,
|
|
|
|
a predefined NixOS group, which the
|
|
|
|
<literal>root</literal> account is a member of. You may
|
|
|
|
conveniently add other users to this group if you need
|
|
|
|
access to <literal>/proc</literal>
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
disableRBAC = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If true, then set <literal>GRKERN_NO_RBAC
|
|
|
|
y</literal>. This disables the
|
|
|
|
<literal>/dev/grsec</literal> device, which in turn
|
|
|
|
disables the RBAC system (and <literal>gradm</literal>).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
verboseVersion = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Use verbose version in kernel localversion.";
|
|
|
|
};
|
|
|
|
|
|
|
|
kernelExtraConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = "Extra kernel configuration parameters.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions =
|
|
|
|
[ { assertion = cfg.stable || cfg.testing;
|
|
|
|
message = ''
|
|
|
|
If grsecurity is enabled, you must select either the
|
|
|
|
stable patch (with kernel 3.2), or the testing patch (with
|
|
|
|
kernel 3.13) to continue.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{ assertion = (cfg.stable -> !cfg.testing) || (cfg.testing -> !cfg.stable);
|
|
|
|
message = ''
|
|
|
|
You must select either the stable or testing patch, not
|
|
|
|
both.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{ assertion = (cfg.testing -> !cfg.vserver);
|
|
|
|
message = "The vserver patches are only supported in the stable kernel.";
|
|
|
|
}
|
2014-04-12 17:16:03 +01:00
|
|
|
{ assertion = (cfg.config.restrictProc -> !cfg.config.restrictProcWithGroup) ||
|
|
|
|
(cfg.config.restrictProcWithGroup -> !cfg.config.restrictProc);
|
|
|
|
message = "You cannot enable both restrictProc and restrictProcWithGroup";
|
|
|
|
}
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
{ assertion = config.boot.kernelPackages.kernel.features ? grsecurity
|
|
|
|
&& config.boot.kernelPackages.kernel.features.grsecurity;
|
|
|
|
message = "grsecurity enabled, but kernel doesn't have grsec support";
|
|
|
|
}
|
|
|
|
{ assertion = elem cfg.config.mode [ "auto" "custom" ];
|
|
|
|
message = "grsecurity mode must either be 'auto' or 'custom'.";
|
|
|
|
}
|
|
|
|
{ assertion = cfg.config.mode == "auto" -> elem cfg.config.system [ "desktop" "server" ];
|
|
|
|
message = "when using auto grsec mode, system must be either 'desktop' or 'server'";
|
|
|
|
}
|
|
|
|
{ assertion = cfg.config.mode == "auto" -> elem cfg.config.priority [ "performance" "security" ];
|
|
|
|
message = "when using auto grsec mode, priority must be 'performance' or 'security'.";
|
|
|
|
}
|
|
|
|
{ assertion = cfg.config.mode == "auto" -> elem cfg.config.virtualisationConfig [ "host" "guest" "none" ];
|
|
|
|
message = "when using auto grsec mode, 'virt' must be 'host', 'guest' or 'none'.";
|
|
|
|
}
|
|
|
|
{ assertion = (cfg.config.mode == "auto" && (elem cfg.config.virtualisationConfig [ "host" "guest" ])) ->
|
|
|
|
cfg.config.hardwareVirtualisation != null;
|
|
|
|
message = "when using auto grsec mode with virtualisation, you must specify if your hardware has virtualisation extensions";
|
|
|
|
}
|
|
|
|
{ assertion = (cfg.config.mode == "auto" && (elem cfg.config.virtualisationConfig [ "host" "guest" ])) ->
|
|
|
|
elem cfg.config.virtualisationSoftware [ "kvm" "xen" "virtualbox" "vmware" ];
|
|
|
|
message = "virtualisation software must be 'kvm', 'xen', 'vmware' or 'virtualbox'";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.grsec-lock = mkIf cfg.config.sysctl {
|
|
|
|
description = "grsecurity sysctl-lock Service";
|
|
|
|
requires = [ "sysctl.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = "yes";
|
|
|
|
script = ''
|
|
|
|
locked=`cat /proc/sys/kernel/grsecurity/grsec_lock`
|
|
|
|
if [ "$locked" == "0" ]; then
|
|
|
|
echo 1 > /proc/sys/kernel/grsecurity/grsec_lock
|
|
|
|
echo grsecurity sysctl lock - enabled
|
|
|
|
else
|
|
|
|
echo grsecurity sysctl lock already enabled - doing nothing
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# systemd.services.grsec-learn = {
|
|
|
|
# description = "grsecurity learning Service";
|
|
|
|
# wantedBy = [ "local-fs.target" ];
|
|
|
|
# serviceConfig = {
|
|
|
|
# Type = "oneshot";
|
|
|
|
# RemainAfterExit = "yes";
|
|
|
|
# ExecStart = "${pkgs.gradm}/sbin/gradm -VFL /etc/grsec/learning.logs";
|
|
|
|
# ExecStop = "${pkgs.gradm}/sbin/gradm -D";
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
|
|
|
|
system.activationScripts.grsec =
|
|
|
|
''
|
|
|
|
mkdir -p /etc/grsec
|
|
|
|
if [ ! -f /etc/grsec/learn_config ]; then
|
|
|
|
cp ${pkgs.gradm}/etc/grsec/learn_config /etc/grsec
|
|
|
|
fi
|
|
|
|
if [ ! -f /etc/grsec/policy ]; then
|
|
|
|
cp ${pkgs.gradm}/etc/grsec/policy /etc/grsec
|
|
|
|
fi
|
|
|
|
chmod -R 0600 /etc/grsec
|
|
|
|
'';
|
|
|
|
|
2014-05-07 23:59:29 +01:00
|
|
|
# Enable AppArmor, gradm udev rules, and utilities
|
nixos: add grsecurity module (#1875)
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 <aseipp@pobox.com>
2014-04-06 20:18:12 +01:00
|
|
|
security.apparmor.enable = true;
|
|
|
|
boot.kernelPackages = grsecPackage;
|
|
|
|
services.udev.packages = [ pkgs.gradm ];
|
|
|
|
environment.systemPackages = [ pkgs.gradm pkgs.paxctl pkgs.pax-utils ];
|
|
|
|
};
|
|
|
|
}
|