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.
This commit is contained in:
parent
ba0df0ec82
commit
f54aae7927
4 changed files with 808 additions and 72 deletions
|
|
@ -42,7 +42,7 @@ A service gets manifests on the host whose configuration deploys it:
|
|||
The renderer reads the service's evaluated unit, not a copy of its settings:
|
||||
|
||||
- **Environment:** the unit's `environment`, including what other modules
|
||||
merge into it, minus `PATH`. A systemd `%d` becomes the credential
|
||||
merge into it, minus `PATH`. A systemd `%d`, here and in `ExecStart`'s arguments, becomes the credential
|
||||
directory it stands for. On a host with a hive collector, the OTLP endpoint
|
||||
variables of a hive-tier service point at it ([Pod logs and metrics](telemetry.md))
|
||||
instead; a swarm-tier producer, `swarm-ci-metrics`, keeps its own. The
|
||||
|
|
@ -80,7 +80,8 @@ commit.
|
|||
The YAML lands in the world-readable nix store, so it holds no credential.
|
||||
It names the Secret `<service>-credentials` and the credential ids as keys.
|
||||
It never names the host path the unit loads a credential from, and never its
|
||||
contents. Nothing here creates the Secret.
|
||||
contents. Nothing here creates the Secret: the unit `swarm-bao-store-auth` publishes
|
||||
the stores' ([the log store](runtime.md#the-log-store)).
|
||||
|
||||
A credential that holds a public CA file isn't a secret. `swarm-notify-router`'s
|
||||
`notify-router-bao-server-ca` and `swarm-ci-metrics`'s `bao-ca.pem` come from
|
||||
|
|
|
|||
|
|
@ -320,14 +320,41 @@ 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
|
||||
(`-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
|
||||
|
|
@ -370,9 +397,9 @@ writes to the store and Grafana that reads 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
|
||||
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.
|
||||
|
|
@ -391,14 +418,24 @@ shape of [the log store](#the-log-store). The gateway's vhost
|
|||
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`) as a list, and its
|
||||
`StateDirectory`, and the renderer reads the pod from those. The image holds
|
||||
(`-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
|
||||
|
|
@ -450,8 +487,8 @@ pushes to the store and Grafana that reads 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 store
|
||||
takes writes, deletes and reads with no credential, so a process on the host
|
||||
can use all three: see [Agent security](../../2-handbook/agents/security.md).
|
||||
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
|
||||
|
|
@ -459,6 +496,25 @@ pushes to the store and Grafana that reads it.
|
|||
`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
|
||||
|
|
@ -583,7 +639,9 @@ 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`
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ the rest of the cell says how.
|
|||
| `ssh-agents/sign/swarm-agent` (a signing call, nothing is stored) | the store's SSH CA mount (`ssh-agents`), when the agent's `hive-agent-ssh-cert` unit asks it to sign, which the operator's per-agent `ssh` switch allows the public key the unit generated in its own `/run`; the CA key is generated inside the store by `swarm-bao-agent-ssh-policy` | the agent, which keeps the key and the signed certificate in `/run` only; a target machine trusts the CA's public key by value | ✅ the certificate lasts 60 minutes; the CA is never replaced, and a target that holds a different CA key refuses every certificate | ✅ the agent signs again every 20 minutes |
|
||||
| `swarm/hives/<hive>/squid-selfcheck` | `swarm-controller`, in the same pass as the agents' credentials | the hive: `hive-c0re` and `squid-selfcheck-credential` (root) | ❌ never replaced: written only while the path holds nothing | ✅ `hive-c0re` every 30 seconds, the root unit every 10 minutes |
|
||||
| `swarm/services/k8s/agent-token` | `k3s-join-token-publish`, on the cluster's main node, as that node's hive: k3s's `agent-token`, written again whenever the file differs | a node that joins: `k3s-join-token`, as that node's hive, before k3s starts | ✅ at each start of the main node's k3s | ✅ at each start of the joining node's k3s |
|
||||
| `swarm/services/victorialogs/store-auth` | `swarm-bao-store-auth`, on the log store's host, as the `swarm-store-auth` principal: 32 random bytes as 64 hex digits, written only while the path holds nothing | the same unit, which hands it to the host's nginx and to the cluster; the log store's pod loads it as its `-httpAuth.password` | ❌ never replaced: to rotate, delete the leaf's metadata with a token that may and restart `swarm-bao-store-auth` | ✅ the unit reads it at each start and writes the nginx file and the Secret again when they differ; the store re-reads its file every two seconds |
|
||||
| `swarm/services/victoriametrics/store-auth` | `swarm-bao-store-auth`, on the metrics store's host, as the `swarm-store-auth` principal: 32 random bytes as 64 hex digits, written only while the path holds nothing | the same unit, which hands it to the host's nginx and to the cluster; the metrics store's pod loads it as its `-httpAuth.password` | ❌ never replaced: to rotate, delete the leaf's metadata with a token that may and restart `swarm-bao-store-auth` | ✅ the unit reads it at each start and writes the nginx file and the Secret again when they differ; the store re-reads its file every two seconds |
|
||||
| `swarm/hives/<hive>/oidc/client` | authelia, first boot, straight into the store | the hive | ❌ minted once, straight into the store; minted again only when the store holds none | ✅ re-read when authelia refuses it |
|
||||
| `swarm/services/<clientId>/oidc/client` | authelia | that service | must be stated | must be stated |
|
||||
| `swarm/services/ci-runner/registration-token` | `swarm-controller`, from the forge, at start and every 5 minutes | `swarm-bao-ci-runner` on the runner's host | ❌ the forge keeps one token until an admin resets it; the controller then writes the new one within 5 minutes | ✅ every 10 minutes; restarts the runner on a change |
|
||||
|
|
@ -127,6 +129,8 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
|
|||
| OIDC client secret, plaintext half | `authelia crypto hash generate --random` | the swarm secret store, at the path its reader fetches: `swarm/hives/<hive>/oidc/client`, `swarm/controller/swarm-controller/oidc/client` or `swarm/services/<client id>/oidc/client`. The bridge reads its own into `/run/swarm-authelia-bridge/client-secret` before each start. A container with no secret publisher identity keeps it in `/var/lib/authelia-swarm/oidc-clients/<id>.secret`; a file an earlier release left seeds the store once when it holds no value, and stays unused | nothing to place: readers fetch it from the store ([how](../../2-handbook/swarm/credentials.md#hive-level-secrets)) |
|
||||
| OIDC client secret, digest half | the same mint | `oidc-clients/<id>.digest` | authelia's own half; merged at runtime via `settingsFiles` |
|
||||
| the swarm collector's copy of its OIDC secret | `swarm-bao-otel-oidc.service` reads it out of the swarm secret store, **on every host that runs the collector and holds a store identity** | `/run/swarm-otel-oidc/<id>.secret` on the host's tmpfs, bind-mounted read-only into the `swarm-otel` container — never on persistent disk, so a reboot fetches it again | same unit, same path — one route, co-located or not. A collector with no store identity has `clientSecretFile == null`, its already-supported unauthenticated-push degrade — see [swarm-level secrets](../../2-handbook/swarm/credentials.md#swarm-level-secrets) |
|
||||
| the log store's listener credential | `swarm-bao-store-auth.service` creates it in the swarm secret store at `swarm/services/victorialogs/store-auth` when the store holds none, then copies it out, **on the host that runs the log store**. The grant is create and read, without update | `/var/lib/swarm-store-auth/victorialogs.conf` (root, `0600`, in a directory of `0700`): the `Authorization` header the vhost's store locations send, and `/var/lib/swarm-store-auth/victorialogs.password` (the same), from which the unit publishes the Secret `swarm-victorialogs-credentials`, key `store-auth`, which the store's pod mounts | nothing to copy: the vhost and the store are on one host. If the nginx file and the Secret hold different values, every request through the gateway answers 401 until the unit runs again; it writes the nginx file first and the Secret after |
|
||||
| the metrics store's listener credential | `swarm-bao-store-auth.service` creates it in the swarm secret store at `swarm/services/victoriametrics/store-auth` when the store holds none, then copies it out, **on the host that runs the metrics store**. The grant is create and read, without update | `/var/lib/swarm-store-auth/victoriametrics.conf` (root, `0600`, in a directory of `0700`): the `Authorization` header the vhost's store locations send, and `/var/lib/swarm-store-auth/victoriametrics.password` (the same), from which the unit publishes the Secret `swarm-victoriametrics-credentials`, key `store-auth`, which the store's pod mounts | nothing to copy: the vhost and the store are on one host. If the nginx file and the Secret hold different values, every request through the gateway answers 401 until the unit runs again; it writes the nginx file first and the Secret after |
|
||||
| Grafana's copy of its OIDC secret | `swarm-bao-grafana-oidc.service` reads it out of the swarm secret store, **on every host that runs Grafana** | `/run/swarm-grafana-secrets/<id>.secret` on the host's tmpfs, bind-mounted read-only into the `swarm-grafana` container — never on persistent disk, so a reboot fetches it again | same unit, same path — one route, co-located or not. Nothing for an operator to place beyond this host's store leaf, see [hive-level secrets](../../2-handbook/swarm/credentials.md#hive-level-secrets) |
|
||||
| Grafana's admin password | `swarm-bao-grafana-admin.service` creates it in the swarm secret store at `swarm/services/<grafana client id>/admin/password` when the store holds none, then copies it out, **on every host that runs Grafana**. Grafana's leaf may create that leaf but not update it, so the store keeps the first value, and the secret publisher can't write it. To rotate, run `bao kv metadata delete secret/swarm/services/<grafana client id>/admin/password` with a token that may, such as the root token (Grafana's, the publisher's and the controller's can't), then `systemctl restart swarm-bao-grafana-admin`; a plain `bao kv delete` isn't enough, see [the callout xkey's section](credentials.md#the-queues-callout-xkey) | `/run/swarm-grafana-secrets/admin-password` on the host's tmpfs, bind-mounted read-only into the `swarm-grafana` container, never on persistent disk: `security.admin_password` for a new database, and `grafana cli admin reset-admin-password` in `grafana.service`'s `preStart` for an existing one, on every start | same unit, same path. After a reboot the unit fetches the file again, and Grafana doesn't start until it exists, so it stays down rather than falling back to the upstream default `admin` |
|
||||
| Grafana's metrics bearer | `swarm-bao-grafana-metrics-bearer.service` creates it in the swarm secret store at `swarm/services/<grafana client id>/metrics/bearer` when the store holds none, then copies it out, **on every host that runs Grafana**. Same grant as the admin password, create without update. To rotate, run `bao kv metadata delete secret/swarm/services/<grafana client id>/metrics/bearer` with a token that may, then `systemctl restart swarm-bao-grafana-metrics-bearer` | `/run/swarm-grafana-secrets/metrics-bearer` on the host's tmpfs, bind-mounted read-only into the `swarm-grafana` container, holding `Bearer <value>`: the metrics datasource's `Authorization` header. The logs datasource sends the same header. `swarm-metrics-auth` on the metrics store's host, and a second instance on the log store's host (`swarm-logs-grafana-auth`), read the stored value themselves, each under its own leaf | same unit, same path. The unit restarts Grafana when the file changes |
|
||||
|
|
@ -198,6 +202,7 @@ login minter's, the forge host's and Grafana's, which reach more than one:
|
|||
| `swarm-archive-users`, `swarm-archive-prune`, `swarm-archive-check` and, with an S3 bucket, `swarm-archive` | `archiveClientCertFile` / `archiveClientKeyFile` | reads `swarm/services/archive/users/*`, `swarm/services/archive/restic/*` and `swarm/services/archive/s3/*`, lists `swarm/services/archive/users/` |
|
||||
| `swarm-ci-metrics` | `ciMetricsClientCertFile` / `ciMetricsClientKeyFile` | `swarm/services/ci-metrics/forge/token` and `swarm/services/<poller client id>/oidc/client` |
|
||||
| `swarm-bao-forge-oidc` and the forge's controller-token mint and its journal forwarder in its container | `forgePublisherClientCertFile` / `forgePublisherClientKeyFile` | writes `swarm/controller/swarm-controller/forge/token`; reads `swarm/services/<forge client id>/oidc/client` and `swarm/services/<forge forwarder client id>/oidc/client` |
|
||||
| `swarm-bao-store-auth` | `storeAuthClientCertFile` / `storeAuthClientKeyFile` | creates and reads `swarm/services/victorialogs/store-auth` and `swarm/services/victoriametrics/store-auth` |
|
||||
|
||||
The option names are `deploy.bao.<pair>`; the common names, what a missing leaf
|
||||
costs and how to place a leaf by hand are in
|
||||
|
|
|
|||
|
|
@ -105,8 +105,9 @@ whether or not that host runs the collector.
|
|||
|
||||
Neither is reachable except through the gateway: Grafana listens on a unix
|
||||
socket only the gateway's nginx can open, and VictoriaMetrics behind a Service
|
||||
that admits only the host's own traffic. VictoriaMetrics authenticates nothing
|
||||
itself; the `metrics.<swarm-domain>` vhost does it:
|
||||
that admits only the host's own traffic. VictoriaMetrics asks every request for
|
||||
a credential of its own, which the gateway's nginx supplies once the
|
||||
`metrics.<swarm-domain>` vhost has checked the caller:
|
||||
|
||||
- **The read API** (the Prometheus query, series, label and metadata
|
||||
routes): Grafana's datasource, an agent, or an operator. Grafana sends a
|
||||
|
|
@ -186,11 +187,12 @@ swarm.
|
|||
| `swarm.victorialogs.domain` | Only to rename it. |
|
||||
|
||||
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).
|
||||
and binds no host port. A NetworkPolicy lets only the host's own traffic reach its
|
||||
Service, and the store asks every request for a credential of its own
|
||||
([the stores' listener credential](../k8s/runtime.md#the-stores-listener-credential)).
|
||||
The gateway vhost, which dials the Service by name and supplies that credential
|
||||
after its own checks, is the way in for a hive, an agent or a browser, and the
|
||||
collector is the only intended writer.
|
||||
|
||||
**Who may query.** `/select/logsql/` takes one of three credentials. An
|
||||
agent presents its `swarm-agent.<agent>.<secret>` bearer, checked by
|
||||
|
|
|
|||
Loading…
Reference in a new issue