Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/docs/4-implementation/k8s/runtime.md
atlas f54aae7927 the log and metrics stores ask every request for a credential the gateway supplies
Each store runs with -httpAuth.* and a credential from the secret store, published to the namespace as a Secret by the host. The gateway's locations send it after auth_request has passed, and the collector's scrape and push take the same one, so a process on the node that bypasses the gateway is refused.
2026-11-27 21:30:12 +01:00

648 lines
42 KiB
Markdown

# Where a service runs: the cluster
The swarm services that have a pod run in the host's cluster and nowhere else:
`swarm-notify-router`, `swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier`,
`swarm-claude-login`, `swarm-controller`, the queue with its auth callout
(`swarm-nats`), the log store with its responders (`swarm-victorialogs`,
`swarm-logs-auth`) and the metrics store with its responders (`swarm-victoriametrics`,
`swarm-metrics-auth`). Each runs once per swarm, because two copies would share one
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.
## The node comes with the services
`services.hyperhive.deploy.k8s.enable` defaults on where the host enables any
of `deploy.notify-router`, `stt`, `ci-metrics`, `review-classifier`,
`claude-login`, `nats`, `swarm-controller`, `victorialogs` or `victoriametrics`.
`deploy.singleHostSwarm` and
`deploy.allSwarmServices` enable them, so an all-local host gets the node and
every service in the cluster with no further option. A host that sets
`deploy.k8s.enable = false` while it enables one fails at evaluation, and the
message names the option and the services.
Some services need more of the host, and the evaluation names the option each
time it's missing:
- `swarm-controller` needs `services.hyperhive.swarm.domain`, which names its
TLS listener (`swarm.controller.tcp.domain`, `controller.<swarm.domain>` by
default) and turns the listener on (`swarm.controller.tcp.enable`, on by
default): the host can't reach a unix socket inside a pod, so the gateway dials
the listener. A setting that can't work fails the evaluation: the listener off,
`deploy.swarm-controller.tcp.listenAddress` other than its default `0.0.0.0` (the
bind inside the pod), or `services.hyperhive.gateway.dns.enable` off, because the
hive's resolver hands the cluster's domain to CoreDNS.
- `nats` needs `services.hyperhive.gateway.dns.enable` too, and the iptables
firewall (`networking.nftables.enable` off).
## Upgrading
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.
`switch-to-configuration` stops every unit the new configuration drops, and waits
for each stop, before it runs the activation that links the manifests into the
cluster's manifests directory (`switch-to-configuration-ng`'s `main.rs` sends the stop jobs for the removed
units, waits for them, and then runs the activation script). The cluster applies a manifest when its
link appears, so the old copy of each service has stopped before its pod can start.
A removed container is a drop-in of the `container@` template, which the same
code treats as removed when no drop-in remains. Nothing else keeps the copies
apart.
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 log store's pod mounts `/var/lib/nixos-containers/swarm-victorialogs/var/lib/victorialogs`,
the directory the container's store used ([The log store](#the-log-store)).
- The metrics store's pod mounts
`/var/lib/nixos-containers/swarm-victoriametrics/var/lib/victoriametrics`, the
directory the container's store used ([The metrics store](#the-metrics-store)).
- 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
directory.
- **The unit the pod comes from.** Each service module still defines the
systemd unit, and the renderer reads the pod's environment, credential ids and
limits from it. The host doesn't run the unit: the module evaluates it on its
own for the services that had a container, and defines
`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 `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
self-signed;
- `bao-server-ca.pem`: the secret store's server CA
(`deploy.bao.serverCaFile`);
- `hive-client-ca.pem` and `swarm-services-root.pem`, for the controller: the
authority the controller writes into each hive's store role
(`deploy.swarm-controller.hiveClientCaFile`), and the store's services root
that its listener trusts the gateway's client leaf by.
All are public certificates. The unit waits for the cluster and for the
files, and a pod that mounts the ConfigMap waits in `ContainerCreating` until
the unit has run. The unit is `Type=simple`, so it doesn't hold
`multi-user.target` while it waits: the store's and the hive's CA files come
from the [setup](../../1-getting-started/setup.md), which runs after the host
has booted. The kubelet retries a failed volume mount with a backoff of up to
two minutes, so a pod that was waiting starts up to two minutes after the unit
has published. A path unit watches both files and runs the unit again when
either changes, with no manual step. A running pod doesn't see a changed
trust bundle until it restarts, because the kubelet doesn't update `subPath`
mounts.
## State
No pod starts behind a gate that checks its state volume: a service keeps
nothing an upgrade has to copy. Each service's state is below.
`swarm-notify-router`, `swarm-review-classifier` and `swarm-claude-login` have
no volume.
`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 an
upgrade copies nothing, and the router continues from the consumer's position.
`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
starts on an empty cache on every start of the pod; an upgrade from the
container doesn't carry the old cache over. The whisper model isn't state: the
pod's image holds it.
`swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers
already pushed. It sits in the PersistentVolumeClaim `swarm-ci-metrics-store`, mounted at
`/var/lib/private/swarm-ci-metrics`, which binds a static local volume on that
host directory, the service's old state directory. An upgrade moves the process
and not the cursor. The volume's `nodeAffinity` and the pod's `nodeSelector`
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
that never ran the service, because the volume needs it before the first Job.
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
claim `swarm-ci-metrics-state` on the cluster's default class. A bound claim's
class can't change, so the poller uses a new claim and the old one stays,
unused, until the operator deletes it. The first Job after the upgrade finds
the host directory's cursor, or none, and pushes every run again as the same
points.
## The controller
`swarm-controller` runs once per swarm, and nothing in the daemon guards that: a
second copy would send the operator admin grants and revokes again, split the
review requests the queue holds, and write the same keys. On one node the guard is
the Deployment: one replica and the `Recreate` strategy, and the removed host
unit stops before the pod can start. No leader lock exists, so a cluster
of more than one node needs one before the controller may run there.
- **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,
`swarm-controller.<namespace>.svc.<cluster domain>`, publishes it. The
listener binds `0.0.0.0` inside the pod (`tcp.listenAddress`, which the
evaluation holds there). The host's resolver, the hive's dnsmasq, hands the
cluster's domain to CoreDNS
([the node](node.md#reaching-the-cluster-from-the-host)). The gateway's
`/api/` and `/webhook/forge/` locations dial the Service's name through
nginx's own `resolver` (the same dnsmasq) and a variable upstream, so nginx
looks the name up per request. A name written into `proxy_pass` gets one
lookup when nginx loads its configuration, and nginx refuses to load when it
doesn't resolve. The locations verify the listener's certificate as
`swarm.controller.tcp.domain` (`proxy_ssl_name`, `proxy_ssl_verify`). With
the controller on the host the locations dial that name. The Service has a
NetworkPolicy that selects the pod for ingress and allows nothing: the
cluster's policy engine always admits traffic from an address of the node, so
the gateway's connection and the kubelet's probes reach the pod, and no other
pod does. A Service works on a cluster of more than one node, but the
controller's Deployment still has the one replica.
- **The listener's leaf.** The pod issues its own, from the store's
`swarm-controller-tls` role. An init container logs in with the pod's
ServiceAccount token (the `swarm-controller` role of the `jwt-k8s` mount,
whose policy holds the one issue path) and writes the leaf and its key into
an `emptyDir` before the daemon starts. The `emptyDir` is in memory
(`medium: Memory`), so the key never reaches a Secret or the node's disk. A
second container, `tls-renew`, runs the script again every day, and again
after ten minutes when the store refused. The script leaves a leaf alone
while it's in the first half of its lifetime, as the host's daily timer
does, and the daemon reads the new files with no restart. A sidecar renews
because nothing rolls the pod before the leaf expires. Both containers run
an image of their own, `swarm-controller-tls`, which holds the store client
and the script's tools.
- **`swarmctl`.** The controller's socket lives inside the pod, so the host's
`swarmctl` reaches the controller only through the gateway: run
`swarmctl login` once. The host's wrapper defaults `--swarm` to the host's own
swarm and sets no socket path, since a socket path on the host serves nothing.
- **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on
`/healthz` and readiness on `/readyz`. Readiness needs the queue connection
and a fresh store login, so a store role that refuses the pod's token leaves
it NotReady.
- **State.** `/var/lib/swarm-controller` is an `emptyDir`. The record of the
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
starts again from nothing: the forge avatar markers and the legacy webhook
secret, which the secret store also holds. A legacy grant file on the host is
not imported.
- **The rev.** The unit's rev file, `/etc/hyperhive/swarm-controller.json`, is a
`subPath` mount of the `swarm-controller-etc` ConfigMap, which a running pod
never sees change. The Deployment's pod template carries `checksum/etc`, a
hash of the ConfigMap's content, so a new rev rolls the pod, which drops the
job graph.
## The queue
`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,
because a server whose responder is down refuses every connect. Two servers
or two responders never run: the Deployment has one replica and the `Recreate`
strategy, and the removed container stops before the pod can start.
- **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
run `nats`, the server, `tls-renew` and `exporter`, the Prometheus exporter.
Two init containers run in order before them. `tls-issue` issues the server's
leaf. `callout-config` creates the callout's keys if the store holds none,
fetches their public halves and writes the server's configuration. The
server's settings are the ones the container's `services.nats.settings`
render, so a change to them reaches both. Only the path of the server's key
differs, because the pod has no credential directory.
- **Names.** The pod's `hostAliases` map the queue's name to the pod's own
loopback, so the responder dials the server by the name its leaf carries and
verifies it, with no traffic leaving the pod. Every other client reaches the
queue by the same name as before: the node's CoreDNS and the bridge's
resolver answer it with the bridge's address, and the load balancer's port
forwards it to the pod.
- **The client port.** The server's port is a `LoadBalancer` Service,
`swarm-nats`, with no `hostPort` on the pod. k3s's service load balancer
(servicelb, on by default) binds the port on `0.0.0.0` of the node with a
`hostPort` of its own, in a pod of `kube-system`, and forwards it to the pod
through the Service, so hives on other hosts keep their URL. The Service
allocates no node port: the forwarding uses the Service's cluster address,
and a node port would be a second way in that the raw-table rules don't name.
The server sees the load balancer's pod as the client, not the client's
address. A `hostPort` is a DNAT rule, and the firewall's INPUT rules, the ones
`deploy.nats.openFirewall` and the bridge's port list write, never see what it
rewrites. The module therefore adds rules to the raw table, which the kernel
reads before the DNAT: a packet for the node's address and the client port is
dropped unless it arrives on the host's loopback, the hive bridge, a pod
interface or an interface that `networking.firewall.interfaces` opens the port on
(the semi-spread example opens it on `wg0`), or unless `deploy.nats.openFirewall`
is on. The container's port
has that reach. The `hostPort` sends the bridge's agents to the cluster, which
a host with the egress intercept on refuses, so the module also adds the port
to `egress.publishedPorts`
([the egress chain](../networking/network.md#agent-bridge-egress-log)): agents
reach the queue through the published port and no other way.
- **The exporter's port.** The exporter's port has no `hostPort`: a ClusterIP
Service, `swarm-nats-metrics`, fronts it, and the gateway's `/metrics`
location on the host dials the Service's name through nginx's `resolver` (the
hive's dnsmasq), as [the controller's](#the-controller) does, so
`gateway.dns.enable` has to be on. The exporter answers with the name of every
client, and only the node may read it. The pod's NetworkPolicy selects it for
ingress and allows the client port from any source and nothing else. The
cluster's policy engine always admits traffic from an address of the node, so
the gateway and the kubelet's probes reach the pod, and a pod of the cluster,
or a client of the bridge that the host forwards, doesn't reach the exporter.
- **The leaf.** `tls-issue` logs in to the store with the pod's token as the
role `swarm-nats` and issues the server's leaf from the same script as the
host's `swarm-bao-nats-tls`. The key lands in a volume in memory. The
callout's keys and the responder's own reads go through the role
`swarm-nats-auth`. A pod has one ServiceAccount, `swarm-nats`, so both roles
bind it, and any container that holds its token can log in as either. The
split between the leaf-issuing identity and the callout-key identity holds
between the host's units but not inside the pod, and a container added to the
pod inherits both. A fourth container, `tls-renew`, runs the same script
every five minutes beside the server. It leaves a leaf in the first half of
its 30 days alone, and issues a new one after that. Then it sends `SIGHUP` to
the server, which reloads its TLS files for new connections, so the pod
shares its processes among its containers. A connection already open keeps
the old leaf. The shared process namespace isolates nothing: the
network-facing server sees the responder's and `tls-renew`'s processes, and
under the same user can read their `/proc/<pid>/environ` and
`/proc/<pid>/root`. The container had the same exposure, as one container.
- **The host's units.** The host has no unit that delivers keys or secrets to the
queue. `swarm-bao-nats-tls` stays: it issues the host's own copy of the leaf
for the gateway's `/metrics` vhost, and restarts no server. The gateway's location dials the exporter's Service by
name where it dialled loopback.
- **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
PersistentVolumeClaim `swarm-nats-store` binds a static local volume on it,
so an upgrade moves the process and not the bytes, and the pod has no state
gate. The pod's `fsGroup` gives its group read and write; files the old
container wrote stay owned by the server's old user.
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
`nodeSelector` both name the node label
`hyperhive.darkest.space/state-nats`, so the pod and the directory stay on the
node that carries it ([node labels](node.md#node-labels)).
The Deployment replaces its pod rather than running two, so one server reads
the directory at a time.
nats-server keeps no lock or identity file in the store, so nothing there ties
the directory to the side that wrote it.
The module makes the directory on a host that never ran the container,
because the volume needs it before the pod starts.
The claim and its volume stay until the operator deletes them, as every claim
does, with the directory.
- **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
`wget` against `/healthz?js-enabled-only=true` on the server's monitor, which
stays on the pod's loopback; the server's image holds `wget` and nothing else
of busybox.
- **Stopping.** The container's unit drains the server's clients, giving them
up to 150 seconds to move. The pod's server gets `SIGTERM` and the pod's
15-second grace period, so every client's connection drops at once and the
clients reconnect when the next pod is up.
Core NATS messages published while no server is up never arrive, and JetStream
publishes fail at the publisher.
- **Limits.** None, as on the host. The pod has no memory or CPU limit, and its
descriptors are the container runtime's, not the 800000 the container's unit
sets. The VM test checks the runtime's is at least that.
## The log store
`swarm-victorialogs` is the swarm's log store: one VictoriaLogs, with the two
`auth_request` responders of its gateway vhost in a second pod. The gateway's
vhost `logs.<swarm domain>` stays on the host, and so do the collector that
writes to the store and Grafana that reads it.
- **The store's pod.** The first service rendered without a unit of the module's
own: the module defines the daemon's `ExecStart`, with its flags
(`-storageDataPath`, `-httpListenAddr`, `-retentionPeriod`, `-httpAuth.username` and
`-httpAuth.password`) as a list, and its `StateDirectory` and `LoadCredential`,
and the renderer reads the pod from those. The image holds
the nixpkgs build of `victoria-logs` and nothing else. The pod serves plain
HTTP on port 9428, probed on `/health`, logs in to nothing and pushes no
telemetry: its output is the pod's log, which the host collector reads like
any pod's ([logs](telemetry.md#logs)), and the collector scrapes the store's
own metrics through the gateway. Its Deployment has one replica and the
`Recreate` strategy, and the removed container stops before the pod can start.
- **The store's credential.** Every route of the store's listener asks for HTTP
Basic credentials, `-httpAuth.password=file://` the credential `store-auth` of
the pod's Secret `swarm-victorialogs-credentials`. The built-in routes that
answer a fixed text (`/health`, `/ping`, `/-/healthy`, `/-/ready`,
`/robots.txt`) stay open, and the kubelet's probes use `/health`: the other
routes, the insert, select, delete and admin ones and `/metrics`, answer 401
without it. The module sets none of the store's `-*AuthKey` flags: each of those
routes falls back to the Basic credentials when its key is empty. The unit
`swarm-bao-store-auth` ([`store-credentials.nix`](../../../nix/host-modules/k8s/store-credentials.nix))
creates the password in the swarm secret store at
`swarm/services/victorialogs/store-auth` when the store holds none, as the host's
`swarm-store-auth` principal, whose one grant is create and read on this leaf
and the metrics store's. It writes the `Authorization` header to
`/var/lib/swarm-store-auth/victorialogs.conf` (`root:root`, `0600`, in a root-only directory;
nginx's main process reads its configuration as root, so the file needs no
other reader, and it's never in the nix store), which the vhost's store
locations `include`, then reloads nginx, and publishes the password as the
Secret the way the host publishes the CA ConfigMap. The files stay on disk, as the cluster keeps the Secret on disk, so a reboot with
the secret store still sealed leaves the gateway sending the credential the pod
expects. Nothing rotates the value
by itself: to rotate it, delete the leaf's metadata with a token that may and
restart the unit, which stores a new password, rewrites the file, reloads
nginx and updates the Secret; the store re-reads the file within seconds. A pod waits in `ContainerCreating`
until the Secret exists, and the store re-reads the file every two seconds. A
gateway whose file is still empty sends the caller's own `Authorization`, which
the store refuses. The responders' locations never include the file.
- **State.** The store's data directory is the container's own on the host,
`/var/lib/nixos-containers/swarm-victorialogs/var/lib/victorialogs`: the claim
`swarm-victorialogs-store` binds a static local volume on it, so an upgrade
moves the process and not the bytes. Its `nodeAffinity` and the pod's
`nodeSelector` both name the node label
`hyperhive.darkest.space/state-victorialogs`
([node labels](node.md#node-labels)), so the pod and the directory stay on the
node that carries it. The files the container wrote belong to a user of its
own, which the pod's user isn't. The pod's `fsGroup` is `65532`, and its
`fsGroupChangePolicy` is `OnRootMismatch`: the first start after the upgrade
gives the pod's group the whole tree, and later starts look at the directory
alone, so a restart doesn't walk a store of many files. The files keep their
user. The module makes the directory on a host that never ran the container,
leaving the owner and mode of an existing one alone. The volume's capacity is
nominal: a local volume's size isn't enforced, and retention
(`deploy.victorialogs.retentionPeriod`, 30 days) is what bounds the store.
- **The gateway's hop.** The host can't reach a unix socket inside a pod, so the
store serves TCP and a ClusterIP Service,
`swarm-victorialogs.<namespace>.svc.<cluster domain>`, publishes it. The
vhost's locations dial the Service's name through nginx's `resolver` (the
hive's dnsmasq) and a variable, as [the controller's](#the-controller) do, so
`gateway.dns.enable` has to be on. Each role has a variable of its own, because
the auth subrequests run their own `set`. A `proxy_pass` with a variable and a
URI part sends that URI and not the request's own, so the store's locations
write none, and the request's path and query reach the store as the caller sent
them. The collector's push, Grafana's datasource, the controller's and
hive-c0re's query URLs and the agents' `swarm-logs` all use
`logs.<swarm domain>`, which the host serves: none of them changes.
- **The responders' pod.** `swarm-logs-auth`, which checks an agent's bearer and
its `logs` permission, and `swarm-logs-grafana-auth` (the `swarm-metrics-auth`
binary), which checks Grafana's, run as two containers of one Deployment,
`swarm-logs-auth`. Both log in as the cert role `swarm-logs-auth` does, so the
pod has one ServiceAccount and one jwt role of that name, and both read the
store with the pod's token. They hold no state and nothing in the store pod
calls them, so the pod has no node label and runs on any node, and only the
gateway's subrequests (`auth_request`) reach them: each serves TCP
(`--listen`) on 8081 and 8082, behind a Service each. A unix socket couldn't
stay, because the host's nginx can't open a socket inside a pod, and Pod
Security `restricted` refuses a `hostPath` for it.
- **Who reaches what.** Both pods have a NetworkPolicy that selects them for
ingress and allows none, so only the node's own traffic reaches them: the
host's nginx, which dials the Services, and the kubelet's probes. The policy
refuses a pod of the cluster. The log store asks for its credential on every route, so a
process on the host that dials the Service gets 401: see
[the stores' listener credential](#the-stores-listener-credential). The responders' policy
also lets the pod reach cluster DNS and the store's pod listener on the
bridge's address (`egress = [ "store" ]`), the one host port the pod needs
until the store moves into the cluster.
- **The host's part.** The host keeps the vhost, `gateway.localNames` and the
options (`retentionPeriod`, `authRate`, `authBurst`, `authVerdictTtl` and the
store identity files). It runs no container, unit or socket directory for
either pod, and no journal forwarder: the host collector reads the pods'
output from the node like any pod's.
## The metrics store
`swarm-victoriametrics` is the swarm's metrics store: one VictoriaMetrics, with
the two `auth_request` responders of its gateway vhost in a second pod, the
shape of [the log store](#the-log-store). The gateway's vhost
`metrics.<swarm domain>` stays on the host, and so do the swarm collector that
pushes to the store and Grafana that reads it.
- **The store's pod.** The module defines the daemon's `ExecStart`, with its flags
(`-storageDataPath`, `-httpListenAddr`, `-retentionPeriod`, `-httpAuth.username` and
`-httpAuth.password`) as a list, and its `StateDirectory` and `LoadCredential`,
and the renderer reads the pod from those. The image holds
the nixpkgs build of `victoria-metrics` and nothing else. The pod serves plain
HTTP on port 8428, logs in to nothing and pushes no telemetry: its output is
the pod's log, which the host collector reads like any pod's
([logs](telemetry.md#logs)), and the collector scrapes the store's own metrics
through the gateway. Its Deployment has one replica and the `Recreate`
strategy.
- **The store's credential.** As the log store's ([above](#the-log-store)):
`-httpAuth.password=file://` the credential `store-auth` of the Secret
`swarm-victoriametrics-credentials`, created and published by the same unit at
`swarm/services/victoriametrics/store-auth`, and sent by the vhost from
`/var/lib/swarm-store-auth/victoriametrics.conf`. Every route answers 401 without
it but `/health` and the built-in routes that answer a fixed text, the import,
snapshot, delete and `-*AuthKey` admin routes and `/metrics` included, and the module sets no
`-*AuthKey` flag: each falls back to the Basic credentials when its key
is empty.
- **Probes.** The store opens its storage before it serves HTTP, so it answers
nothing while a large store opens. The pod's startup probe requests `/health`
every ten seconds for up to ten minutes, and the liveness and readiness probes
begin once it has succeeded. The kubelet restarts a pod that fails the startup probe,
so a store that needs longer than that restarts in a loop. The termination
grace period is the renderer's 15 seconds; the store writes its in-memory data to disk when it
stops.
- **State.** The store's data directory on the host is
`/var/lib/nixos-containers/swarm-victoriametrics/var/lib/victoriametrics`: the
claim `swarm-victoriametrics-store` binds a static local volume on it, so the
history the store holds survives a restart or an upgrade of the pod. Its
`nodeAffinity` and the pod's `nodeSelector` both name the node label
`hyperhive.darkest.space/state-victoriametrics`
([node labels](node.md#node-labels)). The files in the directory belong to a
user of its own, which the pod's user isn't: the pod's `fsGroup` is `65532`
with the `OnRootMismatch` policy, as for the log store, so the first start gives
the pod's group the whole tree and later starts look at the directory alone.
The module makes the directory when it's missing and leaves the owner and mode
of an existing one alone. The volume is the plain directory: a store that keeps
its history under `private/` (the layout of a `DynamicUser` unit) isn't
covered. The volume's capacity is nominal, and retention
(`deploy.victoriametrics.retentionPeriod`, 5
years) bounds the store.
- **The gateway's hop.** The store serves TCP and a ClusterIP Service,
`swarm-victoriametrics.<namespace>.svc.<cluster domain>`, publishes it. The
vhost's locations dial the Service's name through nginx's `resolver` and a
variable, as the log store's do, so `gateway.dns.enable` has to be on. An exact
location names its path after the variable, so the store receives the path
nginx matched and the request's query string, as it did over the socket. The
two prefix locations (`/api/v1/label/` and `/vmui/`) name none, so the request's
own path reaches the store: a decoded path in a `proxy_pass` could carry a line
break into the request line. The collector's push and scrape, Grafana's
datasource, the controller's and hive-c0re's URLs and the agents'
`swarm-metrics` all use `metrics.<swarm domain>`, which the host serves: none
of them changes. The vhost has no location for the store's import and admin
routes, so the gateway refuses them.
- **The responders' pod.** The agents' check (the `swarm-logs-auth` binary on
the metrics surface, which checks an agent's bearer and its `metrics`
permission) and Grafana's (`swarm-metrics-auth`, which checks the bearer
Grafana's datasource sends) run as two containers of one Deployment,
`swarm-metrics-auth`. Both log in as the cert role `swarm-metrics-auth` does, so
the pod has one ServiceAccount and one jwt role of that name, and both read the
store with the pod's token. They hold no state, so the pod has no node label
and runs on any node. Each serves TCP (`--listen`) on 8083 and 8084 behind a
Service of its own. The second container names its ports `grafana-api` and
`grafana-health`: a Service resolves a named port to the first container of the
pod that declares the name, so a shared name would send Grafana's bearer to the
agents' responder.
- **Who reaches what.** Both pods have a NetworkPolicy that selects them for
ingress and allows none, so only the node's own traffic reaches them: the
host's nginx, which dials the Services, and the kubelet's probes. The store
asks for its credential on every route, so a process on the host that dials the
Service gets 401: see [the stores' listener credential](#the-stores-listener-credential).
The responders' policy also lets the pod reach cluster DNS and the secret
store's pod listener (`egress = [ "store" ]`).
- **The host's part.** The host keeps the vhost, `gateway.localNames` and the
options (`retentionPeriod`, `agentAuthRate`, `agentAuthBurst`,
`agentAuthVerdictTtl` and the store identity files). The host collector reads
the pods' output from the node like any pod's.
## The stores' listener credential
Each store listens on its pod's address behind a ClusterIP Service, and the
Service's NetworkPolicy admits traffic from the node and from nothing else. An
agent can't reach the pod: its traffic doesn't come from the node, and the
hive's egress rules don't forward it to the pod network.
VictoriaLogs and VictoriaMetrics each check a credential of their own on every
route, beside the gateway's vhost, which checks the caller's bearer. They run
with `-httpAuth.username` and `-httpAuth.password`. Each password is a random
value that `swarm-bao-store-auth` creates in the swarm secret store, hands to
the gateway's nginx and publishes to the cluster as a Secret the pod loads.
After its own check passes, the vhost replaces the caller's `Authorization`
with that credential, so the caller's bearer never reaches the store. A process
on the host that reaches a store without going through the vhost gets 401 from
every route but `/health` and the few built-in ones that answer a fixed text,
the import, delete and admin routes of the metrics store included. Root can
read the credentials, so treat the host as trusted for what root can do.
## Resources and sandbox
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
([manifests](manifests.md#pods)), so `swarm-stt` keeps its 3 GiB and four-core
ceilings. The pod requests nothing (memory `0`, cpu `0`, as the unit sets no
`MemoryMin` or `MemoryLow`), so the node reserves nothing for it and the pod is
Burstable. `TasksMax` has no pod counterpart, so the renderer drops it. The
systemd sandbox (`MemoryDenyWriteExecute`, `SystemCallFilter`, the read-only
`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
read-only root filesystem, every capability dropped, the runtime's default
seccomp profile and no API token.
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
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
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. The
policy also allows the pods of the queue's
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.
## Telemetry and credentials of the poller
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
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
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`
ConfigMap. The pod has no Secret volume, and no `swarm-ci-metrics-credentials`
Secret exists, because nothing creates it.
## The claude daemons
`swarm-review-classifier` and `swarm-claude-login` keep no state, so the
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
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
`/tmp` is an `emptyDir` volume, so each scratch directory, and the config
`claude` writes under it, land in that volume and go with the pod. The
claude login minter writes the credentials it gets to the secret store, not to
disk. The image holds `claude-code` (and `opencode` for the classifier) from the
store paths the unit's environment names, the same ones the container uses. The
unit's own configuration allows the unfree `claude-code`, so the host needs no
global allowance.
Both log in to the store with their ServiceAccount token through a jwt role
that has the policy of their certificate role. The minter's role writes the
agents' `claude-credentials` leaves, as its certificate does.
Neither side restricts the network. The review classifier runs a model-driven
agent over untrusted PR text, and its ACP runtime takes its `base_url` from the
run, so the hosts it reaches aren't fixed. In a pod it has the security shape
every pod has (above) in place of its unit's `DynamicUser` and `PrivateTmp`. A
tighter sandbox and an egress policy belong to the network policy work.
Both pods push their telemetry to the hive collector, as the router and
`swarm-stt` do, because the loopback forwarder their units name has no
counterpart in a pod. The hive collector stamps the `hive` label on what it
forwards.
## Validation
`module-eval-k8s` checks that the all-local host runs every service as a pod and
none as a container, unit or timer, and that the log store's volume is its
old container's directory and its responders' pod has no node label; that the node
defaults on through the all-local mode and through one toggle, and an explicit `false` stays false; that a
host with the node off and a service on fails with a message naming the option
and the services; that a controller without the TCP listener, the pod's bind
address or the hive's resolver fails the evaluation; that the manifests sit in
`services.k3s.manifests`; and that the poller's pod keeps the swarm route its unit
names, where every other pod gets the hive collector, and mounts no Secret.
The VM test `k8s-services` runs a router, the 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 asserts that the host has no container, unit, timer
or prune unit for any of them, and that each pod is Ready, logged in to the
store with its ServiceAccount token, and minted a token with the client secret
it read. The router's pod routes an event, and a pod deleted exits 0 within its
grace period. For `swarm-stt` it asserts that the pod carries the unit's limits,
requests nothing and is Burstable, runs in a user namespace, and keeps its cache
in an `emptyDir`; its NetworkPolicy lets a queue request in and only DNS and four
host ports out. A Job of the poller 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 pushes nothing. For the two claude daemons it asserts that the minter's
token writes an agent's credentials and the classifier's can't, that the pod's
root takes no writes, and that `claude` with `HOME` in the volume writes its
config there while `claude` with `HOME` on the root leaves nothing there.
The VM test `k8s-nats` runs the queue against the real secret store, with the
egress intercept on. The pod is Ready by its exec probe and has the init
containers, the volumes and the Services the module renders and no `hostPort`,
and its leaf's volume is a tmpfs. The load balancer binds the client port from
`kube-system` and the Service has no node port. A client on the bridge reaches
the queue by name and through the published port only, not by the pod's address
or the node's, and a second node outside the node reaches the control port and
not the queue's; with `openFirewall` it dials the pod by name and verifies the
name, and the responder in the pod admits it. The pod's volume is the host's
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.
The same VM test runs the log store. A unit of the test writes a record into the old
container's data directory as another user before the cluster starts, because the
container is no longer in the module to switch from. It asserts that the host has no
container, unit or socket directory for the store or its responders; that the
volume is that directory and the pod's group owns the tree; that a gateway, run
from the module's own locations in a nginx of its own, returns the record to an
agent's bearer, refuses an agent without the grant and a wrong secret, and
checks Grafana's bearer with the second responder; that the store keeps a record
posted to the ingest route and both records across a pod delete; and that the
policy refuses a peer pod the Services while it admits the node and the
kubelet. From the node itself, not through the gateway, the store answers 401 to
an insert, a select and a delete without the credential and 200 with it, and
`/health` answers without; a gateway whose include file is empty gets 401. The `swarm-logs`
CLI itself isn't run: it needs an agent's store certificate, so the test
presents the `Authorization` header it sends.
`k8s-bao-login` and `k8s-node` check the store's login and the node.