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 maia
commit dca4720b7b
34 changed files with 1385 additions and 746 deletions

1
Cargo.lock generated
View file

@ -5641,6 +5641,7 @@ dependencies = [
"axum",
"chrono",
"clap",
"futures-util",
"hive-log",
"mockall",
"serde",

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.

View file

@ -66,7 +66,6 @@
./glue-secret-publisher-bao-identity.nix
./glue-swarm-bao-otel-oidc-client.nix
./glue-swarm-otel-oidc-client.nix
./glue-victorialogs-otel-oidc-client.nix
./glue-victoriametrics-otel-oidc-client.nix
./swarm-archive.nix
./swarm-attic-options.nix

View file

@ -104,14 +104,12 @@ in
one backfill pass. Remove this definition.
'')
(lib.mkRemovedOptionModule [ "services" "hyperhive" "swarm" "victorialogs" "port" ] ''
VictoriaLogs listens on a unix socket in a network namespace of its own,
and the gateway reaches it there, so it binds no host port. Remove this
definition.
VictoriaLogs runs as a pod behind a Service the gateway dials, so it
binds no host port. Remove this definition.
'')
(lib.mkRemovedOptionModule [ "services" "hyperhive" "deploy" "victorialogs" "port" ] ''
VictoriaLogs listens on a unix socket in a network namespace of its own,
and the gateway reaches it there, so it binds no host port. Remove this
definition.
VictoriaLogs runs as a pod behind a Service the gateway dials, so it
binds no host port. Remove this definition.
'')
(lib.mkRemovedOptionModule [ "services" "hyperhive" "swarm" "victoriametrics" "port" ] ''
VictoriaMetrics listens on a unix socket in a network namespace of its

View file

@ -7,7 +7,7 @@
#
# Gated on authelia being HERE, not on this host running the cache: a client is
# a row in THIS host's provider config, the split
# ./glue-victorialogs-otel-oidc-client.nix makes for the same reason.
# ./glue-victoriametrics-otel-oidc-client.nix makes for the same reason.
{
lib,
config,

View file

@ -1,37 +0,0 @@
# Glue: register the log store container's journal forwarder as an OIDC
# client wherever authelia runs.
#
# ONE PAIRING PER FILE: that forwarder ← authelia, and nothing else.
# Without it authelia mints no secret, the publisher has nothing to copy into
# the store, and the forwarder's export is a 401.
#
# Gated on authelia being HERE, not on this host running the log store: a
# client is a row in THIS host's provider config, the split
# ./glue-swarm-bao-otel-oidc-client.nix makes for the same reason.
{
lib,
config,
...
}:
let
hyperhiveCfg = config.services.hyperhive;
clientId = hyperhiveCfg.swarm.victorialogs.otel.clientId;
in
{
config = lib.mkIf hyperhiveCfg.deploy.authelia.enable {
services.hyperhive.swarm.authelia.oidc.clients = [
{
id = clientId;
description = "HyperHive log store journal forwarder";
kind = "machine";
redirectUris = [ ];
# Its own id as its own permitted audience, the one the swarm
# collector's receiver for this container checks.
audience = [ clientId ];
# The receiver verifies the token offline against `/jwks.json`;
# authelia's default opaque handle fails there.
accessTokenSignedResponseAlg = "RS256";
}
];
};
}

View file

@ -129,13 +129,14 @@ let
"claude-login"
"nats"
"swarm-controller"
"victorialogs"
];
enabledServices = lib.filter (name: deployCfg.${name}.enable) swarmServices;
# The services whose data the module keeps in the cluster. Each puts its state
# label on this node.
stateful = lib.filterAttrs (_: svc: svc.enable) {
inherit (deployCfg) nats ci-metrics;
inherit (deployCfg) nats ci-metrics victorialogs;
};
in
{
@ -264,7 +265,7 @@ in
none of those pods.
- `hyperhive.darkest.space/state-<service>` for each service whose data the
cluster keeps: `nats` and `ci-metrics`, each when enabled. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
cluster keeps: `nats`, `ci-metrics` and `victorialogs`, each when enabled. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
- `hyperhive.darkest.space/entry`: the node the hosts' DNS points at.
- `svccontroller.k3s.cattle.io/enablelb`: with it on any node, the
service load balancer binds a published port on the labelled nodes

View file

@ -125,19 +125,21 @@ let
];
};
# The swarm services that run in the cluster. `unit` is the evaluated
# systemd unit the host runs today; nothing reads it unless `enable` holds.
# The swarm services that run in the cluster. `unit` is an evaluated systemd
# unit, or the `serviceConfig`, `environment` and `path` of one; nothing reads
# it unless `enable` holds.
# `healthEnv` names the variable that binds the daemon's /healthz and
# /readyz listener. `publicCredentials` maps the ids of the credentials that
# hold a public CA file to their key in the CA ConfigMap, and `publicFiles`
# the paths the unit names that hold one to theirs. `listener`, where a
# service has one, is the TCP port a Service publishes in the cluster and the
# directory the pod's init container writes the leaf to.
# service has one, is the TCP port a Service publishes and the directory the
# pod's init container writes the leaf to; without a `tlsDir` it is plain HTTP
# and no leaf is issued. `probe` is the path a service without a `healthEnv` is
# probed on, and `fsGroupChangePolicy` the pod's setting of that name.
# `ephemeralState` gives a service an `emptyDir` in place of a claim for its
# state directory: what it keeps there is re-derived at start. A pod starts on
# whatever volume it gets.
# `otlp` is where the pod pushes
# its telemetry: `"hive"` is the hive collector. A swarm-tier producer is
# `otlp` is where the pod pushes its telemetry: `"hive"` is the hive collector. A swarm-tier producer is
# `"own"` and keeps the route its unit names, because the hive collector
# stamps the `hive` label on what it forwards and a swarm-level series must
# not carry one (../swarm-otel.nix, the swarm tier's own pipeline).
@ -255,6 +257,44 @@ let
};
otlp = "own";
};
# The log store: the VictoriaLogs daemon alone, on a static local volume
# that is the old container's data directory. It holds no store identity
# and pushes no telemetry; its own `/metrics` is scraped through the
# gateway.
swarm-victorialogs = {
inherit (deployCfg.victorialogs) enable package unit;
daemon = "victoria-logs";
kind = "Deployment";
healthEnv = null;
probe.path = "/health";
etcFiles = [ ];
publicCredentials = { };
listener.port = deployCfg.victorialogs.servicePort;
localState = {
service = "victorialogs";
hostDir = deployCfg.victorialogs.hostDataDir;
};
# The first start gives the pod's group the tree the old container wrote;
# a later one looks at the root only.
fsGroupChangePolicy = "OnRootMismatch";
otlp = "none";
};
# The two `auth_request` responders of the log store's gateway vhost, which
# log in to the store under one role. They keep no state, so they run on any
# node. The Grafana responder is the second container of the pod, in `pod`.
swarm-logs-auth = {
inherit (deployCfg.victorialogs) enable;
package = deployCfg.victorialogs.authPackage;
unit = deployCfg.victorialogs.authUnit;
inherit (deployCfg.victorialogs) pod;
kind = "Deployment";
healthEnv = "SWARM_LOGS_AUTH_HEALTH_ADDR";
etcFiles = [ ];
publicCredentials."bao-ca.pem" = baoServerCaKey;
listener.port = deployCfg.victorialogs.authServicePort;
egress = [ "store" ];
otlp = "none";
};
};
# Where a pod pushes telemetry. A `"hive"` service pushes to the hive
@ -508,6 +548,9 @@ let
sc = unit.serviceConfig;
listener = svc.listener or { };
# A listener with a `tlsDir` serves TLS with a leaf the pod issues; one
# without serves plain HTTP, for a caller that is the node.
listenerTls = listener ? tlsDir;
publicFiles = svc.publicFiles or { };
daemon = svc.daemon or name;
baoRole = svc.baoRole or name;
@ -594,7 +637,7 @@ let
++ lib.optional (runtimeDir != null) runtimeDir
++ lib.optional (stateDir != null) stateDir
++ lib.attrNames publicFiles
++ lib.optional (listener != { }) listener.tlsDir
++ lib.optional listenerTls listener.tlsDir
++ map (f: "/etc/${f}") svc.etcFiles;
under = root: v: v == root || lib.hasPrefix "${root}/" v;
unmounted = lib.filterAttrs (_: v: lib.hasPrefix "/" v && !(lib.any (r: under r v) mountRoots)) env;
@ -690,7 +733,7 @@ let
name = "ca-trust";
configMap.name = caConfigMap;
}
++ lib.optional (listener != { }) {
++ lib.optional listenerTls {
name = "tls";
# In memory: the leaf's key never reaches the node's disk.
emptyDir.medium = "Memory";
@ -745,7 +788,7 @@ let
subPath = publicFiles.${path};
readOnly = true;
}) (lib.attrNames publicFiles)
++ lib.optional (listener != { }) tlsMount
++ lib.optional listenerTls tlsMount
++ lib.optional (runtimeDir != null) {
name = "runtime";
mountPath = runtimeDir;
@ -824,6 +867,24 @@ let
}
// lib.optionalAttrs (lib.tail execWords != [ ]) { args = lib.tail execWords; }
// lib.optionalAttrs (ports != [ ]) { inherit ports; }
# A daemon that has no health variable of ours (a third-party one) is
# probed on one path of its listener.
// lib.optionalAttrs (svc ? probe) {
livenessProbe = {
httpGet = {
inherit (svc.probe) path;
port = "api";
};
periodSeconds = 10;
};
readinessProbe = {
httpGet = {
inherit (svc.probe) path;
port = "api";
};
periodSeconds = 10;
};
}
// lib.optionalAttrs (svc.healthEnv != null) {
livenessProbe = {
httpGet = {
@ -906,7 +967,7 @@ let
containers = [
container
]
++ lib.optional (listener != { }) (
++ lib.optional listenerTls (
leafContainer
// {
name = "tls-renew";
@ -923,15 +984,16 @@ let
runAsGroup = serviceUser.gid;
fsGroup = serviceUser.gid;
seccompProfile.type = "RuntimeDefault";
};
}
// lib.optionalAttrs (svc ? fsGroupChangePolicy) { inherit (svc) fsGroupChangePolicy; };
}
// lib.optionalAttrs baoLogin { serviceAccountName = name; }
// lib.optionalAttrs (svc ? hostUsers && !svc.hostUsers) { hostUsers = false; }
// lib.optionalAttrs (localState != null) {
nodeSelector = labels.stateSelector localState.service;
}
// lib.optionalAttrs (listener != { } || extra.initContainers != [ ]) {
initContainers = lib.optional (listener != { }) leafContainer ++ extra.initContainers;
// lib.optionalAttrs (listenerTls || extra.initContainers != [ ]) {
initContainers = lib.optional listenerTls leafContainer ++ extra.initContainers;
}
// lib.optionalAttrs (extra.hostAliases != [ ]) { inherit (extra) hostAliases; }
// extra.podSpec;
@ -1007,7 +1069,13 @@ let
// lib.optionalAttrs (svc ? egress) {
"${name}/networkpolicy" = networkPolicyOf name svc.egress;
}
// lib.optionalAttrs (listener != { }) (listenerObjects name listener)
// lib.optionalAttrs (listener != { }) (
# A service with an egress policy has the ingress rule in that one.
if svc ? egress then
removeAttrs (listenerObjects name listener) [ "${name}/networkpolicy" ]
else
listenerObjects name listener
)
// lib.optionalAttrs baoLogin {
# Named after the service: the store's jwt role binds this account.
"${name}/serviceaccount" = {
@ -1063,10 +1131,10 @@ let
fail name "the unit names no OTLP endpoint of its own, which the pod would push to"
else if svc.healthEnv != null && unitEnv ? ${svc.healthEnv} then
fail name "the unit already sets ${svc.healthEnv}"
else if svc ? probe && (listener == { } || svc.healthEnv != null) then
fail name "has a probe and no listener, or a health variable as well"
else if svc ? egress && !(lib.all (r: hostPorts ? ${r}) svc.egress) then
fail name "egress names a host service the renderer has no port for (${lib.concatStringsSep ", " (lib.attrNames hostPorts)})"
else if svc ? egress && listener != { } then
fail name "has an egress policy and a listener, which would share one NetworkPolicy"
else if lib.head execWords != entrypoint then
fail name "ExecStart is not ${entrypoint} with plain arguments"
else if lib.any (w: lib.hasInfix "\"" w) execWords then
@ -1079,7 +1147,7 @@ let
{
inherit objects image;
# What the pod's other containers run.
extraImages = lib.optional (listener != { }) leafImage ++ extra.images;
extraImages = lib.optional listenerTls leafImage ++ extra.images;
};
enabled = lib.mapAttrs workload (lib.filterAttrs (_: svc: svc.enable) services);

View file

@ -158,11 +158,11 @@ let
}
];
# The log store's auth responders: the agent one checks the secret an agent
# presents against the one stored for it (the same `+` leaf as the queue
# responder's) and reads the agent's mirrored `logs`/`metrics` grant, the other checks the bearer Grafana presents against
# Grafana's metrics bearer; and the store container's journal forwarder
# reads its own client secret under the same leaf. Nothing else.
# The log store's auth responders, which run in one pod under one role: the
# agent one checks the secret an agent presents against the one stored for it
# (the same `+` leaf as the queue responder's) and reads the agent's mirrored
# `logs`/`metrics` grant, the other checks the bearer Grafana presents against
# Grafana's metrics bearer. Nothing else.
logsAuthReaders = [
{
name = "swarm-logs-auth";
@ -171,9 +171,7 @@ let
policyText =
readStanza "${credentialMountPath}/data/swarm/agents/+/queue"
+ readStanza "${credentialMountPath}/data/swarm/agents/+/observability"
+ readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}"
# The journal forwarder in the store's container, under this same leaf.
+ readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.victorialogs.otel.clientId}/oidc/client";
+ readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}";
}
];
@ -418,6 +416,9 @@ let
++ reviewClassifierReaders
++ claudeLoginWriters
++ ciMetricsReaders
# The log store's two responders hold one role, under the ServiceAccount of
# their pod (./k8s/render.nix, `swarm-logs-auth`).
++ logsAuthReaders
++ [ { name = controllerPolicyName; } ]
# The queue's pod holds both of its roles under one ServiceAccount: the
# server's leaf is issued with `swarm-nats`, and the responder reads its

View file

@ -242,9 +242,8 @@ in
swarm-stt = {
clientId = hyperhiveCfg.swarm.stt.clientId;
};
# The forwarders in ./swarm-attic.nix, ./swarm-ci-runner.nix,
# ./swarm-grafana.nix and ./swarm-victorialogs.nix, each authenticated as a
# client of its own.
# The forwarders in ./swarm-attic.nix, ./swarm-ci-runner.nix and
# ./swarm-grafana.nix, each authenticated as a client of its own.
swarm-attic = {
clientId = hyperhiveCfg.swarm.attic.otel.clientId;
};
@ -254,9 +253,6 @@ in
swarm-grafana = {
clientId = hyperhiveCfg.swarm.grafana.otel.clientId;
};
swarm-victorialogs = {
clientId = hyperhiveCfg.swarm.victorialogs.otel.clientId;
};
# The forwarders in ./hive-forge/default.nix and ./hive-matrix.nix, each
# authenticated as a client of its own.
hive-forge = {

View file

@ -250,8 +250,8 @@ let
# Every container with a `serviceProducers` entry (`swarm-bao`, `swarm-nats`,
# `swarm-builder`, `swarm-claude-login`, `swarm-notify-router`,
# `swarm-review-classifier`, `swarm-ci-runner`, `swarm-grafana`,
# `swarm-victorialogs`, `hive-forge`, `hive-matrix`, `swarm-victoriametrics`,
# `swarm-authelia`, `swarm-attic`) forwards its own
# `hive-forge`, `hive-matrix`, `swarm-victoriametrics`, `swarm-authelia`,
# `swarm-attic`) forwards its own
# journal from its own collector, so this receiver never sees their units.
hostJournalDir = "/var/log/journal";
hostJournalMount = "/run/host-journal";

View file

@ -55,13 +55,12 @@ let
hyperhiveCfg.swarm.notify-router.clientId
# The speech-to-text service, which reads it itself inside its container.
hyperhiveCfg.swarm.stt.clientId
# The journal forwarders in the CI runner's, Grafana's, the log store's,
# the cache's, the forge's and the homeserver's containers, each reading it
# inside its container.
# The journal forwarders in the CI runner's, Grafana's, the cache's, the
# forge's and the homeserver's containers, each reading it inside its
# container.
hyperhiveCfg.swarm.attic.otel.clientId
hyperhiveCfg.swarm.ci-runner.otel.clientId
hyperhiveCfg.swarm.grafana.otel.clientId
hyperhiveCfg.swarm.victorialogs.otel.clientId
hyperhiveCfg.swarm.forge.otel.clientId
hyperhiveCfg.swarm.matrix.otel.clientId
# The metrics store container's journal forwarder, whose host reads it.

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