Merge pull request #46 from numtide/fix/env-template-only

fix: vault agent with environment secrets only
main
Jean-François Roche 1 year ago committed by GitHub
commit 3a9398ed38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -64,7 +64,7 @@ let
(lib.mapAttrsToList (lib.mapAttrsToList
(serviceName: _service: (serviceName: _service:
getSecretTemplate serviceName services.${serviceName}.vault) getSecretTemplate serviceName services.${serviceName}.vault)
(lib.filterAttrs (_n: v: v.vault.secrets != { } && v.vault.agent == config._module.args.name) services)) (lib.filterAttrs (_n: v: v.vault.template != null && v.vault.agent == config._module.args.name) services))
++ (lib.mapAttrsToList ++ (lib.mapAttrsToList
(serviceName: _service: (serviceName: _service:
getEnvironmentTemplate serviceName services.${serviceName}.vault) getEnvironmentTemplate serviceName services.${serviceName}.vault)
@ -92,7 +92,8 @@ in
}; };
template = lib.mkOption { template = lib.mkOption {
type = lib.types.lines; type = lib.types.nullOr lib.types.lines;
default = null;
description = '' description = ''
The vault agent template to use for secrets The vault agent template to use for secrets
''; '';
@ -135,13 +136,14 @@ in
config = config =
let let
mkIfHasEnv = lib.mkIf (config.vault.environmentTemplate != null); mkIfHasEnv = lib.mkIf (config.vault.environmentTemplate != null);
mkIfHasSecret = lib.mkIf (config.vault.template != null);
in in
{ {
after = mkIfHasEnv [ "${serviceName}-envfile.service" ]; after = mkIfHasEnv [ "${serviceName}-envfile.service" ];
bindsTo = mkIfHasEnv [ "${serviceName}-envfile.service" ]; bindsTo = mkIfHasEnv [ "${serviceName}-envfile.service" ];
serviceConfig = { serviceConfig = {
LoadCredential = lib.mapAttrsToList (_: config: "${config.name}:/run/systemd-vaultd/sock") config.vault.secrets; LoadCredential = mkIfHasSecret (lib.mapAttrsToList (_: config: "${config.name}:/run/systemd-vaultd/sock") config.vault.secrets);
EnvironmentFile = mkIfHasEnv [ "/run/systemd-vaultd/secrets/${serviceName}.service.EnvironmentFile" ]; EnvironmentFile = mkIfHasEnv [ "/run/systemd-vaultd/secrets/${serviceName}.service.EnvironmentFile" ];
}; };
}; };

Loading…
Cancel
Save