swarm: guard hive names where the roster is declared, and reserve the cert subjects
The two hive-name guards lived in swarm-otel.nix, inside its `config = lib.mkIf (… && deployCfg.swarm-otel.enable)`. A swarm running the secret store and the controller but no collector therefore had no hive-name check at all, while the names were still composed into OIDC client ids, bao policies and cert-auth roles exactly the same way. They move to swarm.nix, which declares `swarm.hives` and is unconditional. swarm-otel keeps the assertion that its own entry is still in the shared list — that one is about this module's stake in a file it no longer controls. The equality guard also takes the store's cert-auth subjects now. Cert auth trusts the CA, so `allowed_common_names` is the whole of what narrows a role to one identity, and the same CA signs every hive's leaf with the hive's name as its CN. A hive named after a role's subject presents a certificate that role accepts, which for the controller is write access to every hive's credentials and policies. A list rather than the one string, because the next role added beside it widens what a hive name must not collide with, and because the subject is an option an operator sets — a literal deny entry covers the default and nothing else. Four module-eval cases, two of them controls. The fixture overrides the subject to `ctl` on purpose: the default contains `swarm`, which the substring guard catches whatever the new arm does, so a fixture using it could not tell the two apart. The controls are that a legal roster trips neither guard, and that all three fixtures really do have the collector disabled — without the second, every case would pass while testing the arrangement they exist to rule out.
This commit is contained in:
parent
613ca541e1
commit
bb62bf1aa9
3 changed files with 129 additions and 31 deletions
|
|
@ -507,8 +507,76 @@ let
|
|||
bao = h.deploy.bao.enable;
|
||||
};
|
||||
|
||||
# The hive-name guards, with the collector explicitly OFF. That is the whole
|
||||
# property: the guards live where `swarm.hives` is declared, so they run in a
|
||||
# deployment that has a secret store and no collector — which used to skip
|
||||
# them entirely, because they were assertions inside swarm-otel's own `mkIf`.
|
||||
#
|
||||
# ⚠️ `controllerCommonName` is overridden to a name containing NO reserved
|
||||
# fragment. Its default (`swarm-controller`) contains `swarm` and is caught
|
||||
# by the substring guard whatever the cert-auth arm does — so a fixture using
|
||||
# the default could not tell the two apart, and the arm under test would pass
|
||||
# on the neighbour's work.
|
||||
hiveNamedAfterCertSubject = hive {
|
||||
deploy.swarm-otel.enable = false;
|
||||
deploy.bao.controllerCommonName = "ctl";
|
||||
swarm.hives.ctl.domain = "ctl.t.local";
|
||||
};
|
||||
|
||||
# The control for both arms below: same shape, a roster nothing objects to.
|
||||
hiveNamesAllLegal = hive {
|
||||
deploy.swarm-otel.enable = false;
|
||||
deploy.bao.controllerCommonName = "ctl";
|
||||
};
|
||||
|
||||
hiveNameWithComposedWord = hive {
|
||||
deploy.swarm-otel.enable = false;
|
||||
swarm.hives."h1-agent".domain = "a.t.local";
|
||||
};
|
||||
|
||||
# Markers from `lib/name-guards.nix`'s two `problem` strings. Matching the
|
||||
# problem rather than the `why` prose keeps the messages rewordable.
|
||||
equalityGuardFired =
|
||||
h: lib.any (a: !a.assertion && lib.hasInfix "has reserved name(s)" a.message) h.assertions;
|
||||
fragmentGuardFired =
|
||||
h:
|
||||
lib.any (
|
||||
a: !a.assertion && lib.hasInfix "has name(s) containing a reserved word" a.message
|
||||
) h.assertions;
|
||||
|
||||
# Each case: a name stating the property, and `ok`.
|
||||
cases = [
|
||||
{
|
||||
# `ctl` is in no deny list — it is reserved *because it is the subject a
|
||||
# cert-auth role accepts*, which is a value an operator sets, so a
|
||||
# literal deny entry could never have covered it.
|
||||
name = "a hive named after a cert-auth subject is refused, with the collector off";
|
||||
ok =
|
||||
equalityGuardFired hiveNamedAfterCertSubject
|
||||
&& lib.any (a: !a.assertion && lib.hasInfix "'ctl'" a.message) hiveNamedAfterCertSubject.assertions;
|
||||
}
|
||||
{
|
||||
# Without this the case above proves nothing: an arm that fires for every
|
||||
# roster is not a guard, and `hives` is non-empty in both fixtures.
|
||||
name = "a legal hive roster trips neither name guard";
|
||||
ok = !(equalityGuardFired hiveNamesAllLegal) && !(fragmentGuardFired hiveNamesAllLegal);
|
||||
}
|
||||
{
|
||||
# The substring guard came along in the move and has to still work.
|
||||
# `h1-agent` mints exactly the client id hive `h1`'s agents present.
|
||||
name = "a hive name containing a composed-identifier word is refused, with the collector off";
|
||||
ok = fragmentGuardFired hiveNameWithComposedWord;
|
||||
}
|
||||
{
|
||||
# ⚠️ The control that makes "with the collector off" mean anything. If a
|
||||
# fixture silently had swarm-otel enabled, all three cases above would
|
||||
# pass while testing the arrangement they exist to rule out.
|
||||
name = "the guard fixtures really do have the collector disabled";
|
||||
ok =
|
||||
!hiveNamedAfterCertSubject.services.hyperhive.deploy.swarm-otel.enable
|
||||
&& !hiveNamesAllLegal.services.hyperhive.deploy.swarm-otel.enable
|
||||
&& !hiveNameWithComposedWord.services.hyperhive.deploy.swarm-otel.enable;
|
||||
}
|
||||
{
|
||||
# `lib.all` over an empty set holds vacuously, so the roster is counted
|
||||
# before it is read: a helper that lost a member would otherwise turn
|
||||
|
|
|
|||
Loading…
Reference in a new issue