2021-04-11 00:25:36 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2021-03-14 10:58:29 +01:00
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.vault-agent;
|
2021-04-11 00:25:36 +02:00
|
|
|
format = pkgs.formats.json { };
|
2021-03-14 10:58:29 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.vault-agent = {
|
|
|
|
enable = mkEnableOption "Vault, secure credentials storage and manager";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2021-07-22 20:20:30 +02:00
|
|
|
default = pkgs.vault;
|
2021-03-14 10:58:29 +01:00
|
|
|
defaultText = "nixpkgs.vault";
|
|
|
|
description = ''
|
|
|
|
The package used for the Vault agent and CLI.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secretsDir = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = "/var/secrets";
|
|
|
|
description = ''
|
|
|
|
Vault secrets directory;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for Vault Agent. See the <link xlink:href="https://www.vaultproject.io/docs/agent#configuration">documentation</link>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secretsGroup = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "secrets";
|
|
|
|
description = ''
|
|
|
|
Group used for accessing the secrets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
id = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1984;
|
|
|
|
description = ''
|
|
|
|
Group ID for the secrets group.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
userName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "vault-agent";
|
|
|
|
};
|
|
|
|
|
|
|
|
groupName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "vault-agent";
|
|
|
|
};
|
|
|
|
|
|
|
|
uid = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1985;
|
|
|
|
};
|
|
|
|
|
|
|
|
gid = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1985;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable
|
|
|
|
(let
|
|
|
|
vaultConfig = format.generate "vault.json" cfg.settings;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
users = {
|
|
|
|
users = {
|
|
|
|
"${cfg.userName}" = {
|
|
|
|
group = cfg.groupName;
|
|
|
|
uid = cfg.uid;
|
2021-05-09 23:34:35 +02:00
|
|
|
isSystemUser = true;
|
2021-03-14 10:58:29 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
groups = {
|
|
|
|
"${cfg.groupName}" = {
|
|
|
|
gid = cfg.gid;
|
|
|
|
};
|
|
|
|
|
|
|
|
"${cfg.secretsGroup.name}" = {
|
|
|
|
gid = cfg.secretsGroup.id;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = mkIf (cfg.secretsDir != null) [
|
|
|
|
"d ${cfg.secretsDir} 6755 vault-agent ${cfg.secretsGroup.name} 0"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.vault-agent = {
|
|
|
|
description = "Vault Agent";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
|
2021-04-11 00:25:36 +02:00
|
|
|
path = (with pkgs; [
|
2021-03-14 10:58:29 +01:00
|
|
|
glibc
|
|
|
|
]);
|
|
|
|
|
|
|
|
serviceConfig = mkMerge [
|
|
|
|
{
|
|
|
|
User = cfg.userName;
|
|
|
|
Group = cfg.groupName;
|
|
|
|
|
2021-04-11 00:25:36 +02:00
|
|
|
ExecReload = "${pkgs.busybox}/bin/kill -HUP $MAINPID";
|
2021-03-14 10:58:29 +01:00
|
|
|
ExecStart = "${cfg.package}/bin/vault agent -config=${vaultConfig}";
|
|
|
|
|
|
|
|
KillMode = "process";
|
|
|
|
KillSignal = "SIGINT";
|
|
|
|
LimitNOFILE = 65536;
|
|
|
|
LimitNPROC = "infinity";
|
|
|
|
OOMScoreAdjust = -1000;
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 2;
|
|
|
|
TasksMax = "infinity";
|
|
|
|
|
|
|
|
ConfigurationDirectory = "vault-agent";
|
|
|
|
ConfigurationDirectoryMode = "0700";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|