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 maia
commit 2e1f037f25
51 changed files with 1044 additions and 3125 deletions

View file

@ -57,9 +57,9 @@ jobs:
- k8s-node - k8s-node
- k8s-collector-switch - k8s-collector-switch
- k8s-bao-login - k8s-bao-login
- k8s-runtime-switch - k8s-services
- k8s-controller-switch - k8s-controller
- k8s-nats-switch - k8s-nats
- k8s-join - k8s-join
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View file

@ -59,9 +59,9 @@ guessed value here is a wrong hostname that evaluates cleanly and deploys.
An all-local swarm, with every shared service and the hive on this one box, An all-local swarm, with every shared service and the hive on this one box,
adds one switch: adds one switch:
| option | what it does | | option | what it does |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `deploy.singleHostSwarm` | Turns on the shared swarm services, the swarm controller, and `/etc/hosts` entries so the swarm's names resolve on the box itself. Leave it off if the services run on other hosts. | | `deploy.singleHostSwarm` | Turns on the shared swarm services, the swarm controller, the cluster they run in, and `/etc/hosts` entries so the swarm's names resolve on the box itself. Leave it off if the services run on other hosts. |
The smallest working config, as in the README's The smallest working config, as in the README's
[all-local quick start](../../README.md#quick-start-an-all-local-swarm): [all-local quick start](../../README.md#quick-start-an-all-local-swarm):

View file

@ -29,6 +29,14 @@ the host's `/etc/hosts` entries for the names it serves
(`deploy.bao.bootstrapTokenFile`). You can still set each derived toggle on (`deploy.bao.bootstrapTokenFile`). You can still set each derived toggle on
its own, and that setting wins. its own, and that setting wins.
The notification router, speech-to-text service, CI run poller, review
classifier, claude login minter, queue and controller run as pods in a single-node
k3s cluster on that host, so `deploy.k8s.enable` defaults on wherever the host
enables one of them, and setting it to `false` there fails the evaluation. The
controller's TLS listener, the gateway's way in, is on by default and named
`controller.<swarm.domain>`. See
[the cluster node](../../4-implementation/k8s/node.md).
**Both default to off**, because a host can't tell whether it's meant to be **Both default to off**, because a host can't tell whether it's meant to be
the swarm's service host. With them off, a hive is a _client_ of those the swarm's service host. With them off, a hive is a _client_ of those
services: it configures how to reach them and runs none of them. services: it configures how to reach them and runs none of them.
@ -213,18 +221,16 @@ and [`builder.md`](../../4-implementation/swarm/builder.md#binary-cache).
### CI metrics ### CI metrics
The CI run poller, a `swarm-ci-metrics` timer unit on the host that sets The CI run poller, a CronJob in the host's cluster on the host that sets
`deploy.ci-metrics.enable`; set it to `false` to opt out. With `deploy.ci-metrics.enable`; set it to `false` to opt out. Every
`deploy.ci-metrics.runtime = "k8s"` it runs as a CronJob in the host's cluster. Every
five minutes it pushes the run time and queue wait of each newly finished forge Actions run to five minutes it pushes the run time and queue wait of each newly finished forge Actions run to
the metrics store. What it reads and pushes: the metrics store. What it reads and pushes:
[`ci-metrics.md`](../../4-implementation/swarm/ci-metrics.md). [`ci-metrics.md`](../../4-implementation/swarm/ci-metrics.md).
### Review classifier ### Review classifier
The review classifier's try-out service, in a `swarm-review-classifier` The review classifier's try-out service, a pod in the host's cluster on the host
container on the host that sets `deploy.review-classifier.enable`, or as a pod in the that sets `deploy.review-classifier.enable`. You set the
host's cluster with `deploy.review-classifier.runtime = "k8s"`. You set the
key for the runtime the swarm settings choose in the swarm UI: the **classifier key for the runtime the swarm settings choose in the swarm UI: the **classifier
settings** card on `/jobs` takes a key for that runtime and shows whether one settings** card on `/jobs` takes a key for that runtime and shows whether one
exists and when it changed, never the key. "Set" means a key exists, not that it exists and when it changed, never the key. "Set" means a key exists, not that it
@ -237,9 +243,8 @@ The store paths for the two keys, and what a run is and costs:
### Claude login minter ### Claude login minter
The claude login minter, in a `swarm-claude-login` container on the host that The claude login minter, a pod in the host's cluster on the host that sets
sets `deploy.claude-login.enable`, or as a pod in the host's cluster with `deploy.claude-login.enable`. Run one: a login in progress lives in the
`deploy.claude-login.runtime = "k8s"`. Run one: a login in progress lives in the
service's memory between its start and its code. An operator logs an agent in service's memory between its start and its code. An operator logs an agent in
from the **log in** button on its card in the swarm UI, and the agent's from the **log in** button on its card in the swarm UI, and the agent's
harness installs the new login. The flow and the version rule: harness installs the new login. The flow and the version rule:
@ -248,21 +253,18 @@ harness installs the new login. The flow and the version rule:
### Notification router ### Notification router
The notification router, in a `swarm-notify-router` container on the host that The notification router, a pod in the host's cluster on the host that sets
sets `deploy.notify-router.enable`. Run one: it handles each issue's events in `deploy.notify-router.enable`. Run one: it handles each issue's events in
order. It turns forge events (assigning an issue or pull request, closing it, a order. It turns forge events (assigning an issue or pull request, closing it, a
failed CI run on a pull request) into todos for the agents they concern, and an failed CI run on a pull request) into todos for the agents they concern, and an
agent that's down gets its todos when it's back. Set agent that's down gets its todos when it's back. The flows and the delivery path:
`deploy.notify-router.runtime = "k8s"` to run it as a pod in the host's cluster
instead of the container. The flows and the delivery path:
[`notify-router.md`](../../4-implementation/swarm/notify-router.md), and [`notify-router.md`](../../4-implementation/swarm/notify-router.md), and
[Host setup](../../4-implementation/swarm/notify-router.md#host-setup). [Host setup](../../4-implementation/swarm/notify-router.md#host-setup).
### Speech to text ### Speech to text
The speech-to-text service, in a `swarm-stt` container on the host that sets The speech-to-text service, a pod in the host's cluster on the host that sets
`deploy.stt.enable`, or as a pod in the host's cluster with `deploy.stt.enable`. Run it where the inference hardware is: it
`deploy.stt.runtime = "k8s"`. Run it where the inference hardware is: it
transcribes with whisper.cpp. An agent that receives a voice memo sends the transcribes with whisper.cpp. An agent that receives a voice memo sends the
audio to it over the queue and gets the text back, and a memo sent to several audio to it over the queue and gets the text back, and a memo sent to several
agents costs one run. `deploy.stt.settings.modelSize` picks the model (`small` agents costs one run. `deploy.stt.settings.modelSize` picks the model (`small`

View file

@ -6,8 +6,8 @@ the systemd unit each service runs today. A host with
`services.hyperhive.k8s.enable` gets them as `system.build.k8sManifests`, a `services.hyperhive.k8s.enable` gets them as `system.build.k8sManifests`, a
directory with one YAML file per object, and the images their pods run as directory with one YAML file per object, and the images their pods run as
`system.build.k8sImages`, which [the cluster node](node.md) loads. Rendering `system.build.k8sImages`, which [the cluster node](node.md) loads. Rendering
changes no unit. [The runtime switch](runtime.md) applies a service's manifests changes no unit. [The runtime module](runtime.md) applies a service's manifests
to the cluster, when the service's `runtime` says `"k8s"`. to the cluster, and the service runs there and nowhere else.
## Options ## Options
@ -81,7 +81,7 @@ A credential that holds a public CA file isn't a secret. `swarm-notify-router`'s
the ConfigMap `hyperhive-ca-trust`, key `bao-server-ca.pem`, and the trust the ConfigMap `hyperhive-ca-trust`, key `bao-server-ca.pem`, and the trust
bundles from the key `trust-bundle.pem`. bundles from the key `trust-bundle.pem`.
The manifests only name the ConfigMap, because the hive CA exists only at The manifests only name the ConfigMap, because the hive CA exists only at
runtime. [The runtime switch](runtime.md#what-k8s-changes) publishes it from the runtime. [The runtime module](runtime.md#what-the-cluster-runs) publishes it from the
host's files. A service with both kinds of credential gets one host's files. A service with both kinds of credential gets one
projected volume that merges the Secret's keys and the ConfigMap's into the projected volume that merges the Secret's keys and the ConfigMap's into the
credential directory. credential directory.
@ -125,9 +125,9 @@ credential directory.
on the hive bridge's address, one TCP port per host service the entry names: on the hive bridge's address, one TCP port per host service the entry names:
the store's pod listener (`store`), the gateway's 443 for the identity the store's pod listener (`store`), the gateway's 443 for the identity
provider (`identity`), the queue's port (`queue`) and the hive collector's provider (`identity`), the queue's port (`queue`) and the hive collector's
(`collector`). Where the queue runs in the cluster, its pod on its port is (`collector`). The policy allows its pod on the queue's port too. The node trusts
allowed too. The node trusts the pod network's interfaces, so without the the pod network's interfaces, so without the policy a pod reaches every port of
policy a pod reaches every port of the host. A service without `egress` has no the host. A service without `egress` has no
policy. policy.
- **Probes:** a service with an opt-in health listener gets its variable set to - **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` `0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
@ -171,7 +171,7 @@ Services, and the queue's client port is a `LoadBalancer` Service that k3s's
service load balancer binds on the node from `kube-system`, which the label service load balancer binds on the node from `kube-system`, which the label
doesn't cover. The level follows the cluster's Kubernetes version, so an doesn't cover. The level follows the cluster's Kubernetes version, so an
upgrade can tighten it. `module-eval-k8s` reads every rendered pod against the upgrade can tighten it. `module-eval-k8s` reads every rendered pod against the
level's rules, and the VM test `k8s-controller-switch` shows the API server level's rules, and the VM test `k8s-controller` shows the API server
refusing a pod with a host port, a kept capability or privilege. refusing a pod with a host port, a kept capability or privilege.
## The store login ## The store login

View file

@ -1,11 +1,14 @@
# The cluster node # The cluster node
`services.hyperhive.deploy.k8s.enable` (default `false`) makes the host run a `services.hyperhive.deploy.k8s.enable` makes the host run the main node of a k3s
k3s server for the swarm services that run in the cluster. It's the Kubernetes cluster for the swarm services that run in the cluster. It defaults on where the
counterpart of `services.hyperhive.deploy.singleHostSwarm`: set it on the host host enables one of them (`deploy.notify-router`, `stt`, `ci-metrics`,
that runs the swarm's services, and the cluster comes up with the service `review-classifier`, `claude-login`, `nats` or `swarm-controller`), which
images loaded and no service's objects applied. Other machines can `services.hyperhive.deploy.singleHostSwarm` and
[join it](#joining-nodes) and run the services' pods; hyperhive runs no `services.hyperhive.deploy.allSwarmServices` do, so the all-local host gets the
cluster with its services in it and no option set. Setting it to `false` on such
a host fails the evaluation, naming the option and the services. Other machines
can [join it](#joining-nodes) and run the services' pods; hyperhive runs no
cluster of its own beyond that one main node, and it replicates no service. cluster of its own beyond that one main node, and it replicates no service.
## What the host gets ## What the host gets
@ -43,11 +46,12 @@ cluster of its own beyond that one main node, and it replicates no service.
## What it leaves alone ## What it leaves alone
The cluster starts with no hyperhive workload. Each service keeps running as The cluster holds the workload of the swarm services the host enables, and no
its systemd unit, and nothing applies the services' manifests: two copies of other: [the runtime module](runtime.md) applies their manifests, and each runs
`swarm-notify-router`, `swarm-ci-metrics` or `swarm-controller` would share one there and nowhere else, because two copies of `swarm-notify-router`,
queue consumer, one cursor or one swarm. A service's objects go into the `swarm-ci-metrics` or `swarm-controller` would share one queue consumer, one
cluster when its `runtime` is `"k8s"` ([the runtime switch](runtime.md)). cursor or one swarm. A host that enables none has a cluster with no hyperhive
workload.
With the option off, the host's configuration is the one it has without the With the option off, the host's configuration is the one it has without the
module. module.
@ -59,8 +63,8 @@ says so with a label. The module sets the labels
(`services.hyperhive.deploy.k8s.nodeLabels`, passed to `services.k3s.nodeLabel`): (`services.hyperhive.deploy.k8s.nodeLabels`, passed to `services.k3s.nodeLabel`):
- `hyperhive.darkest.space/state-<service>=true`, one per service whose data - `hyperhive.darkest.space/state-<service>=true`, one per service whose data
the cluster keeps. Today that's `nats`, when `deploy.nats.runtime` is the cluster keeps. Today that's `nats`, when `deploy.nats.enable` is on, and `ci-metrics`, when
`"k8s"`, and `ci-metrics`, when `deploy.ci-metrics.runtime` is `"k8s"`. The `deploy.ci-metrics.enable` is on. The
service's static local volume has a `nodeAffinity` on the label, and its pod a service's static local volume has a `nodeAffinity` on the label, and its pod a
`nodeSelector` on it, so a node without the label can't run the pod and shows `nodeSelector` on it, so a node without the label can't run the pod and shows
as no match instead of a volume that can't bind. One label per service, so as no match instead of a volume that can't bind. One label per service, so
@ -257,7 +261,7 @@ once more.
### Turning the node on for a swarm that already runs ### Turning the node on for a swarm that already runs
The first activation with `deploy.k8s.enable` restarts the store's container, The first activation with the node on restarts the store's container,
`container@swarm-bao`. The node adds a `pod` listener to the store's `container@swarm-bao`. The node adds a `pod` listener to the store's
configuration, and a changed container configuration restarts the container. configuration, and a changed container configuration restarts the container.
What comes next depends on the store's seal: What comes next depends on the store's seal:

View file

@ -1,78 +1,90 @@
# Where a service runs: the runtime switch # Where a service runs: the cluster
A swarm service with a `runtime` option runs in one of two places: as its host The swarm services that have a pod run in the host's cluster and nowhere else:
unit, or as a pod in the host's cluster. `services.hyperhive.deploy.<service>.runtime` `swarm-notify-router`, `swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier`,
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`,
`swarm-claude-login`, `swarm-controller` and the queue with its auth callout `swarm-claude-login`, `swarm-controller` and the queue with its auth callout
(`swarm-nats`) have the option today, and the other services that run in the (`swarm-nats`). Each runs once per swarm, because two copies would share one
cluster follow the same pattern. queue consumer and one set of buckets, or two cursors that push every CI run
twice. A host that enables one gets [the cluster node](node.md) with it: no
option moves a service between the host and the cluster, and the host has no
unit or container to move it back to. The secret store, the forge, authelia, the
gateway, `swarm-builder`, `swarm-matrix-ctl` and every hive stay on the host.
## Moving a service ## The node comes with the services
To move a service into the cluster, set its `runtime` to `"k8s"` and rebuild. `services.hyperhive.deploy.k8s.enable` defaults on where the host enables any
To move it back, set `runtime` back to `"host"` and rebuild. of `deploy.notify-router`, `stt`, `ci-metrics`, `review-classifier`,
No command copies data, and a move loses nothing a service holds. `claude-login`, `nats` or `swarm-controller`. `deploy.singleHostSwarm` and
The queue keeps its host store: the pod mounts the directory the container's unit uses, so a switch moves the process and not the bytes. `deploy.allSwarmServices` enable them, so an all-local host gets the node and
The controller and the other services hold nothing a move loses; [State](#state) lists what each one keeps. every service in the cluster with no further option. A host that sets
Hives and agents keep the queue's URL, port, certificate name and auth callout, so no hive needs a rebuild. `deploy.k8s.enable = false` while it enables one fails at evaluation, and the
The secret store, the forge, authelia, the gateway, `swarm-builder`, `swarm-matrix-ctl` and every hive stay on the host. message names the option and the services.
## Options Some services need more of the host, and the evaluation names the option each
time it's missing:
- `services.hyperhive.deploy.notify-router.runtime` (default `"host"`). - `swarm-controller` needs `services.hyperhive.swarm.domain`, which names its
`"k8s"` needs `services.hyperhive.deploy.k8s.enable` on the same host, and the TLS listener (`swarm.controller.tcp.domain`, `controller.<swarm.domain>` by
evaluation fails without it. default) and turns the listener on (`swarm.controller.tcp.enable`, on by
- `services.hyperhive.deploy.stt.runtime`, default): the host can't reach a unix socket inside a pod, so the gateway dials
`services.hyperhive.deploy.ci-metrics.runtime`, the listener. A setting that can't work fails the evaluation: the listener off,
`services.hyperhive.deploy.review-classifier.runtime` and `deploy.swarm-controller.tcp.listenAddress` other than its default `0.0.0.0` (the
`services.hyperhive.deploy.claude-login.runtime` (default `"host"`), with the bind inside the pod), or `services.hyperhive.gateway.dns.enable` off, because the
same rule. hive's resolver hands the cluster's domain to CoreDNS.
- `services.hyperhive.deploy.swarm-controller.runtime` (default `"host"`), with - `nats` needs `services.hyperhive.gateway.dns.enable` too, and the iptables
the same rule. It also needs firewall (`networking.nftables.enable` off).
`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.
- `services.hyperhive.deploy.nats.runtime` (default `"host"`), with the same
rule. One switch covers the queue's server and its auth callout. It needs
the iptables firewall (`networking.nftables.enable` off).
[The queue](#the-queue) has its own section.
With `"host"`, a host without [the cluster node](node.md) renders the same ## Upgrading
configuration as before the option existed. With the node on and every service
on `"host"`, the cluster holds no service objects.
## What `"k8s"` changes An upgrade from a host that ran a service as its host unit or container is one
`nixos-rebuild switch`, with nothing to do beforehand and no copy of data.
- **The host unit goes.** The configuration has no container for the service `switch-to-configuration` stops every unit the new configuration drops, and waits
(`swarm-notify-router`, `swarm-stt`, `swarm-review-classifier`, for each stop, before it runs the activation that links the manifests into the
`swarm-claude-login`), no credential hand-ins for it and no journal forwarder cluster's manifests directory (`switch-to-configuration-ng`'s `main.rs` sends the stop jobs for the removed
for it. `swarm-ci-metrics` has no container: its service, its timer and the units, waits for them, and then runs the activation script). The cluster applies a manifest when its
CA bundle unit of its service go. `swarm-controller` has no container link appears, so the old copy of each service has stopped before its pod can start.
either: the host turns `swarm-controller.service` off, so nothing can start A removed container is a drop-in of the `container@` template, which the same
it, and defines no `swarm-controller-tls.service` or timer. The evaluated code treats as removed when no drop-in remains. Nothing else keeps the copies
unit stays the source of the Deployment. apart.
- **The service's objects go in.** The [rendered manifests](manifests.md) reach
the cluster through `services.k3s.manifests`, one file per service plus the The data stays where it was:
- The queue's pod mounts `/var/lib/nixos-containers/swarm-nats/var/lib/nats`, the
directory the container's server used, as a static local volume
([State](#state)).
- The poller's cursor is `/var/lib/private/swarm-ci-metrics`, mounted the same
way.
- The other services keep nothing a move has to carry.
The pods log in to the store with their ServiceAccount tokens, so the store's
`jwt-k8s` auth mount has to be there before they can. The first switch that turns
the node on restarts the store, so [unseal it](node.md) before the pods log in.
No way back to the host unit exists: the options that chose it have gone, and so
have the units. To leave the cluster, switch to an older generation.
## What the cluster runs
- **The service's objects.** 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 namespace. The cluster applies a file when its link appears in the manifests
directory. directory.
- **The pod reads the unit the container ran.** The unit comes from the - **The unit the pod comes from.** Each service module still defines the
container's own configuration, evaluated on its own when the host has no systemd unit, and the renderer reads the pod's environment, credential ids and
container, so the pod's environment is the unit's environment either way. limits from it. The host doesn't run the unit: the module evaluates it on its
The poller has no container: the renderer evaluates its service and timer on own for the services that had a container, and defines
their own when the host doesn't run them, and the CronJob follows that timer. `swarm-controller.service` with `enable = false`. The module evaluates the
poller's service and timer on their own too, and the CronJob follows the
timer.
- **The host publishes the CA files.** `hyperhive-k8s-ca-trust.service` applies - **The host publishes the CA files.** `hyperhive-k8s-ca-trust.service` applies
the `hyperhive-ca-trust` ConfigMap from the host's files, with no manual step: the `hyperhive-ca-trust` ConfigMap from the host's files, with no manual step:
- `trust-bundle.pem`: the hive's trust bundle, where the gateway is - `trust-bundle.pem`: the hive's trust bundle, where the gateway is
self-signed; self-signed;
- `bao-server-ca.pem`: the secret store's server CA - `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 - `hive-client-ca.pem` and `swarm-services-root.pem`, for the controller: the
the cluster: the authority the controller writes into each hive's store role authority the controller writes into each hive's store role
(`deploy.swarm-controller.hiveClientCaFile`), and the store's services root (`deploy.swarm-controller.hiveClientCaFile`), and the store's services root
that its listener trusts the gateway's client leaf by. that its listener trusts the gateway's client leaf by.
@ -83,68 +95,31 @@ on `"host"`, the cluster holds no service objects.
trust bundle until it restarts, because the kubelet doesn't update `subPath` trust bundle until it restarts, because the kubelet doesn't update `subPath`
mounts. mounts.
## One copy at a time
`switch-to-configuration` stops every unit the new configuration drops, and waits
for each stop, before it activates the new configuration. The activation links
the manifests. Switching to `"k8s"` therefore stops the container before the
cluster can apply the pod.
The cluster doesn't delete what a manifest created after the manifest goes away,
and it keeps the file's link in its manifests directory. Switching back to
`"host"` therefore needs a step of its own. `<service>-k8s-prune.service` belongs
to every configuration that has the node and the service on `"host"`, and each
of the service's host units requires it and starts after it. The poller has
two, its timer and its service, so a pass started by hand can't run beside a
Job:
1. If the manifest's link exists, rename it to `<service>.yaml.pruning`, so the
cluster doesn't apply it again. The rename also records what remains to
delete. With no link, nothing went in, so the unit does nothing and needs no
cluster.
2. Wait for the cluster's API, then delete the service's Deployment, CronJob,
Service, NetworkPolicy and ServiceAccount (selected by
`app.kubernetes.io/name`), and wait until its pods have gone. A pod exits 0
within its termination grace period. Then wait until the pods that the
service load balancer bound the service's Services' ports with, in
`kube-system`, have gone too: the rule that forwards a port to one stays
until the pod does.
3. Delete the cluster's AddOn for the file, so that a later switch to `"k8s"`
applies the same manifest again. Then remove the renamed link.
A failed step fails the unit, and the host unit doesn't start: the service stays
down and never doubles. A rerun resumes from the renamed link. Persistent volume
claims stay until the operator deletes them.
## State ## State
No pod starts behind a gate that checks its state volume: a service keeps No pod starts behind a gate that checks its state volume: a service keeps
nothing a switch has to copy. Each service's state is below. nothing an upgrade has to copy. Each service's state is below.
`swarm-notify-router`, `swarm-review-classifier` and `swarm-claude-login` have `swarm-notify-router`, `swarm-review-classifier` and `swarm-claude-login` have
no volume. no volume.
`swarm-notify-router` keeps nothing on the host. Its durable consumer on the `swarm-notify-router` keeps nothing on the host. Its durable consumer on the
forge events stream and its `notify-router-state` bucket live in the queue, so a forge events stream and its `notify-router-state` bucket live in the queue, so an
switch in either direction copies nothing, and the router continues from the upgrade copies nothing, and the router continues from the consumer's position.
consumer's position.
`swarm-stt` keeps a transcript cache, which lives 24 hours. On the host the `swarm-stt` keeps a transcript cache, which lives 24 hours. It sits in an `emptyDir` at `/var/lib/swarm-stt`, so the pod has no claim and
cache sits in the container's `/var/lib/swarm-stt`. In the cluster it sits in an starts on an empty cache on every start of the pod; an upgrade from the
`emptyDir` at the same path, so the pod has no claim and starts on an empty container doesn't carry the old cache over. The whisper model isn't state: the
cache on every start of the pod. A switch copies nothing, and the service pod's image holds it.
transcribes a memo that only the other side cached. The whisper model isn't
state: the pod's image holds it, from the same store path the container reads.
`swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers `swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers
already pushed. On the host it sits in the service's state directory, already pushed. It sits in the PersistentVolumeClaim `swarm-ci-metrics-store`, mounted at
`/var/lib/private/swarm-ci-metrics`. In the cluster it sits in the `/var/lib/private/swarm-ci-metrics`, which binds a static local volume on that
PersistentVolumeClaim `swarm-ci-metrics-store`, mounted at the same path, which host directory, the service's old state directory. An upgrade moves the process
binds a static local volume on that host directory. A switch moves the process
and not the cursor. The volume's `nodeAffinity` and the pod's `nodeSelector` and not the cursor. The volume's `nodeAffinity` and the pod's `nodeSelector`
both name the node label `hyperhive.darkest.space/state-ci-metrics` both name the node label `hyperhive.darkest.space/state-ci-metrics`
([node labels](node.md#node-labels)). The module makes the directory on a host ([node labels](node.md#node-labels)). The module makes the directory on a host
that never ran the service, because the volume needs it before the first Job. that never ran the service, because the volume needs it before the first Job.
The claim and its volume stay after a switch back, with the directory. The claim and its volume stay until the operator deletes them, with the directory.
A host that ran the poller in the cluster before the volume was static has the A host that ran the poller in the cluster before the volume was static has the
claim `swarm-ci-metrics-state` on the cluster's default class. A bound claim's claim `swarm-ci-metrics-state` on the cluster's default class. A bound claim's
@ -157,11 +132,10 @@ points.
`swarm-controller` runs once per swarm, and nothing in the daemon guards that: a `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 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 review requests the queue holds, and write the same keys. On one node the guard is
the whole guard on one node: the Deployment has one replica and the `Recreate` the Deployment: one replica and the `Recreate` strategy, and the removed host
strategy, and the prune unit holds the host unit back until the pod has gone. No unit stops before the pod can start. No leader lock exists, so a cluster
leader lock exists, so a cluster of more than one node needs one before the of more than one node needs one before the controller may run there.
controller may move there.
- **The gateway's hop.** The host can't reach a unix socket inside a pod, so - **The gateway's hop.** The host can't reach a unix socket inside a pod, so
the pod serves the TCP listener, and a ClusterIP Service, the pod serves the TCP listener, and a ClusterIP Service,
@ -183,8 +157,7 @@ controller may move there.
pod does. A Service works on a cluster of more than one node, but the pod does. A Service works on a cluster of more than one node, but the
controller's Deployment still has the one replica. controller's Deployment still has the one replica.
- **The listener's leaf.** The pod issues its own, from the store's - **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` role. An init container logs in with the pod's
`swarm-controller-tls.service`. An init container logs in with the pod's
ServiceAccount token (the `swarm-controller` role of the `jwt-k8s` mount, 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 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 an `emptyDir` before the daemon starts. The `emptyDir` is in memory
@ -199,7 +172,7 @@ controller may move there.
- **`swarmctl`.** The controller's socket lives inside the pod, so the host's - **`swarmctl`.** The controller's socket lives inside the pod, so the host's
`swarmctl` reaches the controller only through the gateway: run `swarmctl` reaches the controller only through the gateway: run
`swarmctl login` once, then use `--swarm <url>` or a wrapper that defaults `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"`. to it. A socket path on the host serves nothing.
- **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on - **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on
`/healthz` and readiness on `/readyz`. Readiness needs the queue connection `/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 and a fresh store login, so a store role that refuses the pod's token leaves
@ -208,24 +181,21 @@ controller may move there.
operator Matrix admin grants is in the queue's key-value store, so the pod operator Matrix admin grants is in the queue's key-value store, so the pod
revokes the accounts the host controller granted. What the directory holds revokes the accounts the host controller granted. What the directory holds
starts again from nothing: the forge avatar markers and the legacy webhook starts again from nothing: the forge avatar markers and the legacy webhook
secret, which the secret store also holds. The controller's first start on secret, which the secret store also holds. A legacy grant file on the host is
the host imports a legacy grant file into the store, so run it there once not imported.
before the switch.
- **The rev.** The unit's rev file, `/etc/hyperhive/swarm-controller.json`, is a - **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 `subPath` mount of the `swarm-controller-etc` ConfigMap, which a running pod
never sees change. The Deployment's pod template carries `checksum/etc`, a 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 hash of the ConfigMap's content, so a new rev rolls the pod, which drops the
re-reads the file with no restart, so this restart, which drops the job graph, job graph.
is new.
## The queue ## The queue
`swarm-nats` is the swarm's message queue: the NATS server and the `swarm-nats` is the swarm's message queue: the NATS server and the
auth-callout responder that admits its clients. Both belong to one pod, auth-callout responder that admits its clients. Both belong to one pod,
because a server whose responder is down refuses every connect. A switch because a server whose responder is down refuses every connect. Two servers
moves the two together, and two servers or two responders never run: the or two responders never run: the Deployment has one replica and the `Recreate`
Deployment has one replica and the `Recreate` strategy, and the prune unit strategy, and the removed container stops before the pod can start.
holds the container back until the pod has gone.
- **Containers.** The responder is the pod's main container, `swarm-nats`, - **Containers.** The responder is the pod's main container, `swarm-nats`,
rendered from the unit the container runs, as the other daemons are. Beside it rendered from the unit the container runs, as the other daemons are. Beside it
@ -288,32 +258,29 @@ holds the container back until the pod has gone.
network-facing server sees the responder's and `tls-renew`'s processes, and network-facing server sees the responder's and `tls-renew`'s processes, and
under the same user can read their `/proc/<pid>/environ` and under the same user can read their `/proc/<pid>/environ` and
`/proc/<pid>/root`. The container had the same exposure, as one container. `/proc/<pid>/root`. The container had the same exposure, as one container.
- **The host's units.** `swarm-nats-auth-secrets` and - **The host's units.** The host has no unit that delivers keys or secrets to the
`swarm-bao-nats-callout-xkey` deliver into the container, so the configuration queue. `swarm-bao-nats-tls` stays: it issues the host's own copy of the leaf
turns them off. `swarm-bao-nats-tls` stays: it issues the host's own copy of for the gateway's `/metrics` vhost, and restarts no server. The gateway's location dials the exporter's Service by
the leaf for the gateway's `/metrics` vhost, and with no container it has
nothing to restart. The gateway's location dials the exporter's Service by
name where it dialled loopback. name where it dialled loopback.
- **State.** The server's store directory, `/var/lib/nats`, is the container's - **State.** The server's store directory, `/var/lib/nats`, is the container's
own on the host, `/var/lib/nixos-containers/swarm-nats/var/lib/nats`: the own on the host, `/var/lib/nixos-containers/swarm-nats/var/lib/nats`: the
PersistentVolumeClaim `swarm-nats-store` binds a static local volume on it, PersistentVolumeClaim `swarm-nats-store` binds a static local volume on it,
so a switch moves the process and not the bytes, and the pod has no state so an upgrade moves the process and not the bytes, and the pod has no state
gate. The container's unit runs `chown -R nats:nats` on the directory before gate. The pod's `fsGroup` gives its group read and write; files the old
the server starts, and the pod's `fsGroup` gives its group read and write. container wrote stay owned by the server's old user.
The volume is `local`, with a storage class of its own and the `Retain` The volume is `local`, with a storage class of its own and the `Retain`
policy, and the claim binds it by name. Its `nodeAffinity` and the pod's policy, and the claim binds it by name. Its `nodeAffinity` and the pod's
`nodeSelector` both name the node label `nodeSelector` both name the node label
`hyperhive.darkest.space/state-nats`, so the pod and the directory stay on the `hyperhive.darkest.space/state-nats`, so the pod and the directory stay on the
node that carries it ([node labels](node.md#node-labels)). node that carries it ([node labels](node.md#node-labels)).
The prune unit stops a pod before the container starts, and the Deployment The Deployment replaces its pod rather than running two, so one server reads
replaces its pod rather than running two, so one server reads the directory the directory at a time.
at a time.
nats-server keeps no lock or identity file in the store, so nothing there ties nats-server keeps no lock or identity file in the store, so nothing there ties
the directory to the side that wrote it. the directory to the side that wrote it.
The module makes the directory on a host that never ran the container, The module makes the directory on a host that never ran the container,
because the volume needs it before the pod starts. because the volume needs it before the pod starts.
The claim and its volume stay after a switch back, as every claim does, with The claim and its volume stay until the operator deletes them, as every claim
the directory. does, with the directory.
- **Readiness.** The pod is Ready when the responder's `/readyz`, on the pod's - **Readiness.** The pod is Ready when the responder's `/readyz`, on the pod's
port 8080, passes and the server's exec probe does. The probe runs port 8080, passes and the server's exec probe does. The probe runs
`wget` against `/healthz?js-enabled-only=true` on the server's monitor, which `wget` against `/healthz?js-enabled-only=true` on the server's monitor, which
@ -340,14 +307,14 @@ systemd sandbox (`MemoryDenyWriteExecute`, `SystemCallFilter`, the read-only
`ProtectSystem` and the rest) stays on the host, and `PrivateUsers` is the pod's `ProtectSystem` and the rest) stays on the host, and `PrivateUsers` is the pod's
own user namespace (`hostUsers: false`). The pod is a non-root user with a own user namespace (`hostUsers: false`). The pod is a non-root user with a
read-only root filesystem, every capability dropped, the runtime's default read-only root filesystem, every capability dropped, the runtime's default
seccomp profile and no API token. The host unit doesn't restrict the network. seccomp profile and no API token.
The pod has a NetworkPolicy (`swarm-stt`, rendered with the pod): it may reach The pod has a NetworkPolicy (`swarm-stt`, rendered with the pod): it may reach
cluster DNS, and on the node's bridge address the store's pod listener, the cluster DNS, and on the node's bridge address the store's pod listener, the
identity provider, the queue and the hive collector, each on its one port. It identity provider, the queue and the hive collector, each on its one port. It
admits no ingress. The kubelet's probes still reach the pod, because the node's admits no ingress. The kubelet's probes still reach the pod, because the node's
own traffic to a pod is always admitted, and the pod doesn't serve anything own traffic to a pod is always admitted, and the pod doesn't serve anything
else: requests reach it as queue messages, over the connection it opens. Where else: requests reach it as queue messages, over the connection it opens. The
the queue runs in the cluster, the policy also allows the pods of the queue's policy also allows the pods of the queue's
load balancer, in `kube-system`, on the queue's port, because the node forwards load balancer, in `kube-system`, on the queue's port, because the node forwards
the `hostPort` they bind to them before the policy sees the packet. the `hostPort` they bind to them before the policy sees the packet.
@ -357,15 +324,15 @@ The pod of `swarm-ci-metrics` keeps pushing to its route of the swarm
collector, `https://<swarm.otel.domain>/swarm-ci-metrics`, with the bearer it collector, `https://<swarm.otel.domain>/swarm-ci-metrics`, with the bearer it
mints for itself each pass. The renderer sets no hive collector endpoint for it mints for itself each pass. The renderer sets no hive collector endpoint for it
([telemetry](telemetry.md#metrics)). The pod holds no client certificate, so it ([telemetry](telemetry.md#metrics)). The pod holds no client certificate, so it
doesn't push the `bao.client_cert.*` gauges of the host unit. Its one credential pushes no `bao.client_cert.*` gauges. Its one credential
file is the store's CA, `bao-ca.pem`, which comes from the `hyperhive-ca-trust` file is the store's CA, `bao-ca.pem`, which comes from the `hyperhive-ca-trust`
ConfigMap. The pod has no Secret volume, and no `swarm-ci-metrics-credentials` ConfigMap. The pod has no Secret volume, and no `swarm-ci-metrics-credentials`
Secret exists, because nothing creates it. Secret exists, because nothing creates it.
## The claude daemons ## The claude daemons
`swarm-review-classifier` and `swarm-claude-login` keep no state, so a switch `swarm-review-classifier` and `swarm-claude-login` keep no state, so the
moves nothing and the renderer adds no volume. Their units set no limits, so their renderer adds no volume. Their units set no limits, so their
pods have none. Both run `claude`, which the daemon starts with `HOME` set to a pods have none. Both run `claude`, which the daemon starts with `HOME` set to a
scratch directory under the system's temporary directory (the classifier also scratch directory under the system's temporary directory (the classifier also
starts `opencode` that way). The pod's root filesystem takes no writes, and its starts `opencode` that way). The pod's root filesystem takes no writes, and its
@ -394,60 +361,52 @@ forwards.
## Validation ## Validation
`module-eval-k8s` checks that the host render with `"host"` holds the container, `module-eval-k8s` checks that the all-local host runs every service as a pod and
no cluster manifests and no CA objects, and that `swarm-stt`'s container and none as a container, unit or timer; that the node defaults on through the
unit are as the module defines them, and likewise for the review classifier and the claude all-local mode and through one toggle, and an explicit `false` stays false; that a
login minter. With `"k8s"` it checks that no container host with the node off and a service on fails with a message naming the option
remains, that the manifests sit in `services.k3s.manifests`, and that the and the services; that a controller without the TCP listener, the pod's bind
evaluation refuses `"k8s"` without the node, and that the poller's pod keeps address or the hive's resolver fails the evaluation; that the manifests sit in
the swarm route its unit names, where every other pod gets the hive collector, `services.k3s.manifests`; and that the poller's pod keeps the swarm route its unit
and mounts no Secret. The VM test `k8s-runtime-switch` runs a router, the names, where every other pod gets the hive collector, and mounts no Secret.
speech-to-text service, the CI run poller, the review classifier and the claude
login minter against the real secret store and a queue. It switches all five
from the host to the cluster and back, checks each step for exactly one copy of
each, and asserts that the router's pod logs in, routes an event, and exits 0
when deleted. For `swarm-stt` it asserts that the pod is Ready, logged in to
the store with its ServiceAccount token, carries the unit's limits, requests
nothing and is Burstable, and has its cache volume bound. For
`swarm-ci-metrics` it asserts that the host has no timer or service on the
cluster side, and that the cluster has no CronJob, Job or pod on the host side
before the timer starts. A Job completes against a forge stub that lists one run
and pushes it to the poller's own route with a bearer the identity provider
stub minted. The pod holds no Secret and binds its cursor volume, and a second
Job, and a Job after a round trip through the host, push nothing. The host's
own pass against the same stubs is the control. For the two claude daemons it
asserts that each pod is Ready and logged in with its token, that the minter's
token writes an agent's credentials and the classifier's token can't, that the
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-nats-switch` moves the queue against the real secret store, The VM test `k8s-services` runs a router, the speech-to-text service, the CI run
with the egress intercept on. A sampler counts servers and responders every poller, the review classifier and the claude login minter against the real
200 ms and sees at most one of each, and the container and the pod never secret store and a queue. It asserts that the host has no container, unit, timer
together. The pod is Ready by its exec probe and has the init containers, the or prune unit for any of them, and that each pod is Ready, logged in to the
volumes and the Services the module renders and no `hostPort`, and its leaf's store with its ServiceAccount token, and minted a token with the client secret
volume is a tmpfs. The load balancer binds the client port from `kube-system` it read. The router's pod routes an event, and a pod deleted exits 0 within its
and the Service has no node port. A client on the bridge reaches the queue by grace period. For `swarm-stt` it asserts that the pod carries the unit's limits,
name and through the published port only, not by the pod's address or the requests nothing and is Burstable, runs in a user namespace, and keeps its cache
node's, and a second node outside the node reaches the control port and not the in an `emptyDir`; its NetworkPolicy lets a queue request in and only DNS and four
queue's, as with the container; with `openFirewall` it dials the pod by name and host ports out. A Job of the poller completes against a forge stub that lists one
verifies the name, and the responder in the pod admits it. A key written on the run and pushes it to the poller's own route with a bearer the identity provider
host before the switch is the pod's to read, a key the pod writes is the host stub minted; the pod holds no Secret and binds its cursor volume, and a second
server's after the switch back, and a stream written before a pod delete Job pushes nothing. For the two claude daemons it asserts that the minter's
survives it: the replacement pod reads it from the same directory. The exporter token writes an agent's credentials and the classifier's can't, that the pod's
answers the host's own processes through its Service and no pod or bridge root takes no writes, and that `claude` with `HOME` in the volume writes its
client, and the switch back removes the pod and the load balancer's pod before config there while `claude` with `HOME` on the root leaves nothing there.
the container starts.
The VM test `k8s-controller-switch` moves the controller. It asserts one copy at The VM test `k8s-nats` runs the queue against the real secret store, with the
each step by the switch's own timestamps and by a sampler, that the pod is Ready egress intercept on. The pod is Ready by its exec probe and has the init
on `/readyz` with the volumes the module renders and no Secret, that its containers, the volumes and the Services the module renders and no `hostPort`,
listener's leaf is the one its init container issued, valid as the listener's and its leaf's volume is a tmpfs. The load balancer binds the client port from
name against the hive's root, that the volume holding its key is a tmpfs, and `kube-system` and the Service has no node port. A client on the bridge reaches
that the listener refuses a client with no leaf. It runs the gateway's own the queue by name and through the published port only, not by the pod's address
controller location, from the module's text for each runtime, against the host or the node's, and a second node outside the node reaches the control port and
unit and the pod: both answer an unsigned webhook 401. A changed rev rolls the not the queue's; with `openFirewall` it dials the pod by name and verifies the
Deployment onto a new pod and keeps the state volume, and the switch back name, and the responder in the pod admits it. The pod's volume is the host's
deletes the pod and its AddOn before the unit starts. store directory, a stream written before a pod delete survives it, and the
exporter answers the host's own processes through its Service and no pod or
bridge client.
The VM test `k8s-controller` runs the controller. It asserts that the host has
no unit for it, its listener leaf or a prune, that the pod is Ready on
`/readyz` with 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, against the pod: it answers an unsigned
webhook 401. A changed rev rolls the Deployment onto a new pod.
`k8s-bao-login` and `k8s-node` check the store's login and the node.

View file

@ -19,7 +19,7 @@ You rarely switch it on yourself. `gateway.enable` defaults to off, and every mo
| `chat.<swarm>/_matrix/*` | tuwunel (unix socket `/run/hive-matrix/tuwunel.sock`) | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` | | `chat.<swarm>/_matrix/*` | tuwunel (unix socket `/run/hive-matrix/tuwunel.sock`) | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` |
| `chat.<swarm>/` | fluffychat-web static | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` | | `chat.<swarm>/` | fluffychat-web static | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` |
| `chat.<swarm>/config.json` | inline JSON (FluffyChat boot config) | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` | | `chat.<swarm>/config.json` | inline JSON (FluffyChat boot config) | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` |
| `<queue domain>/metrics` | the queue exporter's `/metrics` on loopback, or behind its Service where the queue runs in the cluster, behind an authelia `auth_request`; every other path, `/` included, returns `403`, so `/varz` and `/connz` are never reachable | `swarm-nats.nix`, the queue's host | | `<queue domain>/metrics` | the queue exporter's `/metrics` behind its Service, behind an authelia `auth_request`; every other path, `/` included, returns `403`, so `/varz` and `/connz` are never reachable | `swarm-nats.nix`, the queue's host |
| `grafana.<swarm>`, `metrics.<swarm>`, `logs.<swarm>`, `otel.<swarm>`, `bao.<swarm>` | the matching swarm service | that service's module → [`2-handbook/swarm/services.md`](../../2-handbook/swarm/services.md) | | `grafana.<swarm>`, `metrics.<swarm>`, `logs.<swarm>`, `otel.<swarm>`, `bao.<swarm>` | the matching swarm service | that service's module → [`2-handbook/swarm/services.md`](../../2-handbook/swarm/services.md) |
A service module declares its vhost as `services.hyperhive.gateway.vhosts.<name>`: the locations, `forceSSL` and any `extraConfig` it needs. The gateway renders it into `services.nginx.virtualHosts.<name>` and adds the `listen` set ([listen addresses](#listen-addresses)), the certificate for that name and the [security headers](#security-headers) (ahead of the vhost's own `extraConfig`), and drops `addSSL` from a vhost that sets `forceSSL`. The eval fails for a vhost that sets `listen`, `addSSL`, `onlySSL`, `enableACME`, `useACMEHost`, `sslCertificate` or `sslCertificateKey` itself, and for any vhost declared while `gateway.enable` is false. A name with a certificate from outside the gateway's leaves (the queue's) sets `certificate = { cert; key; }` instead. `hive-gateway/vhosts.nix` declares the gateway's own catch-all (`_`) the same way, `hive-c0re/vhosts.nix` the dashboard and the hive domain, and `glue-matrix-hive-discovery.nix` adds the matrix redirect to the hive domain where the homeserver runs, and discovery there when the hive domain is the pinned server name. The catch-all sets `securityHeaders = false` because it sends no response, and the gateway renders a vhost's `default` at `mkDefault` priority. A service module declares its vhost as `services.hyperhive.gateway.vhosts.<name>`: the locations, `forceSSL` and any `extraConfig` it needs. The gateway renders it into `services.nginx.virtualHosts.<name>` and adds the `listen` set ([listen addresses](#listen-addresses)), the certificate for that name and the [security headers](#security-headers) (ahead of the vhost's own `extraConfig`), and drops `addSSL` from a vhost that sets `forceSSL`. The eval fails for a vhost that sets `listen`, `addSSL`, `onlySSL`, `enableACME`, `useACMEHost`, `sslCertificate` or `sslCertificateKey` itself, and for any vhost declared while `gateway.enable` is false. A name with a certificate from outside the gateway's leaves (the queue's) sets `certificate = { cert; key; }` instead. `hive-gateway/vhosts.nix` declares the gateway's own catch-all (`_`) the same way, `hive-c0re/vhosts.nix` the dashboard and the hive domain, and `glue-matrix-hive-discovery.nix` adds the matrix redirect to the hive domain where the homeserver runs, and discovery there when the hive domain is the pinned server name. The catch-all sets `securityHeaders = false` because it sends no response, and the gateway renders a vhost's `default` at `mkDefault` priority.

View file

@ -208,14 +208,15 @@ list-timers swarm-services-cert-renew` shows the next run.
## The controller's TCP listener has two leaves of its own ## The controller's TCP listener has two leaves of its own
`swarm.controller.tcp.enable` adds a TLS listener to the swarm controller (default off). The The swarm controller runs a TLS listener (`swarm.controller.tcp.enable`, on by default). The
controller checks nobody per request, so the listener finishes a handshake for one client only: controller checks nobody per request, so the listener finishes a handshake for one client only:
the gateway. Both ends hold a leaf from the store's `pki` mount, each through a role of its own on the gateway. Both ends hold a leaf from the store's `pki` mount, each through a role of its own on
the same mount and the same root: the same mount and the same root:
- **Server leaf.** The `swarm-controller-tls` role issues for `swarm.controller.tcp.domain` alone, - **Server leaf.** The `swarm-controller-tls` role issues for `swarm.controller.tcp.domain` alone,
`serverAuth` only. `swarm-controller-tls.service` on the controller's host requests it under the `serverAuth` only. The pod's `tls-issue` init container requests it with its
controller's own store leaf, whose policy gains that one issue path. ServiceAccount token, through the `swarm-controller` jwt role, whose policy has
that one issue path.
- **Gateway client leaf.** The `swarm-controller-gateway-client` role issues for - **Gateway client leaf.** The `swarm-controller-gateway-client` role issues for
`gateway-client.<swarm.domain>` alone, `clientAuth` only. `swarm-controller-gateway-client.service` `gateway-client.<swarm.domain>` alone, `clientAuth` only. `swarm-controller-gateway-client.service`
on the host that runs the controller requests it under the services-issuer identity, whose policy on the host that runs the controller requests it under the services-issuer identity, whose policy
@ -229,9 +230,9 @@ handshake. Nginx verifies the controller's server leaf against the trust bundle,
Every host that holds the services-issuer identity can obtain the gateway client leaf, which is Every host that holds the services-issuer identity can obtain the gateway client leaf, which is
every gateway host. The controller trusts exactly that identity: a gateway of this swarm. every gateway host. The controller trusts exactly that identity: a gateway of this swarm.
Set `swarm.controller.tcp.enable` and `swarm.controller.tcp.domain` identically on every host. The Leave `swarm.controller.tcp.enable` and `swarm.controller.tcp.domain` at their defaults, or set them identically on every host. The
store's host writes both roles from them. A store host that leaves the option off has no role, and store's host writes both roles from them. A store host that turns the option off has no role, and
the issuing unit fails with the store's refusal naming it. the pod's init container fails with the store's refusal naming it.
The listener reads the services root once at start. Replacing the root (about 30 years out) needs a The listener reads the services root once at start. Replacing the root (about 30 years out) needs a
controller restart as well as new leaves. controller restart as well as new leaves.

View file

@ -7,7 +7,7 @@ to a repo's first run.
## Where it runs ## Where it runs
A oneshot `swarm-ci-metrics.service` on a 5-minute timer, on the host that sets A CronJob in the host's cluster on a 5-minute schedule, on the host that sets
`deploy.ci-metrics.enable`. `allSwarmServices` defaults it on wherever the host `deploy.ci-metrics.enable`. `allSwarmServices` defaults it on wherever the host
has the poller's store identity, which the host that runs the store has. Run it has the poller's store identity, which the host that runs the store has. Run it
on one host per swarm: each poller keeps its own cursor, so two of them push on one host per swarm: each poller keeps its own cursor, so two of them push
@ -27,10 +27,9 @@ with `invalid peer certificate: UnknownIssuer`.
### In the cluster ### In the cluster
With `deploy.ci-metrics.runtime = "k8s"` (and `deploy.k8s.enable`) the host has The host has neither the service nor the timer, and the poller is a CronJob in
neither the service nor the timer, and the poller is a CronJob in the host's the host's cluster, on the timer's interval ([the runtime module](../k8s/runtime.md)).
cluster, on the timer's interval. A switch moves the poller, so one runs at any The pod differs from the unit in
time ([the runtime switch](../k8s/runtime.md)). The pod differs from the unit in
three places: three places:
- It pushes to the same route of the swarm collector, with the bearer it mints - It pushes to the same route of the swarm collector, with the bearer it mints
@ -110,8 +109,8 @@ store then holds the same point twice in the same series, which changes no
panel. Deleting the file re-runs the backfill the same way. panel. Deleting the file re-runs the backfill the same way.
A failed repo leaves its cursor where it was, the pass goes on with the next A failed repo leaves its cursor where it was, the pass goes on with the next
repo, and the unit fails, so `systemctl status swarm-ci-metrics` shows it. The repo, and the Job fails, so `kubectl -n hyperhive get jobs` shows it. The
timer runs it again 5 minutes later. CronJob runs it again 5 minutes later.
## The board ## The board
@ -126,8 +125,8 @@ variable:
## Host setup ## Host setup
The CI run poller, a `swarm-ci-metrics` oneshot on a 5-minute timer on the host The CI run poller, a CronJob on a 5-minute schedule in the cluster of the host
that sets `deploy.ci-metrics.enable`. It runs on the host, not in a container. that sets `deploy.ci-metrics.enable`.
`allSwarmServices` defaults it on wherever the host has the poller's store `allSwarmServices` defaults it on wherever the host has the poller's store
identity, as for the other swarm services. Set `deploy.ci-metrics.enable = false` to identity, as for the other swarm services. Set `deploy.ci-metrics.enable = false` to
opt out. opt out.

View file

@ -121,18 +121,18 @@ slow steps. `expired` counts logins stopped because their code never came.
## Host setup ## Host setup
The claude login minter, in a `swarm-claude-login` container on the host that The claude login minter, a pod in the cluster of the host that sets
sets `deploy.claude-login.enable`. `allSwarmServices` defaults it on wherever `deploy.claude-login.enable`. `allSwarmServices` defaults it on wherever
the host has the minter's store identity, like the other swarm services. the host has the minter's store identity, like the other swarm services.
Run one: a login in progress lives in the service's memory between its start Run one: a login in progress lives in the service's memory between its start
and its code. and its code.
With `deploy.claude-login.runtime = "k8s"` it runs as a pod in the host's It runs as a pod in the host's cluster, and the host has no container. Each
cluster instead, and the host has no container. Each login's scratch directory login's scratch directory
is in the pod's `/tmp` volume, which is where `claude` writes its config, and is in the pod's `/tmp` volume, which is where `claude` writes its config, and
the pod's store login can write the agents' credentials as the container's the pod's store login can write the agents' credentials as the container's
certificate does. Nothing moves in a switch: a login in progress ends, as it does certificate does. A login in progress ends when the pod restarts. See
on a restart. See [the runtime switch](../k8s/runtime.md#the-claude-daemons). [the runtime module](../k8s/runtime.md#the-claude-daemons).
An operator logs an agent in from the **log in** button on its card in the An operator logs an agent in from the **log in** button on its card in the
swarm UI. swarm-controller relays the start and the pasted code over the queue, swarm UI. swarm-controller relays the start and the pasted code over the queue,

View file

@ -514,24 +514,26 @@ The URL hooks register against is `deploy.swarm-controller.publicUrl`, default
whether the gateway reaches the controller by socket or by its TCP listener. Set it when another whether the gateway reaches the controller by socket or by its TCP listener. Set it when another
URL fronts the controller. URL fronts the controller.
## Reaching the controller over TCP (optional) ## Reaching the controller over TCP
By default the gateway reaches the controller through a unix socket on the same host. Setting The controller runs as a pod in the host's cluster, so the gateway reaches it over a TLS
`swarm.controller.tcp.enable` and `swarm.controller.tcp.domain` on **every host of the swarm** listener, never a unix socket. `swarm.controller.tcp.enable` defaults on and
adds a TLS listener beside the socket and points the gateway's `/api/` and `/webhook/forge/` `swarm.controller.tcp.domain` defaults to `controller.<swarm.domain>`, so nothing needs
locations at it by that name. Nothing else changes: the socket stays, and the operator gate on setting, on every host of the swarm alike. The controller's host refuses to evaluate
`/api/` stays. with the listener off or with no swarm domain, naming the option. The gateway's `/api/` and `/webhook/forge/`
locations dial the pod's Service and verify the certificate as that name. The operator gate on `/api/` stays.
What you provide: What you provide:
- `swarm.controller.tcp.domain`, resolvable from the gateway's host. Nginx resolves it when it - Nothing for the name: `swarm.controller.tcp.domain` is only the name the listener's
loads its config. certificate carries and the gateway verifies, because the gateway dials the pod's
Service.
- `deploy.swarm-controller.tcp.openFirewall = true` on the controller's host only when a gateway - `deploy.swarm-controller.tcp.openFirewall = true` on the controller's host only when a gateway
on another host dials it. The port (`swarm.controller.tcp.port`, default 9443) stays closed 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. until you do, and `deploy.swarm-controller.tcp.listenAddress` picks the bound address.
With `deploy.swarm-controller.runtime = "k8s"` a ClusterIP Service publishes the The controller runs as a pod, and a ClusterIP Service publishes its
pod's listener. The gateway dials the Service's name, listener. The gateway dials the Service's name,
`swarm-controller.hyperhive.svc.cluster.local` by default, at the same port. The `swarm-controller.hyperhive.svc.cluster.local` by default, at the same port. The
hive's resolver answers it through the cluster's DNS, so `gateway.dns.enable` hive's resolver answers it through the cluster's DNS, so `gateway.dns.enable`
has to be on. The gateway still verifies the certificate as has to be on. The gateway still verifies the certificate as

View file

@ -152,12 +152,12 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
| the CI run poller's copy of its OIDC secret | authelia's mint, which creates it in the swarm secret store | `swarm-ci-metrics` reads `swarm/services/<swarm.ci-metrics.clientId>/oidc/client` once per pass under its own leaf, and again when authelia refuses it; memory only. While it differs from authelia's, the token request fails, nothing gets pushed and no cursor moves | same leaf, nothing else | | the CI run poller's copy of its OIDC secret | authelia's mint, which creates it in the swarm secret store | `swarm-ci-metrics` reads `swarm/services/<swarm.ci-metrics.clientId>/oidc/client` once per pass under its own leaf, and again when authelia refuses it; memory only. While it differs from authelia's, the token request fails, nothing gets pushed and no cursor moves | same leaf, nothing else |
| authelia's container's journal forwarder's OIDC secret | authelia's mint, in its container, like every client's secret (`swarm.authelia.otel.clientId`). It creates it at `swarm/services/<id>/oidc/client`, and `swarm-journal-forwarder-oidc.service` in the same container reads it back under the secret publisher's leaf, at start and every 10 minutes | `/run/swarm-journal-forwarder-oidc/client-secret` on the container's tmpfs, root `0400`; `LoadCredential` hands it to the collector. | none: the forwarder runs only in authelia's container, and is off there without the publisher's leaf | | authelia's container's journal forwarder's OIDC secret | authelia's mint, in its container, like every client's secret (`swarm.authelia.otel.clientId`). It creates it at `swarm/services/<id>/oidc/client`, and `swarm-journal-forwarder-oidc.service` in the same container reads it back under the secret publisher's leaf, at start and every 10 minutes | `/run/swarm-journal-forwarder-oidc/client-secret` on the container's tmpfs, root `0400`; `LoadCredential` hands it to the collector. | none: the forwarder runs only in authelia's container, and is off there without the publisher's leaf |
| authelia subject store | `swarmctl` and `swarm-authelia-bridge` | `users.yml` — one file, read and written by both | `swarmctl`, on the host that runs authelia | | authelia subject store | `swarmctl` and `swarm-authelia-bridge` | `users.yml` — one file, read and written by both | `swarmctl`, on the host that runs authelia |
| 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 (with `deploy.nats.runtime = "k8s"`, by the pod's `callout-config` init container under the `swarm-nats-auth` jwt role); 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 nkeys (user seed + account seed) | `swarm-nats-auth ensure-callout-keys`, run by the pod's `callout-config` init container under the `swarm-nats-auth` jwt role when the store holds no seed | 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 (with `deploy.nats.runtime = "k8s"`, by the pod's `callout-config` init container under the `swarm-nats-auth` jwt role) | 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`) | | queue auth-callout xkey (curve seed) | `swarm-nats-auth ensure-callout-keys`, run by the pod's `callout-config` init container under the `swarm-nats-auth` jwt role 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 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 queue pod's TLS leaf and key | the pod's `tls-issue` init container, only with `deploy.nats.runtime = "k8s"`: it logs in with the pod's ServiceAccount token as the store's `swarm-nats` jwt role, which has the policy of the `swarm-nats` cert role, and issues one name, `swarm.nats.domain`. The host keeps `swarm-bao-nats-tls`, which issues its own copy for the gateway's `/metrics` vhost and restarts no server | `/var/lib/swarm-nats-tls/{cert,key}.pem` in an in-memory `emptyDir` (`medium: Memory`), gone with the pod. The server reads both as it starts and again on `SIGHUP`; the key never reaches the node's disk | the pod's `tls-renew` container repeats the check every five minutes, issues a new leaf once the old one is past half its 30 days and signals the server, so a long-running pod needs nothing. Nothing to place: the pod's account is the credential | | the queue pod's TLS leaf and key | the pod's `tls-issue` init container: it logs in with the pod's ServiceAccount token as the store's `swarm-nats` jwt role, which has the policy of the `swarm-nats` cert role, and issues one name, `swarm.nats.domain`. The host keeps `swarm-bao-nats-tls`, which issues its own copy for the gateway's `/metrics` vhost and restarts no server | `/var/lib/swarm-nats-tls/{cert,key}.pem` in an in-memory `emptyDir` (`medium: Memory`), gone with the pod. The server reads both as it starts and again on `SIGHUP`; the key never reaches the node's disk | the pod's `tls-renew` container repeats the check every five minutes, issues a new leaf once the old one is past half its 30 days and signals the server, so a long-running pod needs nothing. Nothing to place: the pod's account is the credential |
| 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 controller's TCP listener certificate and key | the pod's init container, while `swarm.controller.tcp.enable` is on (the default). It issues the leaf into an in-memory `emptyDir` from the store's `swarm-controller-tls` role under its ServiceAccount token: one name, `swarm.controller.tcp.domain`, `serverAuth` only. Its `tls-renew` container repeats the same check daily, because nothing rolls the pod before the leaf expires | `<deploy.swarm-controller.tcp.tlsDir>/{cert,key}.pem` (`/var/lib/swarm-controller-tls`) in the pod, 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 init container 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 gateway's client certificate for the controller's TCP listener | `swarm-controller-gateway-client.service` on the host that runs the controller, while `swarm.controller.tcp.enable` is on (the default). 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 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 | | 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 |
| a cluster pod's store login token (a ServiceAccount token) | the cluster's API server, which signs it for the pod's account and the audience `bao`. The kubelet projects it into the pod and rewrites it before it expires | `/var/run/secrets/hyperhive/bao/token` in the pod. The store accepts it at its `jwt-k8s` mount, for the role of that account only, against the public halves of the node's signing keys, which `swarm-bao-k8s-jwt-policy` derives from the key files. A node whose signing keys changed needs that unit restarted, and tokens signed with the old key fail to log in meanwhile | Nothing to place: the pods and the store run on the cluster's one host | | a cluster pod's store login token (a ServiceAccount token) | the cluster's API server, which signs it for the pod's account and the audience `bao`. The kubelet projects it into the pod and rewrites it before it expires | `/var/run/secrets/hyperhive/bao/token` in the pod. The store accepts it at its `jwt-k8s` mount, for the role of that account only, against the public halves of the node's signing keys, which `swarm-bao-k8s-jwt-policy` derives from the key files. A node whose signing keys changed needs that unit restarted, and tokens signed with the old key fail to log in meanwhile | Nothing to place: the pods and the store run on the cluster's one host |

View file

@ -40,7 +40,9 @@ under `deploy.nats` or `swarm.nats`, fails at eval with a message naming the
option and where the keys live now. option and where the keys live now.
To replace either key, delete both of its paths the way the xkey's section To replace either key, delete both of its paths the way the xkey's section
below shows for the xkey, then restart `swarm-bao-nats-callout-xkey`. below shows for the xkey, then delete the queue's pod (`kubectl -n hyperhive delete pod
--selector app.kubernetes.io/name=swarm-nats`): its init container creates the keys
again.
One consequence worth knowing before you debug it: the queue assembles its One consequence worth knowing before you debug it: the queue assembles its
config each time the server starts rather than at build time, in every mode, config each time the server starts rather than at build time, in every mode,
@ -63,14 +65,14 @@ Only the `swarm-nats-auth` role reads either path, and it may create each but
never replace it. The policy of `swarm-secret-publisher`, which writes the rest never replace it. The policy of `swarm-secret-publisher`, which writes the rest
of `swarm/services/`, denies it the seed's path. of `swarm/services/`, denies it the seed's path.
On the queue's host, `swarm-bao-nats-callout-xkey` runs before the The queue pod's `callout-config` init container runs before the server and the
`swarm-nats` container, under the responder's store leaf: responder, under the pod's `swarm-nats-auth` login:
1. `swarm-nats-auth ensure-callout-keys` creates the pair when the store holds no 1. `swarm-nats-auth ensure-callout-keys` creates the pair when the store holds no
seed, and otherwise only reads it. It needs no queue, so on a first boot seed, and otherwise only reads it. It needs no queue, so on a first boot
the key exists before the server that needs it. the key exists before the server that needs it.
2. It reads the public half back from the store into 2. It reads the public half back from the store into
`/var/lib/nats-callout/callout-xkey.pub` inside the container. `/var/lib/nats-callout/callout-xkey.pub` in the pod's config volume.
3. Each time `nats-server` starts, it renders that key into 3. Each time `nats-server` starts, it renders that key into
`auth_callout.xkey`. With no file, the server doesn't start. `auth_callout.xkey`. With no file, the server doesn't start.
4. The responder starts after the server and reads the seed from the store. 4. The responder starts after the server and reads the seed from the store.
@ -78,31 +80,15 @@ On the queue's host, `swarm-bao-nats-callout-xkey` runs before the
requests it can't open. requests it can't open.
The store has to be reachable each time the responder starts. When it's down, The store has to be reachable each time the responder starts. When it's down,
the fetch unit fails and retries for a day. The server starts with the key the init container fails and the pod doesn't start its server. A responder that starts
fetched last time, or not at all on a first boot. A responder that starts
while the store is down exits and retries, first after 5 seconds and then while the store is down exits and retries, first after 5 seconds and then
after longer waits up to a minute, and until one start reads the seed the after longer waits up to a minute, and until one start reads the seed the
queue refuses every client, OIDC ones included. The retry that lands the file queue refuses every client, OIDC ones included. The retry that lands the file
starts or restarts the server, and the responder comes up with it. starts the server, and the responder comes up with it.
The responder always comes back. Its unit has `Restart=always` and no start The responder is the pod's main container: the kubelet restarts a container that
limit, so a burst of starts can't leave it failed. A stop that comes from the exits, and a deleted pod starts the server and the responder again, so the
server failing isn't a restart trigger, so every host script that restarts responder loads the current seeds.
the server in `swarm-nats` (`swarm-bao-nats-tls` on a leaf rotation,
`swarm-bao-nats-callout-xkey` after fetching the keys) also clears the
responder's failed state and starts it. Those scripts use `start`, not
`restart`: the server's restart already restarts a running responder, which loads
the current seeds.
Those starts can still fail: a start job fails when a unit the responder
requires, the server or the container's trust bundle, fails first, and a
failed job leaves the responder inactive, out of `Restart=`'s reach. Both
units therefore uphold it (systemd's `Upholds=`): while either one runs, systemd starts
an inactive or failed responder, and the unit that comes up last starts it with
both up. This also means stopping the responder or the server by hand inside
the container lasts only as long as the stop itself: systemd starts the
responder again, and the responder pulls the server back in. To keep it down,
mask it, or stop the container.
The responder's store leaf is `deploy.nats.authBaoClientCertFile` / The responder's store leaf is `deploy.nats.authBaoClientCertFile` /
`authBaoClientKeyFile`. On the store's host both default to the leaf `authBaoClientKeyFile`. On the store's host both default to the leaf
@ -114,26 +100,22 @@ name it in both options. Until you do, evaluation fails naming both.
Where the queue and the store run on different hosts, deploy the store's host Where the queue and the store run on different hosts, deploy the store's host
first. `swarm-bao-nats-auth-policy` there writes the role's grants on the first. `swarm-bao-nats-auth-policy` there writes the role's grants on the
keys' paths, and `swarm-bao-secret-publisher-policy` the publisher's denial of keys' paths, and `swarm-bao-secret-publisher-policy` the publisher's denial of
the seeds' paths; where the queue runs on that host too, the fetch waits for the seeds' paths. A queue host deployed before it can't read or create the keys, so
both. A queue host deployed before it can't read or create the keys, so its its init container fails, and the queue refuses every client until you deploy
fetch fails, and the queue refuses every client until you deploy the store's the store's host: the server doesn't start, and the responder can't load its seeds. If that takes longer than the init container's retries, delete the queue's
host: the server starts only on public keys fetched before, and the responder pod.
can't load its seeds. Seed files the import is waiting for stay where they
are. If that takes longer than the fetch's day of retries, run
`systemctl restart swarm-bao-nats-callout-xkey` on the queue's host.
Two starts that create the key at once can't both win: each write is a Two starts that create the key at once can't both win: each write is a
create that fails once the path holds anything, and the start that lost reads create that fails once the path holds anything, and the start that lost reads
the winner's key back. the winner's key back.
To replace the key, remove both paths with their metadata and every version, To replace the key, remove both paths with their metadata and every version,
then restart the fetch unit on the queue's host. Its restart of `nats.service` then delete the queue's pod. The new pod's responder loads the new seed:
restarts the responder too, which then loads the new seed:
```sh ```sh
bao kv metadata delete secret/swarm/services/swarm-nats/callout/xkey-seed bao kv metadata delete secret/swarm/services/swarm-nats/callout/xkey-seed
bao kv metadata delete secret/swarm/public/swarm-nats/callout-xkey bao kv metadata delete secret/swarm/public/swarm-nats/callout-xkey
systemctl restart swarm-bao-nats-callout-xkey kubectl -n hyperhive delete pod --selector app.kubernetes.io/name=swarm-nats
``` ```
`bao kv delete` isn't enough. It deletes the latest version but keeps the `bao kv delete` isn't enough. It deletes the latest version but keeps the

View file

@ -436,15 +436,15 @@ behind. The router reads the consumer counts at the start of each pull, at most
## Host setup ## Host setup
The notification router, in a `swarm-notify-router` container on the host The notification router, a pod in the cluster of the host
that sets `deploy.notify-router.enable`. `allSwarmServices` defaults it on that sets `deploy.notify-router.enable`. `allSwarmServices` defaults it on
wherever the host has the router's store identity, on the review classifier's wherever the host has the router's store identity, on the review classifier's
terms. Run one: it handles each issue's events in order. terms. Run one: it handles each issue's events in order.
With `deploy.notify-router.runtime = "k8s"` on a host that runs the cluster The router runs as a pod in the host's cluster (`deploy.k8s.enable`, which the
(`deploy.k8s.enable`), the router runs as a pod and the host has no container. router turns on by default), and the host has no container. The router keeps
The router keeps nothing on the host, so the switch copies nothing; see nothing on the host, so an upgrade copies nothing; see
[the runtime switch](../k8s/runtime.md). [the runtime module](../k8s/runtime.md).
swarm-controller keeps every `issues` and `pull_request` delivery, and every swarm-controller keeps every `issues` and `pull_request` delivery, and every
failed or cancelled CI run, from its instance-wide hooks in the `SWARM_EVENTS` failed or cancelled CI run, from its instance-wide hooks in the `SWARM_EVENTS`

View file

@ -776,18 +776,18 @@ These get settled, and filled in here, as the work reaches them:
## Host setup ## Host setup
The review classifier's try-out service, in a `swarm-review-classifier` The review classifier's try-out service, a pod in the cluster of the host that
container on the host that sets `deploy.review-classifier.enable`. sets `deploy.review-classifier.enable`.
`allSwarmServices` defaults it on wherever the host has the classifier's store `allSwarmServices` defaults it on wherever the host has the classifier's store
identity: the host that runs the store has it, and a services host with the identity: the host that runs the store has it, and a services host with the
store elsewhere gets the classifier only once it holds a copy of the pair (see store elsewhere gets the classifier only once it holds a copy of the pair (see
below). Set `deploy.review-classifier.enable` directly to override either way. below). Set `deploy.review-classifier.enable` directly to override either way.
With `deploy.review-classifier.runtime = "k8s"` it runs as a pod in the host's It runs as a pod in the host's cluster, and the host has no container. Each
cluster instead, and the host has no container. Each run's scratch directory run's scratch directory
and its `HOME` are in the pod's `/tmp` volume. The pod's network isn't and its `HOME` are in the pod's `/tmp` volume. The pod's network isn't
restricted, and the ACP runtime's `base_url` comes from the run. See restricted, and the ACP runtime's `base_url` comes from the run. See
[the runtime switch](../k8s/runtime.md#the-claude-daemons). [the runtime module](../k8s/runtime.md#the-claude-daemons).
The operator sets the key of the runtime the swarm settings choose in the The operator sets the key of the runtime the swarm settings choose in the
swarm UI: the **classifier settings** card on `/jobs` takes a key for the swarm UI: the **classifier settings** card on `/jobs` takes a key for the

View file

@ -84,7 +84,7 @@ choices behind the defaults.
## Host setup ## Host setup
The speech-to-text service, in a `swarm-stt` container on the host that sets The speech-to-text service, a pod in the cluster of the host that sets
`deploy.stt.enable`. `allSwarmServices` defaults it on wherever the host has the `deploy.stt.enable`. `allSwarmServices` defaults it on wherever the host has the
service's store identity, like the other swarm services. Run it where the inference service's store identity, like the other swarm services. Run it where the inference
hardware is: it transcribes with whisper.cpp. hardware is: it transcribes with whisper.cpp.
@ -97,15 +97,15 @@ model (`small` by default, or `base`), and `modelFile` takes any other ggml
model. The cache time, the limits on file size, audio length and run time, and model. The cache time, the limits on file size, audio length and run time, and
how many requests it holds at once are settings next to it. how many requests it holds at once are settings next to it.
With `deploy.stt.runtime = "k8s"` on a host that runs the cluster The service runs as a pod in the host's cluster (`deploy.k8s.enable`, which the
(`deploy.k8s.enable`), the service runs as a pod and the host has no container. service turns on by default), and the host has no container.
The pod has the unit's memory and CPU ceilings as limits and its cache on a The pod has the unit's memory and CPU ceilings as limits and its cache on a
volume of the cluster. The systemd sandbox stays on the host, and the pod has volume of the cluster. The systemd sandbox stays on the host, and the pod has
the security shape every pod has, in a user namespace of its own as the unit has the security shape every pod has, in a user namespace of its own as the unit has
`PrivateUsers`. The pod's NetworkPolicy lets it reach cluster DNS and the store, `PrivateUsers`. The pod's NetworkPolicy lets it reach cluster DNS and the store,
identity provider, queue and hive collector on the host and nothing else, and identity provider, queue and hive collector on the host and nothing else, and
admits no ingress. Nothing moves in a switch, so each side keeps the cache it admits no ingress. An upgrade from the container doesn't carry its cache over; see
last had; see [the runtime switch](../k8s/runtime.md). [the runtime module](../k8s/runtime.md).
The audio comes from rooms with outside people, so the service runs as its own The audio comes from rooms with outside people, so the service runs as its own
unprivileged user under a tight systemd sandbox, with a memory ceiling and a CPU unprivileged user under a tight systemd sandbox, with a memory ceiling and a CPU

View file

@ -763,13 +763,12 @@ in
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Run the swarm's message queue in a `swarm-nats` container on this Run the swarm's message queue as a pod in this host's cluster. A swarm has one queue, so at most one host turns this on —
host. A swarm has one queue, so at most one host turns this on —
but *which* host is its own decision, not necessarily the one but *which* host is its own decision, not necessarily the one
running the swarm's other shared services. running the swarm's other shared services.
Off by default, and off means *absent*: no container is created Off by default, and off means *absent*: no pod is rendered and nothing
and nothing else in the evaluated config changes. else in the evaluated config changes.
''; '';
}; };
@ -795,8 +794,7 @@ in
default = false; default = false;
example = true; example = true;
description = '' description = ''
Run the review classifier in a `swarm-review-classifier` container on Run the review classifier as a pod in this host's cluster. It answers the swarm UI's review try-outs with `claude` on
this host. It answers the swarm UI's review try-outs with `claude` on
the Anthropic API key the operator sets in the swarm UI, or writes to the secret store at the Anthropic API key the operator sets in the swarm UI, or writes to the secret store at
`secret/swarm/services/review-classifier/anthropic-api-key`, field `secret/swarm/services/review-classifier/anthropic-api-key`, field
`api_key`. `api_key`.
@ -808,9 +806,6 @@ in
and `reviewClassifierClientKeyFile`, minted on the store's host). The and `reviewClassifierClientKeyFile`, minted on the store's host). The
key is never written for you: until the operator writes it the service key is never written for you: until the operator writes it the service
runs and every run fails with "no API key…". runs and every run fails with "no API key…".
Set {option}`services.hyperhive.deploy.review-classifier.runtime` to
`k8s` to run it as a pod in the host's cluster instead.
''; '';
}; };
@ -819,8 +814,7 @@ in
default = false; default = false;
example = true; example = true;
description = '' description = ''
Run the claude login minter in a `swarm-claude-login` container on Run the claude login minter as a pod in this host's cluster. It runs `claude auth login` for the agent an operator logs
this host. It runs `claude auth login` for the agent an operator logs
in from its card in the swarm UI, and writes the credentials to that in from its card in the swarm UI, and writes the credentials to that
agent's `secret/swarm/agents/<agent>/claude-credentials`, which the agent's `secret/swarm/agents/<agent>/claude-credentials`, which the
agent's harness installs. Run it on one host: a login in progress agent's harness installs. Run it on one host: a login in progress
@ -831,9 +825,6 @@ in
host has the minter's store identity (the pair host has the minter's store identity (the pair
{option}`services.hyperhive.deploy.bao.claudeLoginClientCertFile` {option}`services.hyperhive.deploy.bao.claudeLoginClientCertFile`
and `claudeLoginClientKeyFile`, minted on the store's host). and `claudeLoginClientKeyFile`, minted on the store's host).
Set {option}`services.hyperhive.deploy.claude-login.runtime` to `k8s`
to run it as a pod in the host's cluster instead.
''; '';
}; };
@ -842,15 +833,11 @@ in
default = false; default = false;
example = true; example = true;
description = '' description = ''
Run the notification router in a `swarm-notify-router` container on Run the notification router as a pod in this host's cluster. It reads the forge events swarm-controller keeps from its
this host. It reads the forge events swarm-controller keeps from its
webhooks and queues todos for the agents they concern: assigned, webhooks and queues todos for the agents they concern: assigned,
unassigned, and cleared when the issue or pull request closes. Run unassigned, and cleared when the issue or pull request closes. Run
it on one host: it handles each issue's events in order. it on one host: it handles each issue's events in order.
Set {option}`services.hyperhive.deploy.notify-router.runtime` to `k8s`
to run it as a pod in the host's cluster instead.
On by default where On by default where
{option}`services.hyperhive.deploy.allSwarmServices` is set and this {option}`services.hyperhive.deploy.allSwarmServices` is set and this
host has the router's store identity (the pair host has the router's store identity (the pair
@ -864,15 +851,11 @@ in
default = false; default = false;
example = true; example = true;
description = '' description = ''
Run the speech-to-text service in a `swarm-stt` container on this Run the speech-to-text service as a pod in this host's cluster. It transcribes the voice memos agents send, once per memo, with
host. It transcribes the voice memos agents send, once per memo, with
whisper.cpp; run it where the inference hardware is. The model is whisper.cpp; run it where the inference hardware is. The model is
{option}`services.hyperhive.deploy.stt.settings.modelSize` (default {option}`services.hyperhive.deploy.stt.settings.modelSize` (default
`small`). `small`).
Set {option}`services.hyperhive.deploy.stt.runtime` to `k8s` to run it
as a pod in the host's cluster instead.
On by default where On by default where
{option}`services.hyperhive.deploy.allSwarmServices` is set and this {option}`services.hyperhive.deploy.allSwarmServices` is set and this
host has the service's store identity (the pair host has the service's store identity (the pair
@ -995,7 +978,10 @@ in
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Run the swarm-controller daemon on this host. Run the swarm-controller daemon as a pod in this host's cluster
({option}`services.hyperhive.deploy.k8s.enable`, on by default where this
is set). It needs {option}`services.hyperhive.swarm.controller.tcp.enable` (on by default):
the gateway reaches the pod over its TCP listener.
Off by default and deliberately not derived from Off by default and deliberately not derived from
{option}`services.hyperhive.deploy.hive-controller.enable`: a swarm {option}`services.hyperhive.deploy.hive-controller.enable`: a swarm
@ -1003,9 +989,8 @@ in
rather than about whether it runs a hive. rather than about whether it runs a hive.
Also serves the swarm UI from this host. The UI is a view onto the Also serves the swarm UI from this host. The UI is a view onto the
controller's state and reaches it over that daemon's unix socket, controller's state and reaches it through the pod's Service, so the
so the host that runs the controller is the only host that can host that runs the controller is the only host that can serve it.
serve it.
''; '';
}; };
}; };

View file

@ -49,17 +49,6 @@ let
# Readers that log in under another unit's principal: reader unit → the # Readers that log in under another unit's principal: reader unit → the
# gate its own module defines it under, and the policy units it waits for. # gate its own module defines it under, and the policy units it waits for.
readersOfOtherPolicy = { readersOfOtherPolicy = {
# ./swarm-nats.nix, under the queue responder's leaf. Also after the
# publisher's policy, which denies the publisher the callout seeds' paths:
# until it is written the publisher may create them, and this unit keeps
# a seed it finds there.
swarm-bao-nats-callout-xkey = {
here = deployCfg.nats.enable;
policies = [
"swarm-bao-nats-auth-policy"
"swarm-bao-secret-publisher-policy"
];
};
# ./swarm-grafana.nix, under Grafana's leaf, which may create the admin # ./swarm-grafana.nix, under Grafana's leaf, which may create the admin
# password, the metrics bearer, the datasource key and the controller's # password, the metrics bearer, the datasource key and the controller's
# Grafana token only once that policy is written. # Grafana token only once that policy is written.

View file

@ -62,8 +62,6 @@ let
swarm-bao-grafana-metrics-bearer = deployCfg.grafana.enable; swarm-bao-grafana-metrics-bearer = deployCfg.grafana.enable;
swarm-bao-grafana-secret-key = deployCfg.grafana.enable; swarm-bao-grafana-secret-key = deployCfg.grafana.enable;
swarm-bao-grafana-controller-token = deployCfg.grafana.enable; swarm-bao-grafana-controller-token = deployCfg.grafana.enable;
# ./swarm-nats.nix
swarm-bao-nats-callout-xkey = deployCfg.nats.enable;
# ./swarm-ci-runner.nix # ./swarm-ci-runner.nix
swarm-bao-ci-runner = deployCfg.ci-runner.enable; swarm-bao-ci-runner = deployCfg.ci-runner.enable;
# ./swarm-attic.nix # ./swarm-attic.nix

View file

@ -1,7 +1,6 @@
# Kubernetes manifests for the swarm services this host deploys, rendered by # Kubernetes manifests for the swarm services this host deploys, rendered by
# ./render.nix from their systemd units, and the per-service switch that moves # ./render.nix from their systemd units, and the module that applies them to the
# a service between its host unit and the cluster (./runtime.nix). Rendering # cluster (./runtime.nix). docs/4-implementation/k8s/manifests.md
# alone changes no unit and applies nothing. docs/4-implementation/k8s/manifests.md
# and runtime.md have the design. # and runtime.md have the design.
{ {
pkgs, pkgs,
@ -41,9 +40,7 @@ in
object, and the images their pods run into `system.build.k8sImages`. object, and the images their pods run into `system.build.k8sImages`.
The manifests reference their Secrets by name only. The manifests reference their Secrets by name only.
Rendering only: the host's units stay as they are, and nothing The manifests are applied on a host with
applies the manifests to a cluster. A service with a `runtime` option
is applied when it says `k8s`, on a host with
{option}`services.hyperhive.deploy.k8s.enable`. {option}`services.hyperhive.deploy.k8s.enable`.
''; '';
}; };
@ -59,8 +56,8 @@ in
readOnly = true; readOnly = true;
internal = true; internal = true;
description = '' description = ''
What ./runtime.nix moves services with: each enabled service's What ./runtime.nix applies: each enabled service's
objects and switch, the namespace object, and the CA ConfigMap's name objects, the namespace object, and the CA ConfigMap's name
and host files. and host files.
''; '';
}; };
@ -71,7 +68,7 @@ in
inherit (rendered) inherit (rendered)
caConfigMap caConfigMap
caSources caSources
switches serviceNames
userNamespaces userNamespaces
; ;
services = withoutContext rendered.services; services = withoutContext rendered.services;

Some files were not shown because too many files have changed in this diff Show more