Watch
0
0
Fork
You've already forked hyperhive
0

agent ssh connections: declare per agent, render into the agent's ssh config

This commit is contained in:
atlas 2026-11-20 01:38:49 +01:00
commit 934da6f31f

View file

@ -64,6 +64,12 @@ let
# In the state dir, which is bound from the host, so a pin survives a restart.
knownHostsFile = "/agents/${agentName}/state/ssh_known_hosts";
# The file the harness writes the operator's named connections into
# (`hive-agent`'s `ssh_connections`). Owned by the agent user: ssh refuses an
# included file that another user owns, or that group or others can write.
connectionsDir = "/run/hive-agent-ssh-connections";
connectionsFile = "${connectionsDir}/config";
signPath = "${ca.mountPath}/sign/${ca.roleName}";
# A certificate with less than this left is signed again by `ssh`. The timer
@ -92,10 +98,15 @@ in
config = lib.mkIf (baoCfg.addr != null) {
# Every host: the certificate, and the pins in the state dir, which outlives
# the container root. `accept-new` records a host's key at first contact and
# refuses a changed one after that. The `Match` line has no settings: ssh
# refuses a changed one after that. The `Include` is the first line: ssh
# takes the first value it finds for an option, and an include below `Host *`
# would sit inside that block. The included file holds the `Host` blocks of
# the named connections and ends its own scope, and `Host *` below still
# gives each of them the identity. The `Match` line has no settings: ssh
# runs its command while it reads the config, before it loads any identity,
# and the answer is not used.
programs.ssh.extraConfig = ''
Include ${connectionsFile}
Match exec "HIVE_SSH_CERT_ENSURE=1 ${helper} </dev/null"
Host *
IdentityFile ${keyFile}
@ -105,6 +116,14 @@ in
UserKnownHostsFile ${knownHostsFile}
'';
# The directory and an empty file in it, so that the `Include` above finds
# a file before the harness has read the agent's record. `f` leaves an
# existing file's content alone.
systemd.tmpfiles.rules = [
"d ${connectionsDir} 0755 ${agentName} ${agentName} - -"
"f ${connectionsFile} 0600 ${agentName} ${agentName} - -"
];
systemd.services.${unitName} = {
description = "sign this agent's SSH key with the swarm's SSH CA";
after = [