buildkite-agent: secrecy improvements: non-store, non-Nix provisioning of secrets
This commit is contained in:
parent
3385c85fb5
commit
3fa4e1e3ee
@ -4,14 +4,6 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.buildkite-agent;
|
cfg = config.services.buildkite-agent;
|
||||||
configFile = pkgs.writeText "buildkite-agent.cfg"
|
|
||||||
''
|
|
||||||
token="${cfg.token}"
|
|
||||||
name="${cfg.name}"
|
|
||||||
meta-data="${cfg.meta-data}"
|
|
||||||
hooks-path="${cfg.package}/share/hooks"
|
|
||||||
build-path="${cfg.dataDir}"
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -39,10 +31,13 @@ in
|
|||||||
type = types.listOf types.package;
|
type = types.listOf types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
token = mkOption {
|
tokenPath = mkOption {
|
||||||
type = types.str;
|
type = types.path;
|
||||||
description = ''
|
description = ''
|
||||||
The token from your Buildkite "Agents" page.
|
The token from your Buildkite "Agents" page.
|
||||||
|
|
||||||
|
A run-time path to the token file, which is supposed to be provisioned
|
||||||
|
outside of Nix store.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,16 +57,22 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
openssh =
|
openssh =
|
||||||
{ privateKey = mkOption {
|
{ privateKeyPath = mkOption {
|
||||||
type = types.str;
|
type = types.path;
|
||||||
description = ''
|
description = ''
|
||||||
Private agent key.
|
Private agent key.
|
||||||
|
|
||||||
|
A run-time path to the key file, which is supposed to be provisioned
|
||||||
|
outside of Nix store.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
publicKey = mkOption {
|
publicKeyPath = mkOption {
|
||||||
type = types.str;
|
type = types.path;
|
||||||
description = ''
|
description = ''
|
||||||
Public agent key.
|
Public agent key.
|
||||||
|
|
||||||
|
A run-time path to the key file, which is supposed to be provisioned
|
||||||
|
outside of Nix store.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -84,11 +85,15 @@ in
|
|||||||
home = cfg.dataDir;
|
home = cfg.dataDir;
|
||||||
createHome = true;
|
createHome = true;
|
||||||
description = "Buildkite agent user";
|
description = "Buildkite agent user";
|
||||||
|
extraGroups = [ "keys" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
systemd.services.buildkite-agent =
|
systemd.services.buildkite-agent =
|
||||||
|
let copy = x: target: perms:
|
||||||
|
"cp -f ${x} ${target}; ${pkgs.coreutils}/bin/chmod ${toString perms} ${target}; ";
|
||||||
|
in
|
||||||
{ description = "Buildkite Agent";
|
{ description = "Buildkite Agent";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
@ -97,18 +102,26 @@ in
|
|||||||
HOME = cfg.dataDir;
|
HOME = cfg.dataDir;
|
||||||
NIX_REMOTE = "daemon";
|
NIX_REMOTE = "daemon";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
## NB: maximum care is taken so that secrets (ssh keys and the CI token)
|
||||||
|
## don't end up in the Nix store.
|
||||||
preStart = ''
|
preStart = ''
|
||||||
${pkgs.coreutils}/bin/mkdir -m 0700 -p ${cfg.dataDir}/.ssh
|
${pkgs.coreutils}/bin/mkdir -m 0700 -p ${cfg.dataDir}/.ssh
|
||||||
|
${copy (toString cfg.openssh.privateKeyPath) "${cfg.dataDir}/.ssh/id_rsa" 600}
|
||||||
|
${copy (toString cfg.openssh.publicKeyPath) "${cfg.dataDir}/.ssh/id_rsa.pub" 600}
|
||||||
|
|
||||||
echo "${cfg.openssh.privateKey}" > ${cfg.dataDir}/.ssh/id_rsa
|
cat > "${cfg.dataDir}/buildkite-agent.cfg" <<EOF
|
||||||
${pkgs.coreutils}/bin/chmod 600 ${cfg.dataDir}/.ssh/id_rsa
|
token="$(cat ${toString cfg.tokenPath})"
|
||||||
|
name="${cfg.name}"
|
||||||
echo "${cfg.openssh.publicKey}" > ${cfg.dataDir}/.ssh/id_rsa.pub
|
meta-data="${cfg.meta-data}"
|
||||||
${pkgs.coreutils}/bin/chmod 600 ${cfg.dataDir}/.ssh/id_rsa.pub
|
hooks-path="${pkgs.buildkite-agent}/share/hooks"
|
||||||
|
build-path="${cfg.dataDir}/builds"
|
||||||
|
bootstrap-script="${pkgs.buildkite-agent}/share/bootstrap.sh"
|
||||||
|
EOF
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
{ ExecStart = "${pkgs.buildkite-agent}/bin/buildkite-agent start --config ${configFile}";
|
{ ExecStart = "${pkgs.buildkite-agent}/bin/buildkite-agent start --config /var/lib/buildkite-agent/buildkite-agent.cfg";
|
||||||
User = "buildkite-agent";
|
User = "buildkite-agent";
|
||||||
RestartSec = 5;
|
RestartSec = 5;
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
@ -116,4 +129,9 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
imports = [
|
||||||
|
(mkRenamedOptionModule [ "services" "buildkite-agent" "token" ] [ "services" "buildkite-agent" "tokenPath" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "buildkite-agent" "openssh" "privateKey" ] [ "services" "buildkite-agent" "openssh" "privateKeyPath" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "buildkite-agent" "openssh" "publicKey" ] [ "services" "buildkite-agent" "openssh" "publicKeyPath" ])
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user