Watch
0
0
Fork
You've already forked hyperhive
0

swarm-bao: move the agent PKI and SSH CA units out

swarm-bao-agent-pki (the agent PKI mount, its root and role, and the
listener's trust in it, with the restart of openbao) and
swarm-bao-agent-ssh-policy (the agent SSH CA mount and its role) are
their own module, with the bindings only they use. The mount names, the
cached agent CA, the listener bundle and the unit timeouts the host
module also reads join lib/swarm-bao-shared.nix.

Refs #6820
This commit is contained in:
maia 2026-11-23 22:27:36 +01:00 • committed by mara
commit c1851f37cc

View file

@ -378,9 +378,99 @@ let
}
'';
# OpenBao's start job limit inside the container, and the container's own,
# which is the same plus a margin: the container is `Type=notify`, so its
# start job spans OpenBao's and must outlast it, or the container's limit
# kills a start the unit would still finish.
openbaoStartSec = 240;
containerStartSec = openbaoStartSec + 60;
# systemd's default stop limit, which bounds the stop half of a restart.
openbaoStopSec = 90;
# Subject of the root generated into that mount. A label for a human reading
# a chain, not an identity anything authenticates against. Falls through so
# a hive that has set neither a swarm name nor a domain still evaluates.
servicesPkiRootLabel =
if hyperhiveCfg.swarm.name != null then
hyperhiveCfg.swarm.name
else if hyperhiveCfg.domain != null then
hyperhiveCfg.domain
else
"hyperhive";
# The PKI mount agent client certificates are issued from. Its root is
# generated inside the store, so the agent CA's key never exists outside it.
# A mount of its own because the services mount holds exactly one issuer; a
# root apart from ../glue-bao-tls.nix's CA because that is what keeps an
# agent's certificate from satisfying any host role.
agentPkiMountPath = baoDeploy.agentPkiMountPath;
agentPkiRoleName = baoDeploy.agentPkiRoleName;
# The SSH secrets engine mount whose CA signs the agents' user certificates,
# and the one role they sign through, spelled once for this file and
# ../../agent-modules/ssh.nix in ./ssh-agent-ca.nix.
sshAgent = import ./ssh-agent-ca.nix { };
sshAgentsMountPath = sshAgent.mountPath;
sshAgentRoleName = sshAgent.roleName;
# The agent CA's certificate, cached on this host by `swarm-bao-agent-pki`,
# so `swarm-bao-certs` can compose the listener's bundle before the store
# is up. Public material.
agentCaCachePath = "${tlsDir}/agent-ca.pem";
# What the listener verifies client certificates against: `client-ca.pem`
# first, then the agent CA. A file of its own because every host cert-auth
# role pins `client-ca.pem`: with the agent CA in that file, every leaf the
# controller can request would satisfy every host role.
listenerClientCaPath = "${tlsDir}/listener-client-ca.pem";
# Writes `listenerClientCaPath` from `clientCaPath` and, when it parses, the
# cached agent CA. The file is replaced only when its bytes change, so its
# mtime says when the listener's trust last changed; `swarm-bao-agent-pki`
# restarts openbao on exactly that. Refuses, leaving the current file, when
# the result would not begin with `client-ca.pem`: host logins depend on it.
composeListenerBundle = ''
compose_listener_bundle() {
if [ ! -s ${clientCaPath} ]; then
echo "${clientCaPath} is missing or empty; not composing the listener bundle" >&2
return 1
fi
local tmp
tmp="$(mktemp -p ${tlsDir} .listener-client-ca.XXXXXX)"
cat ${clientCaPath} > "$tmp"
if [ -s ${agentCaCachePath} ]; then
if openssl x509 -noout -in ${agentCaCachePath} >/dev/null 2>&1; then
printf '\n' >> "$tmp"
cat ${agentCaCachePath} >> "$tmp"
else
echo "${agentCaCachePath} does not parse; the listener will not trust agent certificates" >&2
fi
fi
if ! cmp -s -n "$(stat -c %s ${clientCaPath})" ${clientCaPath} "$tmp"; then
rm -f "$tmp"
echo "the composed listener bundle does not begin with ${clientCaPath}; leaving the current one" >&2
return 1
fi
if cmp -s "$tmp" ${listenerClientCaPath}; then
rm -f "$tmp"
else
chmod 0644 "$tmp"
mv -f "$tmp" ${listenerClientCaPath}
echo "wrote ${listenerClientCaPath}"
fi
}
'';
clientCaPath = "${tlsDir}/client-ca.pem";
refreshConsumer = import ./refresh-consumer.nix { };
in
{
inherit
agentCaCachePath
agentPkiMountPath
agentPkiRoleName
atticCacheLeaf
atticFactLeaves
atticJwtLeaf
@ -401,6 +491,9 @@ in
classifierAcpKeyLeaf
classifierApiKeyLeaf
classifierForgeTokenLeaf
clientCaPath
composeListenerBundle
containerStartSec
controllerClientLeaf
controllerForgeTokenLeaf
controllerGrafanaTokenLeaf
@ -422,8 +515,16 @@ in
haveServerTls
issuerPublicLeaf
issuerSeedLeaf
listenerClientCaPath
listStanza
openbaoStartSec
openbaoStopSec
readStanza
refreshConsumer
servicesPkiRootLabel
sshAgent
sshAgentRoleName
sshAgentsMountPath
swarmAppserviceRegistrationLeaf
swarmAppserviceTokenLeaf
tlsDir