added ssh host cert renewal
This commit is contained in:
@@ -65,6 +65,52 @@ in
|
||||
'')
|
||||
(writeShellScriptBin "ssh-host-cert-check" "${lib.getExe' pkgs.openssh "ssh-keygen"} -Lf ${sshCertPath}")
|
||||
];
|
||||
|
||||
systemd.services.step-ssh-host-renew = {
|
||||
description = "Renew Step SSH host certificate if needed";
|
||||
wantedBy = [ ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
path = [ pkgs.step-cli pkgs.openssh pkgs.coreutils pkgs.systemd ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "root";
|
||||
Group = "root";
|
||||
};
|
||||
script = ''
|
||||
set -euo pipefail
|
||||
if ${stepBin} ssh needs-renewal "${sshCertPath}" --expires-in "4h"; then
|
||||
echo "Renewing SSH host certificate"
|
||||
else
|
||||
rc=$?
|
||||
if [ "$rc" -eq 1 ]; then
|
||||
echo "SSH host cert does not need renewal"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$rc" -eq 2 ]; then
|
||||
echo "SSH host cert missing: ${sshCertPath}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "step ssh needs-renewal failed with rc=$rc" >&2
|
||||
exit "$rc"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.timers.step-ssh-host-renew = {
|
||||
description = "Periodic Step SSH host certificate renewal";
|
||||
wantedBy = [ "timers.target" ];
|
||||
|
||||
timerConfig = {
|
||||
OnBootSec = "5m";
|
||||
OnUnitActiveSec = "4h";
|
||||
RandomizedDelaySec = "15m";
|
||||
Persistent = true;
|
||||
Unit = "step-ssh-host-renew.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user