Skip to content

Commit

Permalink
nixos/security/misc: add option unprivilegedUsernsClone
Browse files Browse the repository at this point in the history
  • Loading branch information
Izorkin committed Aug 25, 2020
1 parent 6a6d4c9 commit e21e5a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nixos/modules/profiles/hardened.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A profile with most (vanilla) hardening options enabled by default,
# potentially at the cost of features and performance.

{ lib, pkgs, ... }:
{ config, lib, pkgs, ... }:

with lib;

Expand All @@ -27,6 +27,9 @@ with lib;

security.forcePageTableIsolation = mkDefault true;

# This is required by podman to run containers in rootless mode.
security.unprivilegedUsernsClone = mkDefault config.virtualisation.containers.enable;

security.virtualisation.flushL1DataCache = mkDefault "always";

security.apparmor.enable = mkDefault true;
Expand Down
14 changes: 14 additions & 0 deletions nixos/modules/security/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ with lib;
'';
};

security.unprivilegedUsernsClone = mkOption {
type = types.bool;
default = false;
description = ''
When disabled, unprivileged users will not be able to create new namespaces.
By default unprivileged user namespaces are disabled.
This option only works in a hardened profile.
'';
};

security.protectKernelImage = mkOption {
type = types.bool;
default = false;
Expand Down Expand Up @@ -115,6 +125,10 @@ with lib;
];
})

(mkIf config.security.unprivilegedUsernsClone {
boot.kernel.sysctl."kernel.unprivileged_userns_clone" = mkDefault true;
})

(mkIf config.security.protectKernelImage {
# Disable hibernation (allows replacing the running kernel)
boot.kernelParams = [ "nohibernate" ];
Expand Down

0 comments on commit e21e5a9

Please sign in to comment.