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
11be43a2e9
commit
9b12532fc1
2 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.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue