summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJörg Thalheim <Mic92@users.noreply.github.com>2021-04-20 21:12:10 +0100
committerGitHub <noreply@github.com>2021-04-20 21:12:10 +0100
commita8e7d96eb22efc716a5447e0461dae37f47748e5 (patch)
tree7325b41beba8ed2563edfa80a5af6fa60b0a49fb /nixos
parent0540805a62bfded30db92e53cb7bc66e4b9a6be1 (diff)
parente075aeb8c0113b3d91c63aa99b22dcb4ce5a0d81 (diff)
downloadnixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.tar
nixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.tar.gz
nixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.tar.bz2
nixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.tar.lz
nixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.tar.xz
nixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.tar.zst
nixpkgs-a8e7d96eb22efc716a5447e0461dae37f47748e5.zip
Merge pull request #118961 from Izorkin/update-redis-sandbox
nixos/redis: enable sandbox mode
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/databases/redis.nix41
1 files changed, 39 insertions, 2 deletions
diff --git a/nixos/modules/services/databases/redis.nix b/nixos/modules/services/databases/redis.nix
index 3ddc7aad81e..7ec10c0eb5a 100644
--- a/nixos/modules/services/databases/redis.nix
+++ b/nixos/modules/services/databases/redis.nix
@@ -5,6 +5,8 @@ with lib;
 let
   cfg = config.services.redis;
 
+  ulimitNofile = cfg.maxclients + 32;
+
   mkValueString = value:
     if value == true then "yes"
     else if value == false then "no"
@@ -14,8 +16,8 @@ let
     listsAsDuplicateKeys = true;
     mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " ";
   } cfg.settings);
-in
-{
+
+in {
   imports = [
     (mkRemovedOptionModule [ "services" "redis" "user" ] "The redis module now is hardcoded to the redis user.")
     (mkRemovedOptionModule [ "services" "redis" "dbpath" ] "The redis module now uses /var/lib/redis as data directory.")
@@ -121,6 +123,12 @@ in
         description = "Set the number of databases.";
       };
 
+      maxclients = mkOption {
+        type = types.int;
+        default = 10000;
+        description = "Set the max number of connected clients at the same time.";
+      };
+
       save = mkOption {
         type = with types; listOf (listOf int);
         default = [ [900 1] [300 10] [60 10000] ];
@@ -253,6 +261,7 @@ in
         logfile = cfg.logfile;
         syslog-enabled = cfg.syslog;
         databases = cfg.databases;
+        maxclients = cfg.maxclients;
         save = map (d: "${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}") cfg.save;
         dbfilename = "dump.rdb";
         dir = "/var/lib/redis";
@@ -295,6 +304,34 @@ in
         StateDirectoryMode = "0700";
         # Access write directories
         UMask = "0077";
+        # Capabilities
+        CapabilityBoundingSet = "";
+        # Security
+        NoNewPrivileges = true;
+        # Process Properties
+        LimitNOFILE = "${toString ulimitNofile}";
+        # Sandboxing
+        ProtectSystem = "strict";
+        ProtectHome = true;
+        PrivateTmp = true;
+        PrivateDevices = true;
+        PrivateUsers = true;
+        ProtectClock = true;
+        ProtectHostname = true;
+        ProtectKernelLogs = true;
+        ProtectKernelModules = true;
+        ProtectKernelTunables = true;
+        ProtectControlGroups = true;
+        RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
+        RestrictNamespaces = true;
+        LockPersonality = true;
+        MemoryDenyWriteExecute = true;
+        RestrictRealtime = true;
+        RestrictSUIDSGID = true;
+        PrivateMounts = true;
+        # System Call Filtering
+        SystemCallArchitectures = "native";
+        SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @memlock @module @mount @obsolete @privileged @raw-io @reboot @resources @setuid @swap";
       };
     };
   };