Watch
0
0
Fork
You've already forked hyperhive
0

run the log store and its auth responders as pods

swarm-logs-auth and swarm-metrics-auth take --listen for a TCP address beside
--socket. The log store is a Deployment on a static local volume that is its
old container's data directory, behind a ClusterIP Service the gateway dials by
name. Its two auth_request responders are one unpinned pod with a jwt role.
The renderer gains a plain HTTP listener, a probe path, fsGroupChangePolicy,
and one policy for a pod with both a listener and egress.
This commit is contained in:
atlas 2026-11-26 10:17:57 +01:00 • committed by mara
commit c7c82a6b02
9 changed files with 1385 additions and 746 deletions

View file

@ -86,13 +86,25 @@ and the store's granter fetches the bao UI's.
Three services read **every agent's queue secret**
(`swarm/agents/<agent>/queue`), each under a leaf of its own whose policy
reaches that one leaf per agent: the queue's auth callout (`swarm-nats-auth`),
the log store's agent check (`swarm-logs-auth`, on the log store's host), and
the log store's agent check (`swarm-logs-auth`, a pod on the log store's host), and
the metrics store's (`swarm-metrics-agent-auth`, under the `swarm-metrics-auth`
leaf on the metrics store's host). Any one compromised can present any agent's
queue secret, at the queue and at both stores' read routes alike. The two store checks also read the
agent's `swarm/agents/<agent>/observability` leaf, which only the controller writes, and let
the agent through only with the `logs` or `metrics` permission it names.
### The log store takes writes and reads from the node
VictoriaLogs checks no credential: the gateway's vhost does. The 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. A process on
the log store's host, whatever its user, can therefore read every log line and
write records into the store without a bearer. An agent can't: its traffic
doesn't come from the node, and the hive's egress rules don't forward it to the
pod network. Treat the host that runs the log store as trusted for logs. The
metrics store still listens on a unix socket that only the gateway's group can
open.
### Per-hive credentials live under the hive kind
`swarm_secret_client::policy` scopes the **hive** stanza narrowly (unlike the

View file

@ -162,6 +162,9 @@ hive's daemons and the harness units in every agent container.
To read them, open Grafana, pick **Explore** and choose the `VictoriaLogs`
datasource. Agents query it with `swarm-logs`, and need the `logs` permission.
The store runs as a pod in the host's cluster, so `deploy.victorialogs.enable`
turns [the cluster node](../../4-implementation/k8s/node.md) on with it.
| Option | When you'd touch it |
| ------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `deploy.victorialogs.retentionPeriod` | Default `30d`, far shorter than the metrics store's. Raise it to answer questions about last quarter. |

View file

@ -28,6 +28,8 @@ A service gets manifests on the host whose configuration deploys it:
| `swarm-review-classifier` | Deployment | ServiceAccount |
| `swarm-claude-login` | Deployment | ServiceAccount |
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolume and Claim |
| `swarm-victorialogs` | Deployment | Service, NetworkPolicy, PersistentVolume and Claim |
| `swarm-logs-auth` | Deployment | ServiceAccount, two Services, NetworkPolicy |
`namespace.yaml` holds the Namespace ([Pod Security](#pod-security)).
@ -128,17 +130,23 @@ credential directory.
(`collector`). The policy allows its pod on the queue's port too. The node trusts
the pod network's interfaces, so without the policy a pod reaches every port of
the host. A service without `egress` has no
policy.
policy. A service with a listener and `egress` (`swarm-logs-auth`) has the one
policy: it admits the node to the listener and nothing else, and allows the
egress above.
- **Probes:** a service with an opt-in health listener gets its variable set to
`0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` is one of
them, with `SWARM_CONTROLLER_HEALTH_ADDR`.
them, with `SWARM_CONTROLLER_HEALTH_ADDR`. A third-party daemon with no health variable,
`victoria-logs`, names a `probe` path instead (`/health`), which both probes
request on its listener.
- **Listener and init container:** a service with a TCP `listener`
(`swarm-controller`, with `swarm.controller.tcp.enable`) publishes its port
with a ClusterIP Service, admits only the node to it with a NetworkPolicy, and
gets an init container and a renewal container that issue its leaf into an
`emptyDir` ([runtime](runtime.md#the-controller)). The image of those
containers is part of `system.build.k8sImages`.
containers is part of `system.build.k8sImages`. A listener with no `tlsDir`
(`swarm-victorialogs`, `swarm-logs-auth`) serves plain HTTP: it gets the
Service and the policy and no leaf, init container or renewal container.
- **More than the daemon:** a service whose pod holds more than its daemon
(the queue, whose server and exporter run beside the responder) names a
function in its entry that adds containers, init containers, volumes, host
@ -147,7 +155,13 @@ credential directory.
daemon's binary, and the credential directory its unit loads from follows
the daemon's name. The pod runs under one ServiceAccount, so a queue that
holds two store roles has both bound to it
([runtime](runtime.md#the-queue)).
([runtime](runtime.md#the-queue)). The responders' pod of the log store holds a second container the same way
([runtime](runtime.md#the-log-store)).
- **A unit of the module's own making:** a service that never ran under systemd on the
host (`swarm-victorialogs`, `swarm-logs-auth`) gives the renderer the
`serviceConfig`, `environment` and `path` of one as a plain attribute set, with
the daemon's flags as a list in `ExecStart`. The renderer reads nothing else of
a unit. `fsGroupChangePolicy` in the entry sets the pod's field of that name.
- **Config checksum:** a Deployment whose service has a ConfigMap (`etcFiles`)
carries `checksum/etc` on its pod template, the hash of that ConfigMap's
content, so a changed file rolls the pod.

View file

@ -67,8 +67,8 @@ says so with a label. The module sets the labels
(`services.hyperhive.deploy.k8s.nodeLabels`, passed to `services.k3s.nodeLabel`):
- `hyperhive.darkest.space/state-<service>=true`, one per service whose data
the cluster keeps. Today that's `nats`, when `deploy.nats.enable` is on, and `ci-metrics`, when
`deploy.ci-metrics.enable` is on. The
the cluster keeps. Today that's `nats`, `ci-metrics` and `victorialogs`, each when its
`deploy.<service>.enable` is on. The
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
as no match instead of a volume that can't bind. One label per service, so

View file

@ -2,8 +2,9 @@
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` and the queue with its auth callout
(`swarm-nats`). Each runs once per swarm, because two copies would share one
`swarm-claude-login`, `swarm-controller`, the queue with its auth callout
(`swarm-nats`) and the log store with its responders (`swarm-victorialogs`,
`swarm-logs-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
@ -14,7 +15,7 @@ gateway, `swarm-builder`, `swarm-matrix-ctl` and every hive stay on the host.
`services.hyperhive.deploy.k8s.enable` defaults on where the host enables any
of `deploy.notify-router`, `stt`, `ci-metrics`, `review-classifier`,
`claude-login`, `nats` or `swarm-controller`. `deploy.singleHostSwarm` and
`claude-login`, `nats`, `swarm-controller` or `victorialogs`. `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
@ -55,6 +56,8 @@ The data stays where it was:
([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 other services keep nothing a move has to carry.
The pods log in to the store with their ServiceAccount tokens, so the store's
@ -296,6 +299,77 @@ strategy, and the removed container stops before the pod can start.
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`) as a list, and its
`StateDirectory`, 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.
- **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 store takes writes and reads with no credential, so a
process on the host can read and write it: see
[Agent security](../../2-handbook/agents/security.md). 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.
## Resources and sandbox
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
@ -362,8 +436,9 @@ 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; that the node defaults on through the
all-local mode and through one toggle, and an explicit `false` stays false; that a
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
@ -409,4 +484,18 @@ 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. 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.

View file

@ -1,8 +1,10 @@
# Pod logs and metrics
The swarm's log and metric stores stay where they are. A pod's output reaches
them through the hive collector that runs on the host
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), so
The swarm's metric store is a container on the host and its log store is a pod
([the log store](runtime.md#the-log-store)). A pod's output reaches both
through the hive collector that runs on the host
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), which pushes to
the stores through the gateway, so
`swarm-logs query` and `swarm-metrics` show a pod's records next to the ones
the same service produced as a host unit.

View file

@ -146,7 +146,7 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
| an agent's claude login (`.credentials.json`) | `swarm-claude-login.service`, in its container, when an operator completes `claude auth login` from the agent's card in the swarm UI; it stores the file as a new version at `swarm/agents/<agent>/claude-credentials` under its own leaf, which may create and update that path and read nothing under an agent | the swarm secret store at that path; the agent's `hive-agent` reads it under the agent's own leaf every 30 seconds while it waits for a login and writes it to `~/.claude/.credentials.json` | the same read, co-located or not; nothing for an operator to place beyond the agent's store leaf. When the store's copy and the agent's differ the KV version decides: the agent installs only a version newer than the last it installed (`claude-credentials-version` under the harness dir), because claude rotates the refresh token in its own copy and the stored one goes stale. The agent ignores a stale or equal version, and a relogin writes a newer one — [claude-login.md](../../2-handbook/swarm/claude-login.md) |
| the queue responder's copy of its OIDC secret | the responder reads it out of the swarm secret store itself as it starts, under its own leaf, and again when authelia refuses it | the daemon's memory only; never on disk | same read, wherever authelia runs. Nothing for an operator to place beyond the responder's store leaf (`deploy.nats.authBaoClientCertFile`) |
| the queue container's journal forwarder's copy of the queue's OIDC secret | `swarm-journal-forwarder-oidc.service` inside the `swarm-nats` container reads it out of the swarm secret store under the responder's store leaf, and again every 10 minutes | `/run/swarm-journal-forwarder-oidc/client-secret` on the container's tmpfs, root `0400`, never on persistent disk; `LoadCredential` hands it to the collector | same unit, same path. After a reboot the fetch fails fast while the store is down and retries with a delay that grows to 5 minutes; the attempt that succeeds starts the collector, which isn't part of the container's boot, and it resumes from its saved journal cursor. Nothing for an operator to place beyond the responder's store leaf (`deploy.nats.authBaoClientCertFile`) |
| the CI runner, Grafana, log store, cache, forge and homeserver containers' journal forwarders' OIDC secrets | `swarm-journal-forwarder-oidc.service` inside each container reads its forwarder client's secret (`swarm.<service>.otel.clientId`) out of the swarm secret store under the store leaf the host already holds for that service, handed in as a system credential (bound in read-only, for the homeserver's), and again every 10 minutes | `/run/swarm-journal-forwarder-oidc/client-secret` on the container's tmpfs, root `0400`, never on persistent disk; `LoadCredential` hands it to the collector | same unit, same path. Nothing for an operator to place beyond those leaves (`deploy.bao.ciRunnerClientCertFile`, `deploy.bao.grafanaOidcClientCertFile`, `deploy.victorialogs.authBaoClientCertFile`, `deploy.bao.forgePublisherClientCertFile`, `deploy.bao.atticClientCertFile`, `deploy.matrix.ctlBaoClientCertFile`) |
| the CI runner, Grafana, cache, forge and homeserver containers' journal forwarders' OIDC secrets | `swarm-journal-forwarder-oidc.service` inside each container reads its forwarder client's secret (`swarm.<service>.otel.clientId`) out of the swarm secret store under the store leaf the host already holds for that service, handed in as a system credential (bound in read-only, for the homeserver's), and again every 10 minutes | `/run/swarm-journal-forwarder-oidc/client-secret` on the container's tmpfs, root `0400`, never on persistent disk; `LoadCredential` hands it to the collector | same unit, same path. Nothing for an operator to place beyond those leaves (`deploy.bao.ciRunnerClientCertFile`, `deploy.bao.grafanaOidcClientCertFile`, `deploy.bao.forgePublisherClientCertFile`, `deploy.bao.atticClientCertFile`, `deploy.matrix.ctlBaoClientCertFile`) |
| the metrics store container's journal forwarder's OIDC secret | `swarm-victoriametrics-forwarder-oidc.service` on the store's host reads its forwarder client's secret (`swarm.victoriametrics.otel.clientId`) out of the swarm secret store under the metrics store responder's leaf, and again every 10 minutes: the container has no network to reach the store | `/run/swarm-victoriametrics-forwarder-oidc/<id>.secret` on the host (tmpfs), root `0400`, never on persistent disk; bound into the container read-only, where `LoadCredential` hands it to the collector | same unit, same path. Nothing for an operator to place beyond that leaf (`deploy.victoriametrics.authBaoClientCertFile`) |
| the CI run poller's forge token | `swarm-controller`, with the forge's admin API, for its `ci-metrics` account, at start and in a five-minute pass | the swarm secret store at `swarm/services/ci-metrics/forge/token`; `swarm-ci-metrics` reads it once per pass under its own leaf and holds it in memory for that pass. When the store's token no longer matches the forge's, the controller's next pass mints a new one; until then the poller's forge calls answer 401, the unit fails and no cursor moves | nothing to place beyond the poller's leaf (`deploy.bao.ciMetricsClientCertFile`), on a host without the store |
| 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 |

View file

@ -189,19 +189,20 @@ swarm.
| `deploy.victorialogs.grafanaAuthPackage` | The `swarm-metrics-auth` build that runs as `swarm-logs-grafana-auth`. Set on its own: `deploy.victoriametrics.authPackage` doesn't reach it. |
| `swarm.victorialogs.domain` | Only to rename it. |
It listens on a unix socket in a network namespace of its own, on the hive
bridge so its journal forwarder can reach the swarm collector, and binds no host
port. Only the gateway's nginx can open the socket. It takes no credential of
its own: the gateway vhost is the only way in, and the collector is the only
intended writer.
It runs as a pod in the host's cluster ([the log store](../k8s/runtime.md#the-log-store))
and binds no host port. Its Service takes no credential of its own, so a
NetworkPolicy lets only the host's own traffic reach it. The gateway vhost, which
dials the Service by name, is the only way in for a hive, an agent or a
browser, and the collector is the only intended writer. A process on this host
can also reach the Service; see [Agent security](../../2-handbook/agents/security.md).
**Who may query.** `/select/logsql/` takes one of three credentials. An
agent presents its `swarm-agent.<agent>.<secret>` bearer, checked by
`swarm-logs-auth`. The agent must also hold the `logs` permission,
which is off by default; without it the answer is a 403 (`docs/5-project/process/conventions.md`, Permissions). Grafana's datasource presents the same bearer as its
metrics datasource, which `swarm-bao-grafana-metrics-bearer` creates, and a
second `swarm-metrics-auth` instance (`swarm-logs-grafana-auth`) on the log
store's host checks it against the same store path; the gateway tells it from
second `swarm-metrics-auth` instance (`swarm-logs-grafana-auth`, in the same pod as
`swarm-logs-auth`) checks it against the same store path; the gateway tells it from
the others by its shape, 64 hex digits. Anything else needs an operator's
authelia session. Because one bearer opens both read APIs, a rotation
(see [`credentials.md`](../../2-handbook/swarm/credentials.md)) restarts Grafana once, and the log store
@ -290,16 +291,16 @@ gateway either way.
The `swarm-bao`, `swarm-nats`, `swarm-builder`, `swarm-claude-login`,
`swarm-notify-router`, `swarm-review-classifier`, `swarm-ci-runner`, `swarm-grafana`,
`swarm-victorialogs`, `swarm-victoriametrics`, `swarm-authelia`, `swarm-attic`, `hive-forge`
`swarm-victoriametrics`, `swarm-authelia`, `swarm-attic`, `hive-forge`
and `hive-matrix` containers each run a collector of their own that forwards the container's
journal here, on a route and receiver per service
(`https://<swarm.otel.domain>/<container>/`), authenticated as an OIDC client
of that service's. The queue, builder, login minter, notification router and
classifier reuse the service's own client; the store, CI runner, Grafana, log store, metrics store,
classifier reuse the service's own client; the store, CI runner, Grafana, metrics store,
authelia, cache, forge and homeserver have a forwarder client of their own
(`swarm.<service>.otel.clientId`). Their records carry `service.name` (`bao`,
`nats`, `builder`, `claude-login`, `notify-router`, `review-classifier`, `ci-runner`,
`grafana`, `victorialogs`, `victoriametrics`, `authelia`, `attic`, `forgejo`,
`grafana`, `victoriametrics`, `authelia`, `attic`, `forgejo`,
`tuwunel`) and the `sender` of its own client id. The forwarder of all but the store's is
`nix/container-modules/swarm-journal-forwarder.nix`.

View file

@ -82,8 +82,8 @@ With both set, systemd creates the runtime directory under `/run/private/`
`RuntimeDirectoryPreserve=`). No unprivileged user can traverse that, so
nginx's `connect()` to a socket in it fails with `EACCES` whatever the
directory and socket modes are. A unit serving a socket to another user
runs as a static user instead (`swarm-controller`, `swarm-logs-auth`,
`swarm-metrics-auth`, `swarm-metrics-agent-auth`).
runs as a static user instead (`swarm-controller`, `swarm-metrics-auth`,
`swarm-metrics-agent-auth`).
`module-eval-core-toggle` fails on any `unix:` upstream of nginx owned by
such a unit.