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 = {
ConditionPathExists = "/run/secrets/consul.json";
systemd.services."hashicorp-consul" = {
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
};
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";
});
};

View file

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

View file

@ -45,6 +45,9 @@ in
systemd.services."container@klipper" = {
restartIfChanged = lib.mkForce false;
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
};
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
## and the `name` field so it's impossible to configure....
services.hashicorp-envoy.telegraf = {
@ -235,6 +240,11 @@ in
extraConsulArgs = [ "-ignore-envoy-compatibility" ];
};
systemd.services."telegraf-magic" = {
requires = [ "vault-unsealed.service" ];
after = [ "vault-unsealed.service" ];
};
services.telegraf-magic = {
enable = true;
settings = {
@ -324,7 +334,12 @@ in
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
containers.monitor = {

View file

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

View file

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