summary refs log tree commit diff
path: root/nixos/modules/security/misc.nix
blob: 42f872b7b088355d74a953e130c05badbea1e26e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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`.";
      }
    ];
  };
}