Watch
0
0
Fork
You've already forked hyperhive
0

sign ssh certificates on demand from ssh itself, warn before setup, say what to do when a host key changes

This commit is contained in:
atlas 2026-11-16 19:42:44 +01:00 • committed by mara
commit 3d7541c0af

View file

@ -562,7 +562,7 @@ let
&& !(lib.hasInfix "valid_principals" s)
&& !(lib.hasInfix ".ssh" s)
&& lib.elem "hive-agent-bao-identity.service" u.after
&& u.environment.BAO_CLIENT_CERT == agentForgeBao.services.hyperhive.agent.bao.clientCertFile;
&& lib.hasInfix "export BAO_CLIENT_CERT=${agentForgeBao.services.hyperhive.agent.bao.clientCertFile}" s;
}
{
# The certificate lives an hour and the timer fires every third of
@ -599,17 +599,35 @@ let
&& !(lib.hasInfix "hive-agent-ssh-cert" agentForgeNoBao.environment.etc."ssh/ssh_config".text);
}
{
# A refused signing is the switch being off, not a fault: one line and a
# clean exit. Any other failure still fails the unit so it retries.
name = "the ssh certificate unit ends cleanly on a 403 and fails on any other signing error";
# `ssh` runs the helper before it loads an identity, so the first `ssh`
# after the operator's switch has a certificate. The line comes before the
# `Host *` block it serves, runs the `ssh` entry, and is on every agent
# with a store and no other.
name = "the ssh config signs on demand: a Match exec line runs the helper's ssh entry ahead of the Host block";
ok =
let
conf = agentForgeBao.environment.etc."ssh/ssh_config".text;
# What comes before the first `Host *`.
before = lib.head (lib.splitString "Host *" conf);
in
lib.hasInfix "Match exec \"HIVE_SSH_CERT_ENSURE=1 /nix/store/" before
&& lib.hasInfix "</dev/null\"" conf
&& !(lib.hasInfix "Match exec" agentForgeNoBao.environment.etc."ssh/ssh_config".text);
}
{
# The helper is the unit's script and the one `ssh` runs: the ssh entry
# is silent, signs from a fresh login, and remembers a refusal.
name = "the ssh helper is silent in the ssh entry, logs in afresh to sign, and keeps the store's CA for the ssh run";
ok =
let
s = (sshUnit agentForgeBao).script;
at = lib.splitString "Code: 403" s;
in
lib.length at == 2
&& lib.hasInfix "exit 0" (lib.head (lib.splitString "exit 1" (lib.elemAt at 1)))
&& lib.hasInfix "exit 1" (lib.elemAt at 1);
lib.hasInfix "HIVE_SSH_CERT_ENSURE" s
&& lib.hasInfix "exec >/dev/null 2>&1" s
&& lib.hasInfix "bao login -method=cert -token-only" s
&& lib.hasInfix "export BAO_TOKEN" s
&& lib.hasInfix "server-ca.pem" s
&& lib.hasInfix "Code: 403" s;
}
];
in