Compare commits
2 commits
607fb9a28c
...
e791be03a4
Author | SHA1 | Date | |
---|---|---|---|
e791be03a4 | |||
e3ed1611c8 |
3 changed files with 64 additions and 1 deletions
|
@ -52,7 +52,7 @@ let
|
||||||
triggers.add(target)
|
triggers.add(target)
|
||||||
|
|
||||||
for trigger in triggers:
|
for trigger in triggers:
|
||||||
subprocess.run(["${config.systemd.package}/bin/systemctl", "start", "--no-block", f"{trigger}.service"])
|
subprocess.run(["${config.systemd.package}/bin/systemctl", "start", f"{trigger}.service"])
|
||||||
|
|
||||||
with open(indexFile, "w") as f:
|
with open(indexFile, "w") as f:
|
||||||
f.write(newIndex)
|
f.write(newIndex)
|
||||||
|
|
10
cluster/services/locksmith/default.nix
Normal file
10
cluster/services/locksmith/default.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ config, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
services.locksmith = {
|
||||||
|
nodes.receiver = config.services.consul.nodes.agent;
|
||||||
|
nixos.receiver = [
|
||||||
|
./receiver.nix
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
53
cluster/services/locksmith/receiver.nix
Normal file
53
cluster/services/locksmith/receiver.nix
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
consulCfg = config.services.consul.extraConfig;
|
||||||
|
consulIpAddr = consulCfg.addresses.http or "127.0.0.1";
|
||||||
|
consulHttpAddr = "${consulIpAddr}:${toString (consulCfg.ports.http or 8500)}";
|
||||||
|
|
||||||
|
kvRoot = "secrets/locksmith";
|
||||||
|
kvValue = "recipient/${config.networking.hostName}";
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
systemd.tmpfiles.settings.locksmith = {
|
||||||
|
"/run/locksmith".d = {
|
||||||
|
mode = "0711";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.locksmith = {
|
||||||
|
description = "The Locksmith's Chant";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
wants = [ "consul.service" ];
|
||||||
|
after = [ "consul.service" ];
|
||||||
|
chant.enable = true;
|
||||||
|
path = [
|
||||||
|
config.services.consul.package
|
||||||
|
];
|
||||||
|
environment = {
|
||||||
|
CONSUL_HTTP_ADDR = consulHttpAddr;
|
||||||
|
};
|
||||||
|
serviceConfig = {
|
||||||
|
PrivateTmp = true;
|
||||||
|
WorkingDirectory = "/tmp";
|
||||||
|
IPAddressDeny = [ "any" ];
|
||||||
|
IPAddressAllow = [ consulIpAddr ];
|
||||||
|
LoadCredential = lib.mkForce [];
|
||||||
|
};
|
||||||
|
script = ''
|
||||||
|
consul kv get --keys ${kvRoot}/ | ${pkgs.gnused}/bin/sed 's,/$,,g' | while read secret; do
|
||||||
|
out="$(mktemp -u /run/locksmith/.locksmith-secret.XXXXXXXXXXXXXXXX)"
|
||||||
|
if [[ "$(consul kv get --keys "$secret/${kvValue}")" == "$secret/${kvValue}" ]]; then
|
||||||
|
owner="$(consul kv get "$secret/owner")"
|
||||||
|
group="$(consul kv get "$secret/group")"
|
||||||
|
mode="$(consul kv get "$secret/mode")"
|
||||||
|
consul kv get "$secret/${kvValue}" | ${pkgs.age}/bin/age --decrypt -i /etc/ssh/ssh_host_ed25519_key -o $out
|
||||||
|
chown -v "$owner:$group" $out
|
||||||
|
chmod -v "$mode" $out
|
||||||
|
mv -v $out "/run/locksmith/$(basename "$secret")"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue