about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2019-03-15 04:13:01 +0100
committeraszlig <aszlig@nix.build>2019-03-15 04:13:01 +0100
commitd13ad389b4a4ccaae3f3732f3735984814dbb851 (patch)
tree27a27982a32080c82bfc8e87a8a2ec036ed7d782 /nixos
parent9e9af4f9c076f382bc40821551beaeb68ca071cd (diff)
downloadnixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.tar
nixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.tar.gz
nixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.tar.bz2
nixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.tar.lz
nixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.tar.xz
nixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.tar.zst
nixlib-d13ad389b4a4ccaae3f3732f3735984814dbb851.zip
nixos/confinement: Explicitly set serviceConfig
My implementation was relying on PrivateDevices, PrivateTmp,
PrivateUsers and others to be false by default if chroot-only mode is
used.

However there is an ongoing effort[1] to change these defaults, which
then will actually increase the attack surface in chroot-only mode,
because it is expected that there is no /dev, /sys or /proc.

If for example PrivateDevices is enabled by default, there suddenly will
be a mounted /dev in the chroot and we wouldn't detect it.

Fortunately, our tests cover that, but I'm preparing for this anyway so
that we have a smoother transition without the need to fix our
implementation again.

Thanks to @Infinisil for the heads-up.

[1]: https://github.com/NixOS/nixpkgs/issues/14645

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/security/systemd-confinement.nix28
1 files changed, 20 insertions, 8 deletions
diff --git a/nixos/modules/security/systemd-confinement.nix b/nixos/modules/security/systemd-confinement.nix
index fc0ce020afc7..49fde2dcc6d5 100644
--- a/nixos/modules/security/systemd-confinement.nix
+++ b/nixos/modules/security/systemd-confinement.nix
@@ -106,19 +106,31 @@ in {
       config = let
         rootName = "${mkPathSafeName name}-chroot";
         inherit (config.confinement) binSh fullUnit;
+        wantsAPIVFS = lib.mkDefault (config.confinement.mode == "full-apivfs");
       in lib.mkIf config.confinement.enable {
         serviceConfig = {
           RootDirectory = pkgs.runCommand rootName {} "mkdir \"$out\"";
           TemporaryFileSystem = "/";
           MountFlags = lib.mkDefault "private";
-        } // lib.optionalAttrs (config.confinement.mode == "full-apivfs") {
-          MountAPIVFS = true;
-          PrivateDevices = true;
-          PrivateTmp = true;
-          PrivateUsers = true;
-          ProtectControlGroups = true;
-          ProtectKernelModules = true;
-          ProtectKernelTunables = true;
+
+          # https://github.com/NixOS/nixpkgs/issues/14645 is a future attempt
+          # to change some of these to default to true.
+          #
+          # If we run in chroot-only mode, having something like PrivateDevices
+          # set to true by default will mount /dev within the chroot, whereas
+          # with "chroot-only" it's expected that there are no /dev, /proc and
+          # /sys file systems available.
+          #
+          # However, if this suddenly becomes true, the attack surface will
+          # increase, so let's explicitly set these options to true/false
+          # depending on the mode.
+          MountAPIVFS = wantsAPIVFS;
+          PrivateDevices = wantsAPIVFS;
+          PrivateTmp = wantsAPIVFS;
+          PrivateUsers = wantsAPIVFS;
+          ProtectControlGroups = wantsAPIVFS;
+          ProtectKernelModules = wantsAPIVFS;
+          ProtectKernelTunables = wantsAPIVFS;
         };
         confinement.packages = let
           startOnly = config.serviceConfig.RootDirectoryStartOnly or false;