From 94391fce1d5c4580482271c2b49ecffdef38b017 Mon Sep 17 00:00:00 2001 From: Izorkin Date: Tue, 12 May 2020 15:02:57 +0300 Subject: [PATCH] nixos/nginx: add option enableSandbox --- nixos/doc/manual/release-notes/rl-2009.xml | 4 ++-- nixos/modules/services/web-servers/nginx/default.nix | 9 +++++++++ nixos/tests/nginx-sandbox.nix | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2009.xml b/nixos/doc/manual/release-notes/rl-2009.xml index 71edc7f0f009..5b1d04e4bc16 100644 --- a/nixos/doc/manual/release-notes/rl-2009.xml +++ b/nixos/doc/manual/release-notes/rl-2009.xml @@ -237,8 +237,8 @@ php.override { - Nginx web server is now started with additional sandbox/hardening options. By default, write access to - services.nginx.stateDir is allowed. To allow writing to other folders, + Add option services.nginx.enableSandbox to starting Nginx web server with additional sandbox/hardening options. + By default, write access to services.nginx.stateDir is allowed. To allow writing to other folders, use systemd.services.nginx.serviceConfig.ReadWritePaths systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/var/www" ]; diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index 75fe1df506b3..312d2b0a21a7 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -463,6 +463,14 @@ in ''; }; + enableSandbox = mkOption { + default = false; + type = types.bool; + description = '' + Starting Nginx web server with additional sandbox/hardening options. + ''; + }; + user = mkOption { type = types.str; default = "nginx"; @@ -713,6 +721,7 @@ in CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" "CAP_SYS_RESOURCE" ]; # Security NoNewPrivileges = true; + } // optionalAttrs cfg.enableSandbox { # Sandboxing ProtectSystem = "strict"; ProtectHome = mkDefault true; diff --git a/nixos/tests/nginx-sandbox.nix b/nixos/tests/nginx-sandbox.nix index 514318c9456c..bc9d3ba8add7 100644 --- a/nixos/tests/nginx-sandbox.nix +++ b/nixos/tests/nginx-sandbox.nix @@ -18,6 +18,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { ]; services.nginx.enable = true; services.nginx.package = pkgs.nginx-lua; + services.nginx.enableSandbox = true; services.nginx.virtualHosts.localhost = { extraConfig = '' location /test1-write {