summary refs log tree commit diff
path: root/nixos/modules/security/misc.nix
diff options
context:
space:
mode:
authorJoachim Fasting <joachifm@fastmail.fm>2018-10-15 00:39:26 +0200
committerJoachim Fasting <joachifm@fastmail.fm>2018-10-15 23:11:37 +0200
commitf4ea22e5de572efa9babc7674fdc79fa637a7e31 (patch)
tree9e0e7f1626d5c307f2861b662a63df08de943fd9 /nixos/modules/security/misc.nix
parent20c4986c4dd9b014991c619498ae6ef09aa5d0aa (diff)
downloadnixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.tar
nixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.tar.gz
nixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.tar.bz2
nixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.tar.lz
nixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.tar.xz
nixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.tar.zst
nixpkgs-f4ea22e5de572efa9babc7674fdc79fa637a7e31.zip
nixos/security/misc: init
A module for security options that are too small to warrant their own module.

The impetus for adding this module is to make it more convenient to override
the behavior of the hardened profile wrt user namespaces.
Without a dedicated option for user namespaces, the user needs to
1) know which sysctl knob controls userns
2) know how large a value the sysctl knob needs to allow e.g.,
   Nix sandbox builds to work

In the future, other mitigations currently enabled by the hardened profile may
be promoted to options in this module.
Diffstat (limited to 'nixos/modules/security/misc.nix')
-rw-r--r--nixos/modules/security/misc.nix39
1 files changed, 39 insertions, 0 deletions
diff --git a/nixos/modules/security/misc.nix b/nixos/modules/security/misc.nix
new file mode 100644
index 00000000000..42f872b7b08
--- /dev/null
+++ b/nixos/modules/security/misc.nix
@@ -0,0 +1,39 @@
+{ config, lib, ... }:
+
+with lib;
+
+{
+  meta = {
+    maintainers = [ maintainers.joachifm ];
+  };
+
+  options = {
+    security.allowUserNamespaces = mkOption {
+      type = types.bool;
+      default = true;
+      description = ''
+        Whether to allow creation of user namespaces.  A recurring problem
+        with user namespaces is the presence of code paths where the kernel's
+        permission checking logic fails to account for namespacing, instead
+        permitting a namespaced process to act outside the namespace with the
+        same privileges as it would have inside it.  This is particularly
+        damaging in the common case of running as root within the namespace.
+        When user namespace creation is disallowed, attempting to create
+        a user namespace fails with "no space left on device" (ENOSPC).
+      '';
+    };
+  };
+
+  config = mkIf (!config.security.allowUserNamespaces) {
+    # Setting the number of allowed user namespaces to 0 effectively disables
+    # the feature at runtime.  Note that root may raise the limit again
+    # at any time.
+    boot.kernel.sysctl."user.max_user_namespaces" = 0;
+
+    assertions = [
+      { assertion = config.nix.useSandbox -> config.security.allowUserNamespaces;
+        message = "`nix.useSandbox = true` conflicts with `!security.allowUserNamespaces`.";
+      }
+    ];
+  };
+}