summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-12-24 17:22:09 +0100
committerRory& <root@rory.gay>2024-12-24 17:23:11 +0100
commiteb82f41859447482cbc2687028686b94bc52a933 (patch)
tree174b1df9bb32a572179035d1b7ae0c1bfbbe120e /modules
parentDont use dynamic users if sudo is enabled (diff)
downloadRory-Open-Architecture-eb82f41859447482cbc2687028686b94bc52a933.tar.xz
Create users for sudo enabled services
Diffstat (limited to 'modules')
-rw-r--r--modules/packages/redpanda-connect/module.nix77
1 files changed, 39 insertions, 38 deletions
diff --git a/modules/packages/redpanda-connect/module.nix b/modules/packages/redpanda-connect/module.nix

index 8060cd4..ec82edf 100644 --- a/modules/packages/redpanda-connect/module.nix +++ b/modules/packages/redpanda-connect/module.nix
@@ -31,44 +31,33 @@ in }; }; - config = lib.mkIf cfg.enable { - systemd.services = builtins.listToAttrs ( - lib.mapAttrsToList (name: pipeline: { - name = "redpanda-connect-${name}"; - value = { - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "simple"; - ExecStart = - let - configFile = pkgs.writeText "redpanda-connect-${name}.json" (builtins.toJSON pipeline.config); - in - "${cfg.package}/bin/redpanda-connect run ${configFile}"; - Restart = "always"; - RestartSec = "5"; - DynamicUser = !pipeline.allowSudo; - User = if pipeline.allowSudo then "redpanda-connect-${name}" else null; + config = lib.mkIf cfg.enable ( + let + sudoEnabledServices = builtins.filter (pipeline: pipeline.value.allowSudo) (lib.attrsToList cfg.pipelines); + in + { + systemd.services = builtins.listToAttrs ( + lib.mapAttrsToList (name: pipeline: { + name = "redpanda-connect-${name}"; + value = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "simple"; + ExecStart = + let + configFile = pkgs.writeText "redpanda-connect-${name}.json" (builtins.toJSON pipeline.config); + in + "${cfg.package}/bin/redpanda-connect run ${configFile}"; + Restart = "always"; + RestartSec = "5"; + DynamicUser = !pipeline.allowSudo; + User = if pipeline.allowSudo then "redpanda-connect-${name}" else null; + }; }; - }; - }) cfg.pipelines - ); - - # Allow sudo access to allowed services: - #security.polkit.extraConfig = '' - # polkit.addRule(function(action, subject) { - # if (action.id == "org.freedesktop.systemd1.manage-units" && - # action.lookup("unit").startsWith("botcore.") && - # subject.user == "botcore") { - # return polkit.Result.YES; - # } - # }); - #''; + }) cfg.pipelines + ); - security.polkit.extraConfig = - let - allowedServices = builtins.filter (pipeline: pipeline.value.allowSudo) (lib.attrsToList cfg.pipelines); - in - builtins.concatStringsSep "\n" ( + security.polkit.extraConfig = builtins.concatStringsSep "\n" ( builtins.map (value: '' polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.systemd1.manage-units" && @@ -76,7 +65,19 @@ in return polkit.Result.YES; } }); - '') allowedServices + '') sudoEnabledServices ); - }; + + users.users = builtins.listToAttrs ( + lib.mapAttrsToList (name: pipeline: { + name = "redpanda-connect-${name}"; + value = { + isSystemUser = true; + home = "/var/lib/redpanda-connect-${name}"; + description = "Redpanda Connect pipeline ${name}"; + }; + }) sudoEnabledServices + ); + } + ); }