Watch
0
0
Fork
You've already forked hyperhive
0

docs: the controller's runtime, hostPort hop, listener leaf, state and rev rollout

This commit is contained in:
atlas 2026-11-22 12:42:49 +01:00 • committed by maia
commit e7334ad98e
5 changed files with 114 additions and 16 deletions

View file

@ -115,8 +115,17 @@ credential directory.
stay on the host: the pod has the security shape above and no other.
- **Probes:** a service with an opt-in health listener gets its variable set to
`0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` serves
`/readyz` on its unix socket only, so it has no probes yet.
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` is one of
them, with `SWARM_CONTROLLER_HEALTH_ADDR`.
- **Listener and init container:** a service with a TCP `listener`
(`swarm-controller`, with `swarm.controller.tcp.enable`) publishes its port on
the node's address with a `hostPort`, and gets an init container and a
renewal container that issue its leaf into an `emptyDir`
([runtime](runtime.md#the-controller)). The image of those containers is part
of `system.build.k8sImages`.
- **Config checksum:** a Deployment whose service has a ConfigMap (`etcFiles`)
carries `checksum/etc` on its pod template, the hash of that ConfigMap's
content, so a changed file rolls the pod.
- **Shutdown:** `terminationGracePeriodSeconds` is 15, the 10-second drain a
daemon allows itself after SIGTERM (`DRAIN` in
`swarm-secret-client/src/shutdown.rs`) plus headroom.
@ -154,7 +163,7 @@ store's side.
provider) by the same names as the units do. The node's CoreDNS answers those
names with the hive bridge's address.
- `swarm-controller`'s socket lives in an `emptyDir`, so only the pod can
reach it.
reach it. The gateway dials the TCP listener instead.
## Validation

View file

@ -6,9 +6,9 @@ is `"host"` (the default) or `"k8s"`. The service runs once per swarm, so the
option moves it and never copies it: the host unit and the pod never run
together, because they would share one queue consumer and one set of buckets,
or two cursors that push every CI run twice. `swarm-notify-router`,
`swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier` and
`swarm-claude-login` have the option today, and the other services that run in
the cluster follow the same pattern.
`swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier`,
`swarm-claude-login` and `swarm-controller` have the option today, and the
other services that run in the cluster follow the same pattern.
## Options
@ -20,6 +20,12 @@ the cluster follow the same pattern.
`services.hyperhive.deploy.review-classifier.runtime` and
`services.hyperhive.deploy.claude-login.runtime` (default `"host"`), with the
same rule.
- `services.hyperhive.deploy.swarm-controller.runtime` (default `"host"`), with
the same rule. It also needs
`services.hyperhive.swarm.controller.tcp.enable`, and
`deploy.swarm-controller.tcp.listenAddress` at its default `0.0.0.0`: the
evaluation fails without either. [The controller](#the-controller) has its
own section.
With `"host"`, a host without [the cluster node](node.md) renders the same
configuration as before the option existed. With the node on and every service
@ -31,7 +37,10 @@ on `"host"`, the cluster holds no service objects.
(`swarm-notify-router`, `swarm-stt`, `swarm-review-classifier`,
`swarm-claude-login`), no credential hand-ins for it and no journal forwarder
for it. `swarm-ci-metrics` has no container: its service, its timer and the
CA bundle unit of its service go.
CA bundle unit of its service go. `swarm-controller` has no container
either: the host turns `swarm-controller.service` off, so nothing can start
it, and defines no `swarm-controller-tls.service` or timer. The evaluated
unit stays the source of the Deployment.
- **The service's objects go in.** The [rendered manifests](manifests.md) reach
the cluster through `services.k3s.manifests`, one file per service plus the
namespace. The cluster applies a file when its link appears in the manifests
@ -46,9 +55,13 @@ on `"host"`, the cluster holds no service objects.
- `trust-bundle.pem`: the hive's trust bundle, where the gateway is
self-signed;
- `bao-server-ca.pem`: the secret store's server CA
(`deploy.bao.serverCaFile`).
(`deploy.bao.serverCaFile`);
- `hive-client-ca.pem` and `swarm-services-root.pem`, with the controller in
the cluster: the authority the controller writes into each hive's store role
(`deploy.swarm-controller.hiveClientCaFile`), and the store's services root
that its listener trusts the gateway's client leaf by.
Both are public certificates. The unit waits for the cluster and for the
All are public certificates. The unit waits for the cluster and for the
files, and a pod that mounts the ConfigMap waits in `ContainerCreating` until
the unit has run. A path unit watches both files and runs the unit again when
either changes, with no manual step. A running pod doesn't see a changed
@ -109,6 +122,63 @@ with none pushes every run again, as the same points. A second Job on the same
side finds the cursor and pushes nothing. The claim stays after a switch back,
and so does the host's directory.
## The controller
`swarm-controller` runs once per swarm, and nothing in the daemon guards that: a
second copy would send the operator admin grants and revokes again, split the
review requests the queue holds, and write the same keys. The runtime switch is
the whole guard on one node: the Deployment has one replica and the `Recreate`
strategy, and the prune unit holds the host unit back until the pod has gone. No
leader lock exists, so a cluster of more than one node needs one before the
controller may move there.
- **The gateway's hop.** The host can't reach a unix socket inside a pod, so
the pod serves the TCP listener, and publishes it with a `hostPort` on
`deploy.swarm-controller.tcp.hostAddress`. That address is the hive bridge's
by default, the one the pods already reach the host's services on. The
listener binds `0.0.0.0` inside the pod (`tcp.listenAddress`, which the
evaluation holds there). The gateway's `/api/` and `/webhook/forge/`
locations dial the node's address and port, and verify the listener's
certificate as `swarm.controller.tcp.domain` (`proxy_ssl_name`,
`proxy_ssl_verify`). With the controller on the host the locations dial the
name. A `hostPort` reaches one node: a cluster of more than one node needs a
Service instead.
- **The listener's leaf.** The pod issues its own, from the store's
`swarm-controller-tls` role, with the same script as
`swarm-controller-tls.service`. An init container logs in with the pod's
ServiceAccount token (the `swarm-controller` role of the `jwt-k8s` mount,
whose policy holds the one issue path) and writes the leaf and its key into
an `emptyDir` before the daemon starts. The `emptyDir` is in memory
(`medium: Memory`), so the key never reaches a Secret or the node's disk. A
second container, `tls-renew`, runs the script again every day, and again
after ten minutes when the store refused. The script leaves a leaf alone
while it's in the first half of its lifetime, as the host's daily timer
does, and the daemon reads the new files with no restart. A sidecar renews
because nothing rolls the pod before the leaf expires. Both containers run
an image of their own, `swarm-controller-tls`, which holds the store client
and the script's tools.
- **`swarmctl`.** The controller's socket lives inside the pod, so the host's
`swarmctl` reaches the controller only through the gateway: run
`swarmctl login` once, then use `--swarm <url>` or a wrapper that defaults
to it. A socket path on the host serves nothing under `runtime = "k8s"`.
- **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on
`/healthz` and readiness on `/readyz`. Readiness needs the queue connection
and a fresh store login, so a store role that refuses the pod's token leaves
it NotReady.
- **State.** `/var/lib/swarm-controller` is the PersistentVolumeClaim
`swarm-controller-state`. It starts empty, and nothing here copies the host's
directory into it ([migrate](migrate.md) does). An empty claim holds no
`operator-matrix-admins.json`, which reads as an empty set: the controller
revokes nobody, and an account removed from the operator group before the
copy keeps its homeserver admin. The webhook secret is in the store, so it
survives.
- **The rev.** The unit's rev file, `/etc/hyperhive/swarm-controller.json`, is a
`subPath` mount of the `swarm-controller-etc` ConfigMap, which a running pod
never sees change. The Deployment's pod template carries `checksum/etc`, a
hash of the ConfigMap's content, so a new rev rolls the pod. The host unit
re-reads the file with no restart, so this restart, which drops the job graph,
is new.
## Resources and sandbox
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
@ -193,3 +263,14 @@ pod's root takes no writes, so a write outside the `/tmp` volume fails, and
that `claude` with `HOME` in the volume writes its config there, as the
minter's real login step does, while `claude` with `HOME` on the root leaves
nothing there.
The VM test `k8s-controller-switch` moves the controller. It asserts one copy at
each step by the switch's own timestamps and by a sampler, that the pod is Ready
on `/readyz` with the `hostPort` and the volumes the module renders and no
Secret, that its listener's leaf is the one its init container issued, valid as
the listener's name against the hive's root, that the volume holding its key is
a tmpfs, and that the listener refuses a client with no leaf. It runs the
gateway's own controller location, from the module's text for each runtime,
against the host unit and the pod: both answer an unsigned webhook 401. A
changed rev rolls the Deployment onto a new pod and keeps the state volume, and
the switch back deletes the pod and its AddOn before the unit starts.

View file

@ -19,10 +19,13 @@ unit's value.
The collector stamps the hive's `hive` label on what it forwards, as it does for
agents. The pods run on that hive's node.
A swarm-tier producer keeps its own route. `swarm-ci-metrics` is one: its poller
reads `SWARM_CI_METRICS_OTLP_ENDPOINT`, which names its route of the swarm
collector, `https://<swarm.otel.domain>/swarm-ci-metrics`, and it mints the
bearer that route checks itself on each pass. The renderer sets nothing for such
A swarm-tier producer keeps its own route. `swarm-ci-metrics` and
`swarm-controller` are two. The controller's unit sets
`OTEL_EXPORTER_OTLP_ENDPOINT` to its route of the swarm collector and mints its
own bearer, so its pod keeps that value. The poller reads
`SWARM_CI_METRICS_OTLP_ENDPOINT`, which names its route of the swarm collector,
`https://<swarm.otel.domain>/swarm-ci-metrics`, and it mints the bearer that
route checks itself on each pass. The renderer sets nothing for such
a service (`otlp = "own"` in its entry of `render.nix`), because a series that
went through the hive collector would carry the `hive` label, and a swarm-level
series must not. The render refuses a service marked `"own"` whose unit names

View file

@ -530,6 +530,12 @@ What you provide:
on another host dials it. The port (`swarm.controller.tcp.port`, default 9443) stays closed
until you do, and `deploy.swarm-controller.tcp.listenAddress` picks the bound address.
With `deploy.swarm-controller.runtime = "k8s"` the listener is the pod's `hostPort`. The gateway
dials `deploy.swarm-controller.tcp.hostAddress` (the hive bridge's address by default) at the
same port, and still verifies the certificate as `swarm.controller.tcp.domain`, so that name
needs no address of its own. The pod issues its server leaf itself
([`runtime.md`](../k8s/runtime.md#the-controller)).
What you don't: both certificates come from the secret store with no manual step
([`ca.md`](ca.md#the-controllers-tcp-listener-has-two-leaves-of-its-own)). The listener accepts
the gateway's client certificate and nothing else, so reaching the port gets a stranger a refused

View file

@ -154,7 +154,7 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
| queue auth-callout nkeys (user seed + account seed) | `swarm-nats-auth ensure-callout-keys`, run by `swarm-bao-nats-callout-xkey` on the queue's host when the store holds no seed; the verb stores a seed it finds at `/var/lib/swarm-nats-callout/{callout-user,issuer}.seed` as is, then removes the file | the swarm secret store: the seeds at `swarm/services/swarm-nats/callout/{user,issuer}-seed`, read by the `swarm-nats-auth` role alone; the public halves at `swarm/public/swarm-nats/callout-{user,issuer}` | nothing to place beyond the responder's store leaf (`deploy.nats.authBaoClientCertFile`) |
| queue auth-callout xkey (curve seed) | `swarm-nats-auth ensure-callout-keys`, run by `swarm-bao-nats-callout-xkey` on the queue's host when the store holds no seed | the swarm secret store: the seed at `swarm/services/swarm-nats/callout/xkey-seed`, read by the `swarm-nats-auth` role alone; the public half at `swarm/public/swarm-nats/callout-xkey` | nothing to place beyond the responder's store leaf (`deploy.nats.authBaoClientCertFile`) |
| the queue's TLS key, copied for the gateway's `/metrics` vhost | `swarm-nats-gateway-cert.service` on the queue's host, where the gateway uses self-signed TLS: a copy of the queue's bao-PKI TLS leaf (`/var/lib/swarm-nats-tls/`) once `swarm-bao-nats-tls` has issued it, else a throwaway 30-day self-signed pair for the queue's name until then | `/var/lib/swarm-nats-gateway-tls/{cert,key}.pem`; the key is `0640` group `nginx`, read by nginx for the queue's `/metrics` vhost. The queue's own key stays `0600` root | the copy is redone on each leaf renewal (`swarm-bao-nats-tls` starts the unit, which queues a non-blocking nginx reload when nginx is running); a restart before any leaf exists keeps the pair already there. Until `swarm-bao-nats-tls` issues the leaf the vhost serves the throwaway cert, so the collector's scrape fails TLS. Nothing for an operator to place |
| the controller's TCP listener certificate and key | `swarm-controller-tls.service` on the controller's host, only where you set `swarm.controller.tcp.enable`. It logs in under the controller's own store leaf and issues from the store's `swarm-controller-tls` role: one name, `swarm.controller.tcp.domain`, `serverAuth` only. A daily timer renews it past half its life | `<deploy.swarm-controller.tcp.tlsDir>/{cert,key}.pem` (`/var/lib/swarm-controller-tls`), the key `0640` group `swarm-controller`; the daemon re-reads both when they change, so a rotation restarts nothing. A store host that leaves the option off has no role to issue from, and the unit fails with the store's refusal naming it | Nothing to place: the controller's own store leaf is the one it already holds |
| the controller's TCP listener certificate and key | `swarm-controller-tls.service` on the controller's host, only where you set `swarm.controller.tcp.enable`. It logs in under the controller's own store leaf and issues from the store's `swarm-controller-tls` role: one name, `swarm.controller.tcp.domain`, `serverAuth` only. On the host, a daily timer renews it past half its life. With `deploy.swarm-controller.runtime = "k8s"` the host has no unit: the pod's init container issues the leaf into an in-memory `emptyDir` under its ServiceAccount token, and its `tls-renew` container repeats the same check daily, because nothing rolls the pod before the leaf expires | On the host, `<deploy.swarm-controller.tcp.tlsDir>/{cert,key}.pem` (`/var/lib/swarm-controller-tls`), the key `0640` group `swarm-controller`. In the pod, the same two files in an in-memory `emptyDir` (`medium: Memory`), gone with the pod. The daemon re-reads both when they change, so a rotation restarts nothing. A store host that leaves the option off has no role to issue from, and the unit fails with the store's refusal naming it | Nothing to place: the controller's own store leaf is the one it already holds |
| the gateway's client certificate for the controller's TCP listener | `swarm-controller-gateway-client.service` on the host that runs the controller, only where you set `swarm.controller.tcp.enable`. It logs in under the services-issuer identity and issues from the store's `swarm-controller-gateway-client` role: one name, `gateway-client.<swarm.domain>`, `clientAuth` only, so the services leaf can't stand in for it. A daily timer renews it | `<deploy.hive-controller.tls.stateDir>/controller-client.pem` and `controller-client-key.pem`, the key `0640` group `nginx`; the gateway's controller locations name them in `proxy_ssl_certificate`. Until the store answers, a throwaway self-signed pair keeps nginx's config loadable. The listener refuses that pair, so those locations answer 502. Every holder of the services-issuer identity can obtain this leaf: the listener trusts "a gateway of this swarm" | Nothing to place: the services-issuer identity is the one every gateway host already holds |
| the secret store's own contents | openbao, on first `bao operator init` — **an operator action, not a unit** | inside the `swarm-bao` container, at its own `/var/lib/openbao`, kept across rebuilds by `ephemeral = false`. ⚠️ **Not a host path**: `nixos-container destroy swarm-bao` takes the raft data with it, so back up the container's tree, not `/var/lib/`. Only the store's TLS material (`/var/lib/swarm-bao-tls`) and its PKCS11 token (`/var/lib/swarm-bao-token`) are host-level | n/a — there is one store; a hive elsewhere is a _client_ of it and holds none of this |
| the secret store's unseal material | the HSM/TPM under `deploy.bao.seal = "pkcs11"`; openbao itself under `"shamir"` | in the token; or held by whoever ran `bao operator init`, which is what `"shamir"` means and why it's stated rather than inferred | n/a — only the host running the store seals anything |