Harden blowhole agains sealed Vault

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2023-06-28 14:23:08 +02:00
parent 8b2321dde4
commit 004cfb039b
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
7 changed files with 57 additions and 5 deletions

View file

@ -26,8 +26,9 @@ in
}; };
}; };
systemd.services.hashicorp-consul.unitConfig = { systemd.services."hashicorp-consul" = {
ConditionPathExists = "/run/secrets/consul.json"; requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
}; };
services.hashicorp.consul = { services.hashicorp.consul = {

View file

@ -63,6 +63,30 @@ in
]; ];
}; };
systemd.services.vault-unsealed = {
description = "Check whether the local Vault instance is unsealed and fail if not.";
path = with pkgs; [ getent vault ];
unitConfig = {
StartLimitInterval = 0;
};
serviceConfig = {
Restart = "always";
RestartSec = 30;
};
script = ''
export VAULT_ADDR="https://vault.in.redalder.org:8200/"
while [ $( vault operator key-status |& grep -q "Vault is sealed" ; printf $? ) = 1 ]
do
sleep 30
done
exit 2
'';
};
system.stateVersion = "21.05"; system.stateVersion = "21.05";
}); });
}; };

View file

@ -31,8 +31,9 @@ in
destination = "/run/secrets/hostapd_wpa_psk"; destination = "/run/secrets/hostapd_wpa_psk";
}; };
systemd.services.hostapd.unitConfig = { systemd.services."hostapd" = {
ConditionPathExists = "/run/secrets/hostapd_wpa_psk"; requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
}; };
services.hostapd = { services.hostapd = {

View file

@ -45,6 +45,9 @@ in
systemd.services."container@klipper" = { systemd.services."container@klipper" = {
restartIfChanged = lib.mkForce false; restartIfChanged = lib.mkForce false;
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
}; };
containers.klipper = { containers.klipper = {

View file

@ -205,6 +205,11 @@ in
}; };
systemd.services."hashicorp-envoy-telegraf" = {
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
};
## There is no way to say, hey, listen on localhost. The listeners option is missing the `address` field ## There is no way to say, hey, listen on localhost. The listeners option is missing the `address` field
## and the `name` field so it's impossible to configure.... ## and the `name` field so it's impossible to configure....
services.hashicorp-envoy.telegraf = { services.hashicorp-envoy.telegraf = {
@ -235,6 +240,11 @@ in
extraConsulArgs = [ "-ignore-envoy-compatibility" ]; extraConsulArgs = [ "-ignore-envoy-compatibility" ];
}; };
systemd.services."telegraf-magic" = {
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
};
services.telegraf-magic = { services.telegraf-magic = {
enable = true; enable = true;
settings = { settings = {
@ -324,7 +334,12 @@ in
fsType = "zfs"; fsType = "zfs";
}; };
systemd.services."container@monitor".serviceConfig.LimitNOFILE = "infinity"; systemd.services."container@monitor" = {
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
serviceConfig.LimitNOFILE = "infinity";
};
# TODO: split interface name and container name, i.e. rewrite the container module....... again # TODO: split interface name and container name, i.e. rewrite the container module....... again
containers.monitor = { containers.monitor = {

View file

@ -28,6 +28,11 @@ in
}; };
}; };
systemd.services."hashicorp-nomad" = {
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
};
services.hashicorp.nomad = { services.hashicorp.nomad = {
enable = true; enable = true;

View file

@ -17,6 +17,9 @@ in
{ {
preStart = "systemd-tmpfiles --create " + config; preStart = "systemd-tmpfiles --create " + config;
postStop = "systemd-tmpfiles --clean " + config; postStop = "systemd-tmpfiles --clean " + config;
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
}; };
services.hashicorp.vault-agent = { services.hashicorp.vault-agent = {