Watch
0
0
Fork
You've already forked hyperhive
0

require k8s: swarm services with a pod run in the cluster only

This commit is contained in:
atlas 2026-11-26 00:36:09 +01:00 • committed by mara
commit 052b559196
9 changed files with 1044 additions and 3125 deletions

View file

@ -2779,7 +2779,7 @@ let
# The controller's whole reach on any PKI mount: one role's issue
# endpoint. It cannot rewrite the role, sign a CSR of its choosing or
# touch the issuer, so the role's narrowing is the narrowing.
name = "the controller's only PKI grant is update on the agent role's issue path";
name = "the controller's only PKI grants are update on the agent role's issue path and on its listener's";
ok =
let
cg = grantsIn baoGrantHere.systemd.services.swarm-bao-controller-policy.script;
@ -2789,6 +2789,12 @@ let
path = "pki-agents/issue/swarm-agent";
caps = [ "update" ];
}
# The listener's own leaf, which the controller's pod issues now that the
# listener is on by default.
{
path = "pki/issue/swarm-controller-tls";
caps = [ "update" ];
}
]
&& lib.all (p: grantFor cg p == null) [
"pki-agents/roles/swarm-agent"

View file

@ -380,7 +380,7 @@ let
# The responder denies a client id it does not know, and a NATS denial
# arrives as a timeout.
name = "the queue's responder grants the builder's client its subject";
ok = lib.hasInfix "--builder-client swarm-builder" natsHere.containers.swarm-nats.config.systemd.services.swarm-nats-auth.serviceConfig.ExecStart;
ok = lib.hasInfix "--builder-client swarm-builder" natsHere.services.hyperhive.deploy.nats.unit.serviceConfig.ExecStart;
}
{
name = "the builder's client is registered as a machine, and the mint stores its secret";

View file

@ -30,24 +30,27 @@ let
# poller defaults on, beside authelia, the publisher and the collector.
allLocal = shared.allLocal;
svc = allLocal.systemd.services.swarm-ci-metrics;
svc = allLocal.services.hyperhive.deploy.ci-metrics.unit;
timer = allLocal.services.hyperhive.deploy.ci-metrics.timer;
env = svc.environment;
clientId = allLocal.services.hyperhive.swarm.ci-metrics.clientId;
otel = allLocal.services.hyperhive.swarm.otel;
cases = [
{
# The control is the same unit and timer on the all-local host: a
# misspelled attribute path would make the absence arm pass alone.
name = "the CI run poller's unit and timer exist only where its host enables it";
# The unit and timer are the source of the poller's CronJob: the host runs
# neither. The unit and timer options are the control that the lookups find
# what the host does not have.
name = "the CI run poller's unit and timer are the source of its CronJob and the host runs neither";
ok =
!(bare.systemd.services ? swarm-ci-metrics)
&& !(bare.systemd.timers ? swarm-ci-metrics)
&& !(allLocal.systemd.services ? swarm-ci-metrics)
&& !(allLocal.systemd.timers ? swarm-ci-metrics)
&& allLocal.services.hyperhive.deploy.ci-metrics.enable
&& svc.serviceConfig.Type == "oneshot"
&& !(svc.serviceConfig.RemainAfterExit or false)
&& allLocal.systemd.timers.swarm-ci-metrics.timerConfig.OnUnitInactiveSec == "5min"
&& lib.elem "timers.target" allLocal.systemd.timers.swarm-ci-metrics.wantedBy;
&& timer.timerConfig.OnUnitInactiveSec == "5min"
&& lib.elem "timers.target" timer.wantedBy;
}
{
# The leaf is handed in as a credential, never an argument; the forge
@ -83,16 +86,13 @@ let
# without the bundle every pass fails `UnknownIssuer`. hive-c0re's
# bundle on the bare host is the control that the absence arm looks up
# a unit name the module would write.
name = "the poller trusts the swarm's CA through its own bundle, which exists only where the poller does";
name = "the poller trusts the swarm's CA through its own bundle, which the pod builds and the host does not run";
ok =
allLocal.services.hyperhive.gateway.useSelfSigned
&& (env.SSL_CERT_FILE or null) == "/run/swarm-ci-metrics-ca/trust-bundle.pem"
&& lib.elem "swarm-ci-metrics-ca-bundle.service" svc.requires
&& lib.elem "hive-tls-ca.service" (
allLocal.systemd.services.swarm-ci-metrics-ca-bundle.requires or [ ]
)
&& bare.systemd.services ? hive-c0re-ca-bundle
&& !(bare.systemd.services ? swarm-ci-metrics-ca-bundle);
&& !(allLocal.systemd.services ? swarm-ci-metrics-ca-bundle);
}
{
name = "the poller's client is registered as a machine, and the mint stores its secret";

View file

@ -41,24 +41,20 @@ let
deploy.hive-controller.hyperhiveRev = lib.fixedWidthString 40 "b" "";
};
# `allLocal` with the controller's TCP listener on, the one fixture that has
# the store, the controller and the gateway together: the two roles, the two
# issue grants and the vhost all render from this one option. The firewall is
# opened so the lookup that finds the port is shown to find it. Off is
# `allLocal` itself.
# `allLocal` with the firewall opened for the controller's TCP listener, the one
# fixture that has the store, the controller and the gateway together: the two
# roles, the two issue grants and the vhost all render from the listener's
# option. The firewall is opened so the lookup that finds the port is shown to
# find it.
allLocalTcp = hiveWithController {
deploy.singleHostSwarm = true;
swarm.controller.tcp = {
enable = true;
domain = "controller.t.local";
};
deploy.swarm-controller.tcp.openFirewall = true;
};
# The listener asked for with nothing to name it by.
# A controller on a swarm with no domain, so nothing to name the listener by.
tcpNoDomain = hive {
deploy.swarm-controller.enable = true;
swarm.controller.tcp.enable = true;
swarm.domain = lib.mkForce null;
};
bare = shared.bareWithController;
@ -178,10 +174,9 @@ let
};
# A container the operator runs that hyperhive doesn't own, next to one it
# does (the classifier's).
# does (the secret store's).
withForeignContainer = hiveWith [ { containers.operator-box.config = { }; } ] {
deploy.bao.enable = true;
deploy.review-classifier.enable = true;
};
# On the store's host, which mints the runner's store identity.
@ -196,13 +191,6 @@ let
deploy.review-classifier.enable = true;
};
# The same classifier on a host that runs a hive: its metrics path is the
# same as without one.
withClassifierOnHive = hiveWithController {
deploy.bao.enable = true;
deploy.review-classifier.enable = true;
};
# The host fetches that restart their consumer when the store's value
# changes (../host-modules/lib/refresh-consumer.nix), each on a fixture
# that renders it.
@ -817,11 +805,10 @@ let
ok =
let
l = allLocal.services.nginx.virtualHosts."t.local".locations;
socket = allLocal.services.hyperhive.deploy.swarm-controller.socketPath;
in
lib.hasInfix "auth_request /__hive_authelia;" l."/api/".extraConfig
&& lib.hasInfix socket l."/api/".proxyPass
&& lib.hasInfix socket l."/webhook/forge/".proxyPass
&& lib.hasInfix "swarm_controller_upstream" l."/api/".proxyPass
&& lib.hasInfix "swarm_controller_upstream" l."/webhook/forge/".proxyPass
&& !(lib.hasInfix "auth_request" l."/webhook/forge/".extraConfig);
}
{
@ -1004,23 +991,24 @@ let
ok = forceServiceConfigs withCi.containers.swarm-ci-runner.config;
}
{
# It spends money on an operator's key, so no host runs it by default.
name = "the review classifier's container exists only where its host enables it";
# It spends money on an operator's key, so no host runs it by default, and
# where one does it is a pod: no container.
name = "the review classifier is enabled only where its host asks, and runs as a pod";
ok =
!(bare.containers ? swarm-review-classifier)
&& !(centralToggleOff.containers ? swarm-review-classifier)
&& withClassifier.containers ? swarm-review-classifier;
!bare.services.hyperhive.deploy.review-classifier.enable
&& !centralToggleOff.services.hyperhive.deploy.review-classifier.enable
&& withClassifier.services.hyperhive.deploy.review-classifier.enable
&& !(withClassifier.containers ? swarm-review-classifier);
}
{
# The daemon holds its store leaf, handed in by nspawn without a copy on
# disk, and nothing else from the host; a key is read per run and
# reaches only the model child's environment. Reading the claude path
# also evaluates the container's unfree allowance.
name = "the review classifier loads only its store leaf and carries no API or provider key in its unit";
name = "the review classifier's unit names only its store leaf and carries no API or provider key";
ok =
let
svc =
withClassifier.containers.swarm-review-classifier.config.systemd.services.swarm-review-classifier;
svc = withClassifier.services.hyperhive.deploy.review-classifier.unit;
env = svc.environment;
in
lib.elem "review-classifier-bao-key" svc.serviceConfig.LoadCredential
@ -1031,44 +1019,12 @@ let
&& lib.hasSuffix "/bin/opencode" env.SWARM_REVIEW_CLASSIFIER_OPENCODE
&& !(env ? ANTHROPIC_API_KEY)
&& !(env ? ACP_PROVIDER_API_KEY)
&& lib.elem "--load-credential=review-classifier-bao-key:/var/lib/swarm-bao-pki/review-classifier-key.pem" (
withClassifier.containers.swarm-review-classifier.extraFlags
)
# No host unit copies the leaf into the container's root.
&& !(lib.any (u: lib.hasInfix "nixos-containers/swarm-review-classifier" (u.script or "")) (
lib.attrValues withClassifier.systemd.services
));
}
{
# The collector the classifier's metrics reach is the container's own
# forwarder, which holds the service's client, so the path is the same
# with or without a hive on the host. The logs pipeline is the control
# that the lookup finds what is there.
name = "the review classifier pushes its metrics to the swarm collector through its own forwarder, with or without a hive";
ok =
let
check =
h:
let
c = h.containers.swarm-review-classifier.config;
s = c.services.opentelemetry-collector.settings;
otel = h.services.hyperhive.swarm.otel;
in
c.systemd.services.swarm-review-classifier.environment.OTEL_EXPORTER_OTLP_ENDPOINT
== "http://127.0.0.1:4318"
&& s.receivers.otlp.protocols.http.endpoint == "127.0.0.1:4318"
&& s.service.pipelines.metrics.receivers == [ "otlp" ]
&& s.service.pipelines.metrics.exporters == [ "otlphttp" ]
&& s.exporters.otlphttp.endpoint == "https://${otel.domain}/swarm-review-classifier"
&& s.exporters.otlphttp.auth.authenticator == "oauth2client/swarm"
&& s.service.pipelines.logs.receivers == [ "journald" ];
in
check withClassifier && check withClassifierOnHive;
&& !(withClassifier.systemd.services ? swarm-review-classifier);
}
{
# The runner serves its Prometheus endpoint on loopback in its own
# netns, and the container's forwarder scrapes exactly that address into
# a pipeline that leaves through the swarm exporter. The classifier's
# a pipeline that leaves through the swarm exporter.
# forwarder, which sets no extra targets, is the control: no extra
# receiver, no extra pipeline.
name = "the CI runner's built-in metrics are scraped on loopback by its forwarder";
@ -1076,8 +1032,6 @@ let
let
cc = withCi.containers.swarm-ci-runner.config;
s = cc.services.opentelemetry-collector.settings;
c =
withClassifier.containers.swarm-review-classifier.config.services.opentelemetry-collector.settings;
runner = cc.services.gitea-actions-runner.instances.swarm.settings;
in
runner.metrics.enabled == true
@ -1091,21 +1045,7 @@ let
]
&& s.service.pipelines."metrics/extra".receivers == [ "prometheus/extra" ]
&& s.service.pipelines."metrics/extra".exporters == [ "otlphttp" ]
&& s.exporters ? otlphttp
&& !(c.receivers ? "prometheus/extra")
&& !(c.service.pipelines ? "metrics/extra");
}
{
# Only the classifier asks the forwarder for a metrics receiver; the
# others carry a journal. The classifier is the control.
name = "a service forwarder without an OTLP port has no metrics pipeline";
ok =
let
s = withCi.containers.swarm-ci-runner.config.services.opentelemetry-collector.settings;
c =
withClassifier.containers.swarm-review-classifier.config.services.opentelemetry-collector.settings;
in
c.service.pipelines ? metrics && !(s.service.pipelines ? metrics) && !(s.receivers ? otlp);
&& s.exporters ? otlphttp;
}
{
# The hive tier is the labelling point for a hive's telemetry, so it runs
@ -1127,15 +1067,6 @@ let
&& lib.elem "hive-collector.hive" bare.services.hyperhive.gateway.localNames
&& !(lib.elem "hive-collector.hive" shared.servicesHere.services.hyperhive.gateway.localNames);
}
{
# 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
@ -2526,7 +2457,7 @@ let
&&
old.containers.swarm-builder.config.systemd.services.swarm-builder.environment.SWARM_BUILDER_NIXPKGS_FLAKE
== "path:/legacy/nixpkgs"
&& (locs sw.nats.domain)."= /metrics".proxyPass == "http://127.0.0.1:17777/metrics"
&& lib.hasInfix ":17777;" (locs sw.nats.domain)."= /metrics".extraConfig
&& old.containers.hive-matrix.config.services.matrix-tuwunel.settings.global.allow_encryption
&& lib.all warned [
"swarm.controller.queue.natsUrl"
@ -2564,7 +2495,7 @@ let
&& h.deploy.nats.monitorPort == 8222
&& h.deploy.nats.otel.telemetryPort == 8891
&& h.deploy.swarm-otel.telemetryPort == 8889
&& (locs h.swarm.nats.domain)."= /metrics".proxyPass == "http://127.0.0.1:7777/metrics"
&& lib.hasInfix ":7777;" (locs h.swarm.nats.domain)."= /metrics".extraConfig
&&
(locs h.swarm.victorialogs.domain)."= /metrics".proxyPass
== "http://unix:/run/swarm-victorialogs/victorialogs.sock:/metrics"
@ -2963,13 +2894,8 @@ let
"swarm-authelia"
"swarm-bao"
"swarm-builder"
"swarm-claude-login"
"swarm-grafana"
"swarm-nats"
"swarm-notify-router"
"swarm-otel"
"swarm-review-classifier"
"swarm-stt"
"swarm-victorialogs"
"swarm-victoriametrics"
]
@ -3032,9 +2958,7 @@ let
lib.attrNames withForeignContainer.containers == [
"operator-box"
"swarm-bao"
"swarm-review-classifier"
]
&& lib.length (checks "swarm-review-classifier") == 1
&& lib.length (checks "swarm-bao") == 1
&& checks "operator-box" == [ ];
}
@ -3152,42 +3076,6 @@ let
mentions "privateListenAddresses holds"
&& !(mentions "while services.hyperhive.gateway.privateListenAddresses is empty");
}
{
# The off arm of the controller's TCP listener: a host that never set it
# renders what it rendered before it existed. The gateway still reaches
# the controller by socket, nothing TCP-shaped is rendered, and the
# store writes neither role nor grant. The `swarm-services-cert` unit is
# the presence control for the unit lookup, and the socket in
# `proxyPass` for the location lookup.
name = "a swarm without the controller's TCP listener renders the socket-only controller";
ok =
let
m = allLocal;
l = m.services.nginx.virtualHosts."t.local".locations;
socket = "http://unix:${m.services.hyperhive.deploy.swarm-controller.socketPath}:";
env = m.systemd.services.swarm-controller.environment;
policies = m.systemd.services.swarm-bao-controller-policy.script;
issuer = m.systemd.services.swarm-bao-services-issuer-policy.script;
in
l."/api/".proxyPass == socket
&& l."/webhook/forge/".proxyPass == socket
&& !(lib.hasInfix "proxy_ssl_certificate" l."/api/".extraConfig)
&& !(lib.hasInfix "proxy_ssl" l."/webhook/forge/".extraConfig)
&& !(m.systemd.services ? swarm-controller-tls)
&& !(m.systemd.services ? swarm-controller-gateway-client)
&& !(m.systemd.timers ? swarm-controller-tls)
&& !(m.systemd.timers ? swarm-controller-gateway-client)
&& m.systemd.services ? swarm-services-cert
&& !(lib.any (lib.hasPrefix "SWARM_CONTROLLER_TCP_") (lib.attrNames env))
&& !(lib.elem 9443 m.networking.firewall.allowedTCPPorts)
&& !(lib.hasInfix "swarm-controller-tls" policies)
&& !(lib.hasInfix "swarm-controller-gateway-client" policies)
&& !(lib.hasInfix "swarm-controller-gateway-client" issuer)
&& lib.hasInfix "issue/swarm-services" issuer
&& env.SWARM_CONTROLLER_PUBLIC_URL == "https://t.local"
&& m.services.hyperhive.deploy.swarm-controller.tcp.openFirewall == false
&& allLocalTcp.services.hyperhive.deploy.swarm-controller.tcp.openFirewall == true;
}
{
# The on arm. The gateway dials the listener by name over TLS, verified,
# with the client leaf, and keeps the operator gate on `/api/` and the
@ -3200,7 +3088,7 @@ let
let
m = allLocalTcp;
l = m.services.nginx.virtualHosts."t.local".locations;
upstream = "https://controller.t.local:9443";
upstream = "https://\$swarm_controller_upstream";
tls = m.services.hyperhive.deploy.hive-controller.tls.stateDir;
env = m.systemd.services.swarm-controller.environment;
dialled =
@ -3228,8 +3116,9 @@ let
&& env.SWARM_CONTROLLER_TCP_CLIENT_NAME == "gateway-client.t.local"
&& lib.elem 9443 m.networking.firewall.allowedTCPPorts
&& env.SWARM_CONTROLLER_PUBLIC_URL == "https://t.local"
&& m.systemd.services.swarm-controller-tls.wantedBy == [ "multi-user.target" ]
&& lib.elem "swarm-controller-tls.service" m.systemd.services.swarm-controller.after;
# The listener's leaf is the pod's, so the host has no unit for it.
&& !(m.systemd.services ? swarm-controller-tls)
&& !(m.systemd.timers ? swarm-controller-tls);
}
{
# The two roles carry opposite flag pairs, which is the whole reason the
@ -3285,7 +3174,7 @@ let
&& allLocalTcp.systemd.timers ? swarm-controller-gateway-client;
}
{
name = "the controller's TCP listener is refused at eval with no name to dial it by";
name = "the controller is refused at eval where no swarm domain names its listener";
ok =
let
fired = lib.filter (a: !a.assertion) tcpNoDomain.assertions;

File diff suppressed because it is too large Load diff

View file

@ -61,7 +61,7 @@ let
deploy.bao.clientKeyFile = "/etc/pki/h1-key.pem";
};
responderOf = h: h.containers.swarm-nats.config.systemd.services.swarm-nats-auth;
responderOf = h: h.services.hyperhive.deploy.nats.unit;
refusedWithoutIdentity =
m:
@ -77,8 +77,8 @@ let
# The same swarm's IdP host, for the arm that the two agree.
autheliaColocated = shared.autheliaOnly;
# The other four queue clients with a container of their own, each forwarding
# its journal as the queue's does. One shared host: the switch that turns on
# The queue client with a container of its own, which forwards its journal
# from there; the other services run as pods. One shared host: the switch that turns on
# every swarm service, which other suites already evaluate.
servicesHost = shared.swarmServicesWithController;
forwarderServices = [
@ -88,30 +88,6 @@ let
credential = "builder-bao";
port = 8892;
}
{
machine = "swarm-claude-login";
name = "claude-login";
credential = "claude-login-bao";
port = 8893;
}
{
machine = "swarm-review-classifier";
name = "review-classifier";
credential = "review-classifier-bao";
port = 8894;
}
{
machine = "swarm-notify-router";
name = "notify-router";
credential = "notify-router-bao";
port = 8902;
}
{
machine = "swarm-stt";
name = "stt";
credential = "stt-bao";
port = 8904;
}
];
forwarderFetchDir = "/run/credentials/swarm-journal-forwarder-oidc.service";
@ -338,7 +314,8 @@ let
# Piggybacks on the queue-only fixture above, which already
# renders this container's full config.
name = "the queue's payload ceiling is set, not inherited from the server's default";
ok = natsQueueOnly.containers.swarm-nats.config.services.nats.settings.max_payload == 8388608;
ok =
natsQueueOnly.services.hyperhive.deploy.nats.system.services.nats.settings.max_payload == 8388608;
}
{
# What keeps a callout request inside one principal: the responder is
@ -352,7 +329,7 @@ let
(
h:
let
settings = h.containers.swarm-nats.config.services.nats.settings;
settings = h.services.hyperhive.deploy.nats.system.services.nats.settings;
in
settings.authorization.auth_callout.account == "AUTH"
&& lib.length settings.accounts.AUTH.users == 1
@ -373,7 +350,7 @@ let
(
h:
let
c = h.containers.swarm-nats.config;
c = h.services.hyperhive.deploy.nats.system;
nats = c.systemd.services.nats.serviceConfig;
pre = lib.toList (nats.ExecStartPre or [ ]);
render = lib.head pre;
@ -399,15 +376,14 @@ let
# `Restart=always`. `RestartSec` is the control that the lookup reaches
# the unit's real `serviceConfig`; the callout key fetch starts the
# responder after it restarts the server.
name = "the queue's responder has no start limit, always restarts, and is started after the key fetch";
name = "the queue's responder has no start limit and always restarts";
ok =
let
r = responderOf natsQueueOnly;
in
r.startLimitIntervalSec == 0
&& r.serviceConfig.Restart == "always"
&& r.serviceConfig.RestartSec == "5s"
&& lib.hasInfix "start --no-block swarm-nats-auth.service" natsWithStoreIdentity.systemd.services.swarm-bao-nats-callout-xkey.script;
&& r.serviceConfig.RestartSec == "5s";
}
{
# A server that starts late, once its xkey arrives, must bring the
@ -423,7 +399,7 @@ let
name = "the server and the trust bundle the queue's responder requires both uphold it";
ok =
let
c = natsQueueOnly.containers.swarm-nats.config;
c = natsQueueOnly.services.hyperhive.deploy.nats.system;
in
lib.sort lib.lessThan c.systemd.units."swarm-nats-auth.service".upheldBy == [
"nats.service"
@ -432,92 +408,6 @@ let
&& c.systemd.units ? "nats.service"
&& c.systemd.units ? "swarm-nats-ca-bundle.service";
}
{
# The keys are created before anything needs them, by the responder's
# own verb under its own leaf, then each public half is read back from
# the store and left where the server's render reads it. Before the
# container and wanted by it, and a fetch that finds nothing fails so
# `storeRetry` retries.
name = "the callout keys are created, then their public halves fetched from the store before the queue's container starts";
ok =
let
u = natsWithStoreIdentity.systemd.services.swarm-bao-nats-callout-xkey;
s = builtins.unsafeDiscardStringContext u.script;
at = needle: lib.stringLength (lib.head (lib.splitString needle s));
ensure = "swarm-nats-auth ensure-callout-keys --store-cert-role swarm-nats-auth";
fetched =
leaf: file:
let
fetch = "bao kv get -field=value secret/swarm/public/swarm-nats/${leaf}";
path = "/var/lib/nixos-containers/swarm-nats/var/lib/nats-callout/${file}";
in
lib.hasInfix fetch s
&& at ensure < at fetch
&& lib.hasInfix "atomic_write_secret 0444 \"\" ${path}" s
&& lib.hasInfix "refresh_consumer swarm-nats nats.service ${path}" s;
in
lib.elem "container@swarm-nats.service" u.before
&& lib.elem "container@swarm-nats.service" u.wantedBy
&& u.environment.BAO_CLIENT_CERT == "/etc/pki/nats-auth.pem"
&& lib.hasInfix ensure s
&& fetched "callout-xkey" "callout-xkey.pub"
&& fetched "callout-issuer" "issuer.pub"
&& fetched "callout-user" "callout-user.pub"
&& !(lib.hasInfix "exit 0" s)
&& u.serviceConfig.Restart == "on-failure";
}
{
# The seeds a host kept on disk are what the verb stores when the store
# holds none, so the keys keep their public halves; the verb removes
# them itself. Nothing mints a seed on the host, and no
# tmpfiles rule touches the host seeds, which could run before the
# import does.
name = "the callout keys import the host's seed files, which only the importing unit removes";
ok =
let
s = natsWithStoreIdentity.systemd.services.swarm-bao-nats-callout-xkey.script;
rules = natsWithStoreIdentity.systemd.tmpfiles.rules;
in
lib.hasInfix "--import-issuer-seed-file /var/lib/swarm-nats-callout/issuer.seed" s
&& lib.hasInfix "--import-user-seed-file /var/lib/swarm-nats-callout/callout-user.seed" s
&& !(natsWithStoreIdentity.systemd.services ? swarm-nats-callout-keys)
&& !(lib.any (lib.hasInfix "/var/lib/swarm-nats-callout") rules);
}
{
# Its creates are what the responder's role was granted, and the
# publisher's policy is what denies the publisher the seeds' paths: a
# seed found there is kept. On the store's host both units run first.
name = "on the store's host the callout key fetch waits for the responder's role and the publisher's denial";
ok =
let
u = natsOnStoreHost.systemd.services.swarm-bao-nats-callout-xkey;
waitsFor = p: lib.elem "${p}.service" u.after && lib.elem "${p}.service" u.wants;
in
u.environment.BAO_CLIENT_CERT == "/var/lib/swarm-bao-pki/nats-auth.pem"
&& waitsFor "swarm-bao-nats-auth-policy"
&& 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.
name = "off the store's host the callout key fetch waits for no policy unit";
ok =
let
u = natsWithStoreIdentity.systemd.services.swarm-bao-nats-callout-xkey;
in
!(lib.any (lib.hasSuffix "-policy.service") (u.after ++ u.wants));
}
{
# The responder takes no agent-client suffix: no such client is minted.
# `--hive-client-prefix` is the control that the lookup finds a flag the
@ -525,8 +415,7 @@ let
name = "the responder is passed no agent-client suffix";
ok =
let
exec =
natsQueueOnly.containers.swarm-nats.config.systemd.services.swarm-nats-auth.serviceConfig.ExecStart;
exec = natsQueueOnly.services.hyperhive.deploy.nats.unit.serviceConfig.ExecStart;
in
lib.hasInfix "--hive-client-prefix " exec && !(lib.hasInfix "--agent-client-suffix" exec);
}
@ -595,20 +484,6 @@ let
&& u.environment.BAO_CLIENT_KEY == "/run/credentials/swarm-nats-auth.service/bao-client-key.pem"
&& lib.hasPrefix "https://" u.environment.BAO_ADDR;
}
{
# Copied so an absent leaf fails the unit rather than reaching the
# responder as a file it cannot log in with. No seed is copied: the
# responder reads every callout seed from the store.
name = "the copy unit delivers the store identity and no seed, and nothing in its place when absent";
ok =
let
s = natsWithStoreIdentity.systemd.services.swarm-nats-auth-secrets.script;
in
lib.hasInfix "install -m 0400 /etc/pki/nats-auth.pem " s
&& lib.hasInfix "install -m 0400 /etc/pki/nats-auth-key.pem " s
&& !(lib.hasInfix "/dev/null" s)
&& !(lib.hasInfix ".seed" s);
}
{
# The responder names no seed file, by flag or by credential, and the
# copies a container may still hold are removed. The store identity is
@ -674,15 +549,12 @@ let
# On or off the store's host alike; the callout key fetch beside it is
# the control that the unit set is read at all, and the store cert role
# the control on the flags.
name = "the responder's OIDC secret is fetched by no unit and carried by no credential or flag, and the container's copy is removed";
name = "the responder's OIDC secret is fetched by no unit and carried by no credential or flag, and the old container's copy is removed";
ok =
let
fetchedNowhere =
h:
!(h.systemd.services ? swarm-bao-nats-auth-oidc)
&& h.systemd.services ? swarm-bao-nats-callout-xkey;
h: !(h.systemd.services ? swarm-bao-nats-auth-oidc) && h.systemd.services ? swarm-bao-nats-tls;
u = responderOf natsWithStoreIdentity;
copy = natsWithStoreIdentity.systemd.services.swarm-nats-auth-secrets.script;
removesCopy = h: lib.elem "r ${dir}/oidc-client.secret" h.systemd.tmpfiles.rules;
dir = "/var/lib/nixos-containers/swarm-nats/var/lib/swarm-nats-auth";
in
@ -692,9 +564,7 @@ let
&& !(lib.hasInfix "client-secret" u.serviceConfig.ExecStart)
&& lib.hasInfix "--store-cert-role swarm-nats-auth" u.serviceConfig.ExecStart
&& removesCopy natsWithStoreIdentity
&& removesCopy autheliaNotColocated
&& !(lib.hasInfix "oidc-client" copy)
&& !(lib.hasInfix "authelia" copy);
&& removesCopy autheliaNotColocated;
}
{
# On the store's host the glue pairs the responder with a leaf of its
@ -780,43 +650,6 @@ let
autheliaColocated.services.hyperhive.swarm.authelia.url
== autheliaNotColocated.services.hyperhive.swarm.authelia.url;
}
{
# The queue container's own journal forwarder, on the store's host and
# on a queue host with no store and no swarm collector: it exports to
# the swarm collector's `swarm-nats` route by name, authenticated as
# the queue's client, and its secret is read with the responder's
# store identity inside the container.
name = "the queue container forwards its journal to its own route on the swarm collector";
ok =
lib.all
(
h:
let
c = h.containers.swarm-nats.config;
s = c.services.opentelemetry-collector.settings;
otel = h.services.hyperhive.swarm.otel;
fetch = c.systemd.services.swarm-journal-forwarder-oidc;
clientId = h.services.hyperhive.swarm.nats.clientId;
in
c.services.opentelemetry-collector.enable
&& s.exporters.otlphttp.endpoint == "https://${otel.domain}/swarm-nats"
&& s.exporters.otlphttp.auth.authenticator == "oauth2client/swarm"
&& s.extensions."oauth2client/swarm".client_id == clientId
&& s.extensions."oauth2client/swarm".endpoint_params.audience == clientId
&& lib.elem "oauth2client/swarm" s.service.extensions
&& s.service.pipelines.logs.receivers == [ "journald" ]
&& selfScrapes s h.services.hyperhive.deploy.nats.otel.telemetryPort { container = "nats"; }
&& lib.elem "oidc-client-secret:/run/swarm-journal-forwarder-oidc/client-secret" c.systemd.services.opentelemetry-collector.serviceConfig.LoadCredential
&& fetch.environment.BAO_CLIENT_CERT == "/var/lib/swarm-nats-auth/bao-client.pem"
&& lib.hasInfix "bao kv get -field=value secret/swarm/services/${clientId}/oidc/client" fetch.script
# The guest keeps its journal; a host-linked one is empty inside.
&& !(lib.elem "--link-journal=host" h.containers.swarm-nats.extraFlags)
)
[
natsOnStoreHost
natsWithStoreIdentity
];
}
{
# The far end: a receiver, authenticator, pipeline entry and gateway
# route of its own, checking the queue client as audience. Rendered on

View file

@ -89,7 +89,7 @@ let
policyScript = allLocal.systemd.services.swarm-bao-nats-tls-policy.script;
leafUnit = allLocal.systemd.services.swarm-bao-nats-tls;
natsContainer = allLocal.containers.swarm-nats.config;
natsContainer = allLocal.services.hyperhive.deploy.nats.system;
natsTls = natsContainer.services.nats.settings.tls;
# Every `(nats|tls)://…` in a string.
@ -118,21 +118,28 @@ let
containerUnits = lib.concatLists (
lib.mapAttrsToList (c: cc: fromUnits c cc.config.systemd.services) machine.containers
);
# The daemons that run as pods are read from the units their pods are
# rendered from.
d = machine.services.hyperhive.deploy;
podUnits = lib.concatLists (
map (n: lib.optionals d.${n}.enable (fromUnits "pod" { ${n} = d.${n}.unit; })) [
"notify-router"
"stt"
"review-classifier"
"claude-login"
"ci-metrics"
]
);
# The responder runs beside the queue only, so a hive without one has
# none to read.
responder =
map
(u: {
name = "swarm-nats/swarm-nats-auth/--nats-url";
value = u;
})
(
lib.optionals (machine.containers ? swarm-nats) (
urlsIn machine.containers.swarm-nats.config.systemd.services.swarm-nats-auth.serviceConfig.ExecStart
)
);
responder = map (u: {
name = "swarm-nats/swarm-nats-auth/--nats-url";
value = u;
}) (lib.optionals d.nats.enable (urlsIn d.nats.unit.serviceConfig.ExecStart));
in
lib.listToAttrs (fromUnits "host" machine.systemd.services ++ containerUnits ++ responder);
lib.listToAttrs (
fromUnits "host" machine.systemd.services ++ containerUnits ++ podUnits ++ responder
);
scanned = clientUrls allLocal;
@ -206,12 +213,10 @@ let
{
# Mint to consume: the leaf the unit writes is the one the server reads,
# and the login leaf glue-bao-tls signs is the one the unit presents.
name = "the server serves the leaf the host unit issues, and the unit logs in as swarm-nats";
name = "the server serves the leaf the pod issues, and the host unit that writes the gateway's copy logs in as swarm-nats";
ok =
natsTls.cert_file == "/var/lib/swarm-nats-tls/cert.pem"
&& natsTls.key_file == "/run/credentials/nats.service/tls-key"
&& lib.elem "tls-key:/var/lib/swarm-nats-tls/key.pem" natsContainer.systemd.services.nats.serviceConfig.LoadCredential
&& allLocal.containers.swarm-nats.bindMounts ? "/var/lib/swarm-nats-tls"
&& natsTls.key_file == "/var/lib/swarm-nats-tls/key.pem"
&& lib.hasInfix "d=/var/lib/swarm-nats-tls" leafUnit.script
&& lib.hasInfix "pki/issue/swarm-nats" leafUnit.script
&& leafUnit.environment.BAO_CLIENT_CERT == "/var/lib/swarm-bao-pki/nats.pem"
@ -221,14 +226,14 @@ let
{
# The leaf rotation restarts the server; the responder, stopped when
# the server failed, is cleared and started after it.
name = "the leaf rotation starts the responder after restarting the server";
name = "the host's leaf unit restarts no server: the queue runs in the pod";
ok =
let
s = leafUnit.script;
in
lib.hasInfix "restart nats.service" s
&& lib.hasInfix "reset-failed swarm-nats-auth.service" s
&& lib.hasInfix "start --no-block swarm-nats-auth.service" s;
lib.hasInfix "pki/issue/swarm-nats" s
&& !(lib.hasInfix "restart nats.service" s)
&& !(lib.hasInfix "swarm-nats-auth.service" s);
}
{
# The hive's own reader is not the queue's identity, and no path is
@ -397,7 +402,7 @@ let
]
&& locs."/".return == "403"
&& locs."/".proxyPass == null
&& locs."= /metrics".proxyPass == "http://127.0.0.1:${toString h.deploy.nats.metricsPort}/metrics"
&& locs."= /metrics".proxyPass == "http://\$swarm_nats_metrics_upstream/metrics"
&& checksOf locs."= /metrics" == [ "auth_request /__nats_metrics_authz;" ]
&& !(lib.hasInfix "error_page" locs."= /metrics".extraConfig)
&& authz.proxyPass == "https://auth.t.local/api/authz/auth-request"

View file

@ -36,21 +36,23 @@ let
# a unit's ExecStart names which option it read. Nothing else reads them.
marker = name: pkgs.runCommand "auth-marker-${name}" { } "mkdir $out";
# The all-local host with the k3s node on, and the controller's TCP listener
# that a controller in the cluster needs and the one on the host serves as
# well. It does not set `k8s.enable`: the node turns the rendering on.
k8sNodeSettings = {
# The all-local host: every swarm service in its cluster, which the mode turns
# on, and the controller's TCP listener that the controller's pod is reached
# through.
allLocalSettings = {
deploy.singleHostSwarm = true;
deploy.k8s.enable = true;
deploy.k8s.address = "192.168.1.10";
deploy.k8s.nodeAddresses = [
"192.168.1.11"
"192.168.1.12"
];
deploy.victorialogs.authPackage = marker "logs";
deploy.victorialogs.grafanaAuthPackage = marker "logs-grafana";
deploy.victoriametrics.authPackage = marker "metrics";
deploy.victoriametrics.agentAuthPackage = marker "metrics-agent";
swarm.controller.tcp = {
enable = true;
domain = "controller.t.local";
};
};
allLocal = hiveWithController allLocalSettings;
in
{
agentBare = agent { };
@ -61,18 +63,10 @@ in
bareWithController = hiveWithController { };
# With the k8s manifests rendered too, which changes no unit.
allLocal = hiveWithController {
deploy.singleHostSwarm = true;
k8s.enable = true;
deploy.victorialogs.authPackage = marker "logs";
deploy.victorialogs.grafanaAuthPackage = marker "logs-grafana";
deploy.victoriametrics.authPackage = marker "metrics";
deploy.victoriametrics.agentAuthPackage = marker "metrics-agent";
};
inherit allLocal;
inherit k8sNodeSettings;
k8sNode = hiveWithController k8sNodeSettings;
k8sNodeSettings = allLocalSettings;
k8sNode = allLocal;
autheliaOnly = hive { deploy.authelia.enable = true; };

View file

@ -119,13 +119,16 @@ let
dest = "mirrors/tool";
};
hyperhiveElsewhere = "https://example.invalid/hyperhive";
# A store path: the controller's pod mounts no host path, and carries the files
# its unit names from the store.
markerAvatar = pkgs.writeText "marker-avatar.png" "marker";
controllerWithMirrors = hiveWithController {
deploy.swarm-controller.enable = true;
deploy.forgejo.enable = true;
deploy.forgejo.mirrors = [ aMirror ];
deploy.forgejo.actionsFromSelf = false;
deploy.forgejo.hyperhiveUpstream = null;
deploy.swarm-controller.configOrgAvatarPng = "/etc/marker-avatar.png";
deploy.swarm-controller.configOrgAvatarPng = markerAvatar;
};
mirrorsNoController = hive {
deploy.forgejo.enable = true;
@ -198,13 +201,8 @@ let
"swarm-bao"
"swarm-builder"
"swarm-ci-runner"
"swarm-claude-login"
"swarm-grafana"
"swarm-nats"
"swarm-notify-router"
"swarm-otel"
"swarm-review-classifier"
"swarm-stt"
"swarm-victorialogs"
"swarm-victoriametrics"
];
@ -265,7 +263,6 @@ let
"forgejo.service"
"gitea-runner-swarm.service"
"grafana.service"
"nats.service"
"opentelemetry-collector.service"
"tuwunel.service"
"victorialogs.service"
@ -345,12 +342,14 @@ let
lib.length (lib.attrNames es) == 8 && lib.all lib.id (lib.attrValues es);
}
{
# The container is the control that the toggle reaches the module, not
# only the option; `nats` is the control that the switch is on at all.
name = "hosting the swarm's shared services turns on the review classifier";
# The pod runs it, so no container: the unit is the control that the toggle
# reaches the module, not only the option; `nats` is the control that the
# switch is on at all.
name = "hosting the swarm's shared services turns on the review classifier as a pod";
ok =
swarmServicesHere.services.hyperhive.deploy.review-classifier.enable
&& swarmServicesHere.containers ? swarm-review-classifier
&& swarmServicesHere.services.hyperhive.deploy.review-classifier.unit.serviceConfig ? ExecStart
&& !(swarmServicesHere.containers ? swarm-review-classifier)
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
}
{
@ -392,16 +391,14 @@ let
&& swarmServicesBaoElsewhere.services.hyperhive.deploy.nats.enable;
}
{
# Static, not `DynamicUser`: the user is declared in the container and
# the unit names it. `nats` is the control that the switch is on at all.
name = "hosting the swarm's shared services runs the claude login minter in its container as a static user";
# Static, not `DynamicUser`: the unit names the user. `nats` is the control
# that the switch is on at all.
name = "hosting the swarm's shared services runs the claude login minter as a static user";
ok =
let
c = swarmServicesHere.containers.swarm-claude-login.config;
sc = c.systemd.services.swarm-claude-login.serviceConfig;
sc = swarmServicesHere.services.hyperhive.deploy.claude-login.unit.serviceConfig;
in
swarmServicesHere.services.hyperhive.deploy.claude-login.enable
&& c.users.users.swarm-claude-login.isSystemUser
&& sc.User == "swarm-claude-login"
&& !(sc.DynamicUser or false)
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
@ -416,16 +413,14 @@ let
&& swarmServicesBaoElsewhere.services.hyperhive.deploy.nats.enable;
}
{
# Same shape as the minter's: a static user in its own container. `nats`
# is the control that the switch is on at all.
name = "hosting the swarm's shared services runs the notification router in its container as a static user";
# Same shape as the minter's: a static user. `nats` is the control that
# the switch is on at all.
name = "hosting the swarm's shared services runs the notification router as a static user";
ok =
let
c = swarmServicesHere.containers.swarm-notify-router.config;
sc = c.systemd.services.swarm-notify-router.serviceConfig;
sc = swarmServicesHere.services.hyperhive.deploy.notify-router.unit.serviceConfig;
in
swarmServicesHere.services.hyperhive.deploy.notify-router.enable
&& c.users.users.swarm-notify-router.isSystemUser
&& sc.User == "swarm-notify-router"
&& !(sc.DynamicUser or false)
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
@ -434,11 +429,10 @@ let
name = "hosting the swarm's shared services runs the speech-to-text service as an unprivileged user under a sandbox";
ok =
let
c = swarmServicesHere.containers.swarm-stt.config;
sc = c.systemd.services.swarm-stt.serviceConfig;
unit = swarmServicesHere.services.hyperhive.deploy.stt.unit;
sc = unit.serviceConfig;
in
swarmServicesHere.services.hyperhive.deploy.stt.enable
&& c.users.users.swarm-stt.isSystemUser
&& sc.User == "swarm-stt"
&& !(sc.DynamicUser or false)
&& sc.NoNewPrivileges
@ -447,7 +441,7 @@ let
&& sc.CapabilityBoundingSet == ""
&& sc.MemoryMax == "3G"
&& sc.StateDirectory == "swarm-stt"
&& c.systemd.services.swarm-stt.environment.SWARM_STT_MAX_WAITING == "3";
&& unit.environment.SWARM_STT_MAX_WAITING == "3";
}
{
# dhcpcd without IPv4LL, waiting for IPv4: `network-online` is a lease.
@ -466,11 +460,8 @@ let
lib.hasInfix "noipv4ll" d.extraConfig && d.wait == "ipv4";
fetch = (cfgOf "swarm-builder").systemd.services.swarm-journal-forwarder-oidc;
in
leased "swarm-notify-router"
&& leased "swarm-authelia"
leased "swarm-authelia"
&& lib.hasInfix "nohook resolv.conf" (cfgOf "swarm-authelia").networking.dhcpcd.extraConfig
&& !(lib.hasInfix "noipv4ll" (cfgOf "swarm-nats").networking.dhcpcd.extraConfig)
&& (cfgOf "swarm-nats").networking.dhcpcd.wait == "any"
&& lib.elem "network-online.target" fetch.after
&& lib.elem "network-online.target" fetch.wants;
}
@ -506,8 +497,8 @@ let
ok =
let
claudeOf =
host: container: unit: var:
host.containers.${container}.config.systemd.services.${unit}.environment.${var};
host: service: var:
host.services.hyperhive.deploy.${service}.unit.environment.${var};
pinned = "${pkgs.hello}/bin/claude";
servedClaude =
host:
@ -517,18 +508,13 @@ let
in
servedClaude swarmServicesPinnedClaude == "${pkgs.hello}"
&& servedClaude swarmServicesHere == null
&&
claudeOf swarmServicesPinnedClaude "swarm-claude-login" "swarm-claude-login"
"SWARM_CLAUDE_LOGIN_CLAUDE" == pinned
&&
claudeOf swarmServicesPinnedClaude "swarm-review-classifier" "swarm-review-classifier"
"SWARM_REVIEW_CLASSIFIER_CLAUDE" == pinned
&& claudeOf swarmServicesPinnedClaude "claude-login" "SWARM_CLAUDE_LOGIN_CLAUDE" == pinned
&& claudeOf swarmServicesPinnedClaude "review-classifier" "SWARM_REVIEW_CLASSIFIER_CLAUDE" == pinned
&& lib.hasInfix "claude-code" (
claudeOf swarmServicesHere "swarm-claude-login" "swarm-claude-login" "SWARM_CLAUDE_LOGIN_CLAUDE"
claudeOf swarmServicesHere "claude-login" "SWARM_CLAUDE_LOGIN_CLAUDE"
)
&& lib.hasInfix "claude-code" (
claudeOf swarmServicesHere "swarm-review-classifier" "swarm-review-classifier"
"SWARM_REVIEW_CLASSIFIER_CLAUDE"
claudeOf swarmServicesHere "review-classifier" "SWARM_REVIEW_CLASSIFIER_CLAUDE"
);
}
{
@ -789,7 +775,6 @@ let
"swarm-victorialogs"
"swarm-victoriametrics"
"swarm-otel"
"swarm-nats"
"hive-matrix"
"hive-forge"
]
@ -836,7 +821,7 @@ let
# that lost a container can't pass by comparing fewer of them.
name = "every service container restates its host-side privateNetwork";
ok =
lib.length (lib.attrNames serviceContainers) == 16
lib.length (lib.attrNames serviceContainers) == 11
&& lib.all (
c: c.privateNetwork == (c.config.services.hyperhive.swarmContainer.privateNetwork or null)
) (lib.attrValues serviceContainers);
@ -850,7 +835,7 @@ let
let
shared = lib.filter (c: !c.privateNetwork) (lib.attrValues serviceContainers);
in
lib.length shared == 2
lib.length shared == 1
&& lib.all (
c: !c.config.networking.firewall.enable && !c.config.networking.resolvconf.enable
) shared;
@ -1555,7 +1540,7 @@ let
name = "the org avatar lands on the controller's unit, not hive-c0re's";
ok =
controllerWithMirrors.systemd.services.swarm-controller.environment.SWARM_CONTROLLER_CONFIG_ORG_AVATAR_PNG
== "/etc/marker-avatar.png"
== "${markerAvatar}"
&& !(controllerWithMirrors.systemd.services.hive-c0re.environment ? HIVE_ORG_AVATAR_PNG);
}
{
@ -1583,7 +1568,6 @@ let
"swarm-bao-grafana-metrics-bearer"
"swarm-bao-grafana-secret-key"
"swarm-bao-grafana-controller-token"
"swarm-bao-nats-callout-xkey"
"swarm-bao-ci-runner"
"swarm-bao-otel-oidc"
];
@ -1607,9 +1591,9 @@ let
!(lib.any (n: lib.elem n (s.after ++ s.wants ++ s.requires)) storeUnits);
in
lib.all waits readers
&& lib.length readersHere == 10
&& lib.length readersHere == 9
&& lib.elem "swarm-bao-grafana-admin" readersHere
&& lib.length readersElsewhere == 8
&& lib.length readersElsewhere == 7
&& lib.all namesNoStoreUnit readersElsewhere
&& !(lib.any (u: storeOnlyNoHive.systemd.services ? ${u}) readers);
}