Watch
0
0
Fork
You've already forked hyperhive
0

swarm-bao-pki: enabling a service mints its client leaf on the same switch

`swarm-bao-pki` was a `RemainAfterExit` oneshot. Once active, nothing
re-ran it: a switch restarts it only when its definition changes, and a
`Requires=`/`Wants=` on an active unit is satisfied without running it.

On muede-lpt2 the 10:57Z switch that added the builder line did change
the unit, so switch-to-configuration stopped it in its stop phase. A
start of `container@swarm-bao` 4 s later (before the daemon-reload at
10:57:35Z) pulled it back in through `swarm-bao-certs` with the OLD
definition, which had no builder line: 48 ms, nothing missing. The start
phase then found it active and did nothing. The 20:14Z switch that
enabled the builder left the unit unchanged, so it was never re-run, and
`container@swarm-builder` crash-looped on the absent `builder.pem`.

The unit now goes inactive after each run. Every switch starts
`multi-user.target`, which runs it again post-reload with the current
definition, and every unit that wants or requires it runs it on its own
start. Each line is idempotent on presence, so an existing leaf is never
re-signed.

The three consumers started from `machines.target` rather than
`multi-user.target` also want it, since `After=` alone does not order
against a job in another transaction: the builder's and the review
classifier's containers (nspawn `--load-credential`) and
`swarm-nats-auth-secrets` (pulled in by the queue's container).

Fixes #5284
This commit is contained in:
atlas 2026-10-14 22:50:21 +02:00 • committed by mara
commit b5053d9a80
8 changed files with 74 additions and 20 deletions

View file

@ -94,6 +94,22 @@ let
&& svc.serviceConfig.DynamicUser
&& !(lib.any (lib.hasSuffix "TOKEN") (lib.attrNames env));
}
{
# The minting unit goes inactive after each run, so a start that pulls it
# runs it again and mints a leaf that is missing; an active
# `RemainAfterExit` unit would satisfy the pull without running.
name = "the builder's container runs the leaf-minting unit before every start";
ok =
let
pki = withBuilder.systemd.services.swarm-bao-pki;
c = withBuilder.systemd.services."container@swarm-builder";
in
pki.serviceConfig.Type == "oneshot"
&& !(pki.serviceConfig.RemainAfterExit or false)
&& lib.elem "multi-user.target" pki.wantedBy
&& lib.elem "swarm-bao-pki.service" c.wants
&& lib.elem "swarm-bao-pki.service" c.after;
}
{
# The check builds on the sources a hive on this host would render into
# its meta flake, so a green check means the same base.

View file

@ -417,6 +417,15 @@ let
lib.attrValues withClassifier.systemd.services
));
}
{
# See the same case in ./builder.nix.
name = "the review classifier's container runs the leaf-minting unit before every start";
ok =
let
c = withClassifier.systemd.services."container@swarm-review-classifier";
in
lib.elem "swarm-bao-pki.service" c.wants && lib.elem "swarm-bao-pki.service" c.after;
}
{
# The collector reaches these routes through the gateway now, so each
# store needs an ingest location of its own. Without one the write rides

View file

@ -253,6 +253,16 @@ let
&& waitsFor "swarm-bao-secret-publisher-policy"
&& natsOnStoreHost.systemd.services ? swarm-bao-secret-publisher-policy;
}
{
# The queue's container pulls the copy in, outside the switch's
# `multi-user.target` transaction; see the same case in ./builder.nix.
name = "the responder's leaf copy runs the leaf-minting unit first";
ok =
let
u = natsOnStoreHost.systemd.services.swarm-nats-auth-secrets;
in
lib.elem "swarm-bao-pki.service" u.wants && lib.elem "swarm-bao-pki.service" u.after;
}
{
# The control is the fixture above the store: off the store's host
# there is no local policy unit to wait for.