the queue's exporter asks every request for a login the gateway supplies
This commit is contained in:
parent
f54aae7927
commit
893b693b46
11 changed files with 488 additions and 133 deletions
|
|
@ -256,6 +256,30 @@ strategy, and the removed container stops before the pod can start.
|
||||||
cluster's policy engine always admits traffic from an address of the node, so
|
cluster's policy engine always admits traffic from an address of the node, so
|
||||||
the gateway and the kubelet's probes reach the pod, and a pod of the cluster,
|
the gateway and the kubelet's probes reach the pod, and a pod of the cluster,
|
||||||
or a client of the bridge that the host forwards, doesn't reach the exporter.
|
or a client of the bridge that the host forwards, doesn't reach the exporter.
|
||||||
|
- **The exporter's login.** The node's processes reach the exporter too, so it
|
||||||
|
asks every request for a login. The exporter's container runs with
|
||||||
|
`-http_user swarm-exporter` and `-http_pass $(EXPORTER_HASH)`, the variable
|
||||||
|
coming from the key `hash` of the Secret `swarm-nats-exporter-auth`. The
|
||||||
|
exporter's flag takes no file, and it treats a value as bcrypt only when it
|
||||||
|
starts with `$2a$` (`exporter/exporter.go`, `bcryptPrefix`, in 0.15.0), so the
|
||||||
|
command line, which anyone who reads the pod spec or `/proc` sees, carries a
|
||||||
|
`$2a$11$` hash: cost 11 is the default of `nats server passwd`, and a hash of
|
||||||
|
a 64-digit random password is no credential. An exporter whose Secret is
|
||||||
|
missing doesn't start; it never runs open. TLS client verification isn't an
|
||||||
|
option in 0.15.0: `-tlscacert` sets the client CA pool and leaves `ClientAuth`
|
||||||
|
at `NoClientCert` (`exporter/exporter.go`), so the exporter never asks for a client certificate.
|
||||||
|
The unit `swarm-bao-store-auth` creates the password in the swarm
|
||||||
|
secret store at `swarm/services/nats/exporter-auth`, under the same
|
||||||
|
`swarm-store-auth` principal as the stores' with one more create-and-read
|
||||||
|
leaf, makes the hash with `htpasswd` (the password on stdin, never an
|
||||||
|
argument), and writes the password's `Authorization` header to
|
||||||
|
`/var/lib/swarm-store-auth/nats.conf`, which the gateway's `/metrics`
|
||||||
|
location `include`s in place of the caller's header. Without that file's
|
||||||
|
content the location sends no login and the exporter answers 401, so a
|
||||||
|
gateway that lacks it fails closed. A host that runs the queue gets the unit
|
||||||
|
and the leaf by default, with no option to name. Rotating works as for the
|
||||||
|
stores, and the exporter reads the hash as it starts, so the queue's pod
|
||||||
|
restarts after it.
|
||||||
- **The leaf.** `tls-issue` logs in to the store with the pod's token as the
|
- **The leaf.** `tls-issue` logs in to the store with the pod's token as the
|
||||||
role `swarm-nats` and issues the server's leaf from the same script as the
|
role `swarm-nats` and issues the server's leaf from the same script as the
|
||||||
host's `swarm-bao-nats-tls`. The key lands in a volume in memory. The
|
host's `swarm-bao-nats-tls`. The key lands in a volume in memory. The
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ the rest of the cell says how.
|
||||||
<!-- vale write-good.Passive = NO -->
|
<!-- vale write-good.Passive = NO -->
|
||||||
|
|
||||||
| store path | minter | reader | automatic re-mint | automatic re-pull |
|
| store path | minter | reader | automatic re-mint | automatic re-pull |
|
||||||
| ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| `swarm/agents/<agent>/matrix/main` | `swarm-controller`, at agent creation and every 5 minutes | the agent | ✅ when missing or rejected by the homeserver | ✅ the daemon restarts within 5 minutes of a rejection |
|
| `swarm/agents/<agent>/matrix/main` | `swarm-controller`, at agent creation and every 5 minutes | the agent | ✅ when missing or rejected by the homeserver | ✅ the daemon restarts within 5 minutes of a rejection |
|
||||||
| `swarm/agents/<agent>/matrix/<account>` | `swarm-controller`, from a credential you hand it | the agent | must be stated | ✅ retried within 2 to 16 minutes after a rejection |
|
| `swarm/agents/<agent>/matrix/<account>` | `swarm-controller`, from a credential you hand it | the agent | must be stated | ✅ retried within 2 to 16 minutes after a rejection |
|
||||||
| `swarm/agents/<agent>/matrix-recovery/<account>` | `swarm-controller`, a random passphrase per account | the agent | ❌ never replaced: the account's key backup opens only with this passphrase | ❌ read when the account comes up |
|
| `swarm/agents/<agent>/matrix-recovery/<account>` | `swarm-controller`, a random passphrase per account | the agent | ❌ never replaced: the account's key backup opens only with this passphrase | ❌ read when the account comes up |
|
||||||
|
|
@ -44,6 +44,7 @@ the rest of the cell says how.
|
||||||
| `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/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/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/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/services/nats/exporter-auth` | `swarm-bao-store-auth`, on the queue'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 the password to the host's nginx and its bcrypt hash to the cluster; the queue's exporter takes the hash as its `-http_pass` | ❌ never replaced: to rotate, delete the leaf's metadata with a token that may, restart `swarm-bao-store-auth`, then restart the queue's pod, which reads the hash only as it starts | ✅ the unit reads it at each start and writes the nginx file, the hash and the Secret again when they differ; a hash is made again only when the password changed |
|
||||||
| `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/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/<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 |
|
| `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 |
|
||||||
|
|
@ -121,7 +122,7 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
|
||||||
### Swarm-level — one of each per swarm
|
### Swarm-level — one of each per swarm
|
||||||
|
|
||||||
| secret | generated by | lives at | hive elsewhere |
|
| secret | generated by | lives at | hive elsewhere |
|
||||||
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| swarm-services root CA (cert + key) | `swarm-bao.nix`'s granting unit, inside the store's `pki` mount | the **key** never leaves the mount; the **cert** lands at `/var/lib/swarm-bao-services-pki/services-root.pem` (0644) and at `/var/lib/hive-tls/swarm-services-root.pem` on every hive | nothing to copy — every hive receives the cert with the leaf it asks the store for, or from `pki/ca/pem` where it fronts no swarm name and needs a store identity |
|
| swarm-services root CA (cert + key) | `swarm-bao.nix`'s granting unit, inside the store's `pki` mount | the **key** never leaves the mount; the **cert** lands at `/var/lib/swarm-bao-services-pki/services-root.pem` (0644) and at `/var/lib/hive-tls/swarm-services-root.pem` on every hive | nothing to copy — every hive receives the cert with the leaf it asks the store for, or from `pki/ca/pem` where it fronts no swarm name and needs a store identity |
|
||||||
| authelia session, JWT, storage-encryption and OIDC HMAC keys | `authelia-swarm-secrets` in authelia's container. It stores each in the swarm secret store at `swarm/services/swarm-authelia/keys/<name>` when the store holds none: the value of the key an earlier release generated, or a new one when there is no such file. The files stay on disk. While the store is down, refuses the login, or fails the read of a leaf (a refusal, a timeout, an error), the unit runs on the files, logs the store's error, and writes nothing to the store; the unit seeds or mints only a leaf the store reports as absent. A container with no secret publisher identity generates the files, as before | `/var/lib/authelia-swarm/{session,jwt,storage-encryption,oidc-hmac}.key` | nothing to place: the publisher's store leaf is the one in the row below. A store that stays unreachable on a start with no key file keeps authelia from starting |
|
| authelia session, JWT, storage-encryption and OIDC HMAC keys | `authelia-swarm-secrets` in authelia's container. It stores each in the swarm secret store at `swarm/services/swarm-authelia/keys/<name>` when the store holds none: the value of the key an earlier release generated, or a new one when there is no such file. The files stay on disk. While the store is down, refuses the login, or fails the read of a leaf (a refusal, a timeout, an error), the unit runs on the files, logs the store's error, and writes nothing to the store; the unit seeds or mints only a leaf the store reports as absent. A container with no secret publisher identity generates the files, as before | `/var/lib/authelia-swarm/{session,jwt,storage-encryption,oidc-hmac}.key` | nothing to place: the publisher's store leaf is the one in the row below. A store that stays unreachable on a start with no key file keeps authelia from starting |
|
||||||
| authelia OIDC issuer key (RSA) | same unit, same store path (`oidc-issuer`) | `/var/lib/authelia-swarm/oidc-issuer.key` | same — relying parties verify against the **public** half at `/jwks.json` |
|
| authelia OIDC issuer key (RSA) | same unit, same store path (`oidc-issuer`) | `/var/lib/authelia-swarm/oidc-issuer.key` | same — relying parties verify against the **public** half at `/jwks.json` |
|
||||||
|
|
@ -131,6 +132,7 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
|
||||||
| 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 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 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 |
|
| 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 |
|
||||||
|
| the queue exporter's listener credential | `swarm-bao-store-auth.service` creates it in the swarm secret store at `swarm/services/nats/exporter-auth` when the store holds none, then copies it out, **on the host that runs the queue**. The grant is create and read, without update | `/var/lib/swarm-store-auth/nats.conf` (root, `0600`, in a directory of `0700`): the `Authorization` header the gateway's `/metrics` location for the queue sends; `/var/lib/swarm-store-auth/nats.password` (the password) and `/var/lib/swarm-store-auth/nats.hash` (its bcrypt hash, from which the unit publishes the Secret `swarm-nats-exporter-auth`, key `hash`, which the exporter container reads as `EXPORTER_HASH`). The password reaches nothing but the host: the Secret and the pod's command line hold the hash | nothing to copy: the vhost and the pod are on one host. An nginx file that doesn't match the hash makes the gateway's scrape answer 401 until the unit runs again; the exporter reads the hash as it starts, so a rotated password also needs a restart of the queue's pod |
|
||||||
| 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 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 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 |
|
| 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 |
|
||||||
|
|
@ -202,7 +204,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-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-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-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` |
|
| `swarm-bao-store-auth` | `storeAuthClientCertFile` / `storeAuthClientKeyFile` | creates and reads `swarm/services/victorialogs/store-auth`, `swarm/services/victoriametrics/store-auth` and `swarm/services/nats/exporter-auth` |
|
||||||
|
|
||||||
The option names are `deploy.bao.<pair>`; the common names, what a missing leaf
|
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
|
costs and how to place a leaf by hand are in
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ let
|
||||||
swarm-bao-ci-runner = deployCfg.ci-runner.enable;
|
swarm-bao-ci-runner = deployCfg.ci-runner.enable;
|
||||||
# ./k8s/store-credentials.nix
|
# ./k8s/store-credentials.nix
|
||||||
swarm-bao-store-auth =
|
swarm-bao-store-auth =
|
||||||
(deployCfg.victorialogs.enable || deployCfg.victoriametrics.enable)
|
(deployCfg.victorialogs.enable || deployCfg.victoriametrics.enable || deployCfg.nats.enable)
|
||||||
&& deployCfg.k8s.enable
|
&& deployCfg.k8s.enable
|
||||||
&& hyperhiveCfg.k8s.enable
|
&& hyperhiveCfg.k8s.enable
|
||||||
&& havePair baoDeploy.storeAuthClientCertFile baoDeploy.storeAuthClientKeyFile;
|
&& havePair baoDeploy.storeAuthClientCertFile baoDeploy.storeAuthClientKeyFile;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
# The listener credential of the Victoria stores the cluster runs: the unit that
|
# The listener credentials of the Victoria stores the cluster runs and of the
|
||||||
# creates it in the swarm secret store when the store holds none, hands it to
|
# queue's exporter: the unit that creates each in the swarm secret store when it
|
||||||
# the gateway's nginx and publishes it to the cluster as the Secret the store's
|
# holds none, hands it to the gateway's nginx and publishes it to the cluster as
|
||||||
# pod loads its password from. The store's flags and the locations that send it
|
# the Secret the pod reads it from (the store's password, the exporter's bcrypt
|
||||||
# are in ../swarm-victorialogs.nix and ../swarm-victoriametrics.nix; ../lib/store-auth.nix names what they
|
# hash). The stores' flags and the locations that send the credential are in
|
||||||
# share. docs/4-implementation/k8s/runtime.md has the design.
|
# ../swarm-victorialogs.nix and ../swarm-victoriametrics.nix, the exporter's in
|
||||||
|
# ../swarm-nats.nix; ../lib/store-auth.nix names what they share.
|
||||||
|
# docs/4-implementation/k8s/runtime.md has the design.
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
|
|
@ -26,6 +28,11 @@ let
|
||||||
lib.optional deployCfg.victorialogs.enable "victorialogs"
|
lib.optional deployCfg.victorialogs.enable "victorialogs"
|
||||||
++ lib.optional deployCfg.victoriametrics.enable "victoriametrics";
|
++ lib.optional deployCfg.victoriametrics.enable "victoriametrics";
|
||||||
|
|
||||||
|
# The queue's exporter runs in the queue's pod.
|
||||||
|
exporterOn = deployCfg.nats.enable;
|
||||||
|
exporter = storeAuth.exporter;
|
||||||
|
credentialNames = stores ++ lib.optional exporterOn "the queue's exporter";
|
||||||
|
|
||||||
haveIdentity =
|
haveIdentity =
|
||||||
baoDeploy.storeAuthClientCertFile != null && baoDeploy.storeAuthClientKeyFile != null;
|
baoDeploy.storeAuthClientCertFile != null && baoDeploy.storeAuthClientKeyFile != null;
|
||||||
|
|
||||||
|
|
@ -43,12 +50,13 @@ let
|
||||||
(storeAuth.passwordFile store)
|
(storeAuth.passwordFile store)
|
||||||
(storeAuth.nginxFile store)
|
(storeAuth.nginxFile store)
|
||||||
(storeAuth.secretName store)
|
(storeAuth.secretName store)
|
||||||
|
storeAuth.user
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config = lib.mkIf (stores != [ ]) (
|
config = lib.mkIf (stores != [ ] || exporterOn) (
|
||||||
lib.mkMerge [
|
lib.mkMerge [
|
||||||
{
|
{
|
||||||
# The files exist before nginx first reads its configuration, because
|
# The files exist before nginx first reads its configuration, because
|
||||||
|
|
@ -59,7 +67,8 @@ in
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d ${storeAuth.dir} 0700 root root - -"
|
"d ${storeAuth.dir} 0700 root root - -"
|
||||||
]
|
]
|
||||||
++ map (store: "f ${storeAuth.nginxFile store} 0600 root root -") stores;
|
++ map (store: "f ${storeAuth.nginxFile store} 0600 root root -") stores
|
||||||
|
++ lib.optional exporterOn "f ${exporter.nginxFile} 0600 root root -";
|
||||||
}
|
}
|
||||||
|
|
||||||
(lib.mkIf (node.enable && k8sCfg.enable) {
|
(lib.mkIf (node.enable && k8sCfg.enable) {
|
||||||
|
|
@ -67,7 +76,7 @@ in
|
||||||
{
|
{
|
||||||
assertion = haveIdentity;
|
assertion = haveIdentity;
|
||||||
message = ''
|
message = ''
|
||||||
The ${lib.concatStringsSep " and " stores} the cluster runs takes a credential, which a unit
|
The ${lib.concatStringsSep " and " credentialNames} the cluster runs takes a credential, which a unit
|
||||||
creates in the swarm secret store and publishes under the identity
|
creates in the swarm secret store and publishes under the identity
|
||||||
services.hyperhive.deploy.bao.storeAuthClientCertFile and
|
services.hyperhive.deploy.bao.storeAuthClientCertFile and
|
||||||
storeAuthClientKeyFile name (the leaf the store mints where
|
storeAuthClientKeyFile name (the leaf the store mints where
|
||||||
|
|
@ -77,7 +86,7 @@ in
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.swarm-bao-store-auth = lib.mkIf haveIdentity {
|
systemd.services.swarm-bao-store-auth = lib.mkIf haveIdentity {
|
||||||
description = "create the Victoria stores' listener credential in the swarm secret store if absent, and publish it";
|
description = "create the Victoria stores' and the queue exporter's listener credentials in the swarm secret store if absent, and publish them";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
after = [
|
after = [
|
||||||
|
|
@ -87,8 +96,10 @@ in
|
||||||
++ storeContainer;
|
++ storeContainer;
|
||||||
path = [
|
path = [
|
||||||
baoDeploy.package
|
baoDeploy.package
|
||||||
|
pkgs.apacheHttpd
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
pkgs.gnugrep
|
pkgs.gnugrep
|
||||||
|
pkgs.gnused
|
||||||
pkgs.kubectl
|
pkgs.kubectl
|
||||||
pkgs.openssl
|
pkgs.openssl
|
||||||
pkgs.systemd
|
pkgs.systemd
|
||||||
|
|
@ -125,17 +136,20 @@ in
|
||||||
openssl rand -hex 32
|
openssl rand -hex 32
|
||||||
}
|
}
|
||||||
|
|
||||||
# <store> <leaf> <password file> <nginx file> <secret>. The store's
|
# <store> <leaf> <password file> <nginx file> <secret> <user>. The
|
||||||
# value wins and a leaf that holds none is created, so the first
|
# store's value wins and a leaf that holds none is created, so the
|
||||||
# password stored is the one every later run reads. The nginx file
|
# first password stored is the one every later run reads. The nginx
|
||||||
# is written first: it is what the gateway needs before the store
|
# file is written first: it is what the gateway needs before the
|
||||||
# answers anyone, and it needs nothing of the cluster.
|
# store answers anyone, and it needs nothing of the cluster.
|
||||||
|
# `password_changed` tells the exporter's hash step that the
|
||||||
|
# password file was rewritten.
|
||||||
reload=0
|
reload=0
|
||||||
|
password_changed=0
|
||||||
publish() {
|
publish() {
|
||||||
local store="$1" leaf="$2" password_file="$3" nginx_file="$4" secret="$5"
|
local store="$1" leaf="$2" password_file="$3" nginx_file="$4" secret="$5" user="$6"
|
||||||
local password directive
|
local password directive
|
||||||
password="$(store_seeded "$leaf" /nonexistent mint_password)" || return 1
|
password="$(store_seeded "$leaf" /nonexistent mint_password)" || return 1
|
||||||
directive="proxy_set_header Authorization \"Basic $(printf '%s:%s' ${lib.escapeShellArg storeAuth.user} "$password" | base64 -w0)\";"
|
directive="proxy_set_header Authorization \"Basic $(printf '%s:%s' "$user" "$password" | base64 -w0)\";"
|
||||||
|
|
||||||
if secret_differs "$nginx_file" "$directive"; then
|
if secret_differs "$nginx_file" "$directive"; then
|
||||||
atomic_write_secret 0600 root:root "$nginx_file" "$directive"
|
atomic_write_secret 0600 root:root "$nginx_file" "$directive"
|
||||||
|
|
@ -145,10 +159,39 @@ in
|
||||||
fi
|
fi
|
||||||
if secret_differs "$password_file" "$password"; then
|
if secret_differs "$password_file" "$password"; then
|
||||||
atomic_write_secret 0600 root:root "$password_file" "$password"
|
atomic_write_secret 0600 root:root "$password_file" "$password"
|
||||||
|
password_changed=1
|
||||||
fi
|
fi
|
||||||
echo "the credential of $store is at $nginx_file and $password_file; the Secret $secret follows."
|
echo "the credential of $store is at $nginx_file and $password_file; the Secret $secret follows."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# <password file> <hash file>. The exporter takes the hash of its
|
||||||
|
# password on its command line, so that is all the cluster is given.
|
||||||
|
# `htpasswd` reads the password from stdin, never from an argument,
|
||||||
|
# and writes `$2y$`, which the exporter would take for a plain
|
||||||
|
# password (it treats only `$2a$` as bcrypt): the prefix is
|
||||||
|
# rewritten, and a hash that is not `$2a$<cost>$` and 60 characters
|
||||||
|
# stops the unit. A new hash only when there is none or the
|
||||||
|
# password changed, since each carries a fresh salt.
|
||||||
|
exporter_hash() {
|
||||||
|
local password_file="$1" hash_file="$2" hash
|
||||||
|
if [ "$password_changed" != 1 ] && [ -s "$hash_file" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
hash="$(htpasswd -niBC ${toString exporter.cost} x < "$password_file" | cut -d: -f2- | sed 's/^[$]2y[$]/$2a$/')"
|
||||||
|
case "$hash" in
|
||||||
|
'${exporter.hashPrefix}${toString exporter.cost}$'*) ;;
|
||||||
|
*)
|
||||||
|
echo 'htpasswd did not give a $2a$<cost>$ hash' >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if [ "''${#hash}" != 60 ]; then
|
||||||
|
echo "the hash is ''${#hash} characters, not 60" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
atomic_write_secret 0600 root:root "$hash_file" "$hash"
|
||||||
|
}
|
||||||
|
|
||||||
store_init
|
store_init
|
||||||
store_login
|
store_login
|
||||||
if [ "$STORE_UP" != 1 ]; then
|
if [ "$STORE_UP" != 1 ]; then
|
||||||
|
|
@ -156,6 +199,24 @@ in
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
${lib.concatMapStrings publish stores}
|
${lib.concatMapStrings publish stores}
|
||||||
|
${lib.optionalString exporterOn ''
|
||||||
|
publish ${
|
||||||
|
lib.escapeShellArgs [
|
||||||
|
"nats-exporter"
|
||||||
|
"secret/${exporter.leaf}"
|
||||||
|
exporter.passwordFile
|
||||||
|
exporter.nginxFile
|
||||||
|
exporter.secretName
|
||||||
|
exporter.user
|
||||||
|
]
|
||||||
|
}
|
||||||
|
exporter_hash ${
|
||||||
|
lib.escapeShellArgs [
|
||||||
|
exporter.passwordFile
|
||||||
|
exporter.hashFile
|
||||||
|
]
|
||||||
|
}
|
||||||
|
''}
|
||||||
|
|
||||||
# A running nginx reads its files at a reload; one that is not
|
# A running nginx reads its files at a reload; one that is not
|
||||||
# running reads them as it starts.
|
# running reads them as it starts.
|
||||||
|
|
@ -172,6 +233,12 @@ in
|
||||||
--dry-run=client --output=yaml \
|
--dry-run=client --output=yaml \
|
||||||
| kubectl --namespace ${k8sCfg.namespace} apply --server-side --force-conflicts --filename=-
|
| kubectl --namespace ${k8sCfg.namespace} apply --server-side --force-conflicts --filename=-
|
||||||
'') stores}
|
'') stores}
|
||||||
|
${lib.optionalString exporterOn ''
|
||||||
|
kubectl --namespace ${k8sCfg.namespace} create secret generic ${exporter.secretName} \
|
||||||
|
--from-literal=${exporter.hashKey}="$(< ${exporter.hashFile})" \
|
||||||
|
--dry-run=client --output=yaml \
|
||||||
|
| kubectl --namespace ${k8sCfg.namespace} apply --server-side --force-conflicts --filename=-
|
||||||
|
''}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,26 @@ rec {
|
||||||
# The Secret the store's pod loads its credentials from
|
# The Secret the store's pod loads its credentials from
|
||||||
# (../k8s/render.nix names it `<service>-credentials`).
|
# (../k8s/render.nix names it `<service>-credentials`).
|
||||||
secretName = store: "swarm-${store}-credentials";
|
secretName = store: "swarm-${store}-credentials";
|
||||||
|
|
||||||
|
# The queue's exporter takes the same kind of login, with a difference: its
|
||||||
|
# flag takes no file, so the pod gets the password's bcrypt hash from the
|
||||||
|
# Secret `exporter.secretName` (key `hashKey`, environment variable
|
||||||
|
# `hashEnv`, argument `-http_pass`), and the gateway's `/metrics` location
|
||||||
|
# for the queue sends the password itself in the header `exporter.nginxFile`
|
||||||
|
# sets. The password and the hash are files only root reads. `cost` is NATS's
|
||||||
|
# own default for `nats server passwd`; the exporter compares with
|
||||||
|
# `bcrypt.CompareHashAndPassword`, which reads the cost from the hash, and
|
||||||
|
# only for a value that starts with `$2a$`.
|
||||||
|
exporter = {
|
||||||
|
user = "swarm-exporter";
|
||||||
|
leaf = "swarm/services/nats/exporter-auth";
|
||||||
|
passwordFile = "${dir}/nats.password";
|
||||||
|
nginxFile = "${dir}/nats.conf";
|
||||||
|
hashFile = "${dir}/nats.hash";
|
||||||
|
secretName = "swarm-nats-exporter-auth";
|
||||||
|
hashKey = "hash";
|
||||||
|
hashEnv = "EXPORTER_HASH";
|
||||||
|
cost = 11;
|
||||||
|
hashPrefix = "$2a$";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ let
|
||||||
# (`swarm-bao-store-auth`, ./k8s/store-credentials.nix): it creates each
|
# (`swarm-bao-store-auth`, ./k8s/store-credentials.nix): it creates each
|
||||||
# credential when the store holds none and reads it back, `create` without
|
# credential when the store holds none and reads it back, `create` without
|
||||||
# `update`, so a stored value is never replaced. One principal for both
|
# `update`, so a stored value is never replaced. One principal for both
|
||||||
# stores, a leaf each.
|
# stores and the queue's exporter, a leaf each.
|
||||||
storeAuthWriters = [
|
storeAuthWriters = [
|
||||||
{
|
{
|
||||||
name = "swarm-store-auth";
|
name = "swarm-store-auth";
|
||||||
|
|
@ -376,7 +376,8 @@ let
|
||||||
[
|
[
|
||||||
"victorialogs"
|
"victorialogs"
|
||||||
"victoriametrics"
|
"victoriametrics"
|
||||||
];
|
]
|
||||||
|
+ createReadStanza "${credentialMountPath}/data/${storeAuth.exporter.leaf}";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2051,10 +2051,12 @@ in
|
||||||
default = "swarm-store-auth";
|
default = "swarm-store-auth";
|
||||||
description = ''
|
description = ''
|
||||||
Subject the store's `swarm-store-auth` cert-auth role accepts: the
|
Subject the store's `swarm-store-auth` cert-auth role accepts: the
|
||||||
identity the unit that publishes the log store's and the metrics store's
|
identity the unit that publishes the log store's, the metrics store's and the
|
||||||
listener credentials presents from the host (./k8s/store-credentials.nix).
|
queue exporter's listener credentials presents from the host
|
||||||
Its grant is create and read on `swarm/services/victorialogs/store-auth`
|
(./k8s/store-credentials.nix). Its grant is create and read on
|
||||||
and `swarm/services/victoriametrics/store-auth`, and nothing else.
|
`swarm/services/victorialogs/store-auth`,
|
||||||
|
`swarm/services/victoriametrics/store-auth` and
|
||||||
|
`swarm/services/nats/exporter-auth`, and nothing else.
|
||||||
|
|
||||||
⚠️ Reserved as a hive name by ./swarm.nix, like its siblings.
|
⚠️ Reserved as a hive name by ./swarm.nix, like its siblings.
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ let
|
||||||
machine = "swarm-nats";
|
machine = "swarm-nats";
|
||||||
|
|
||||||
labels = import ./k8s/labels.nix;
|
labels = import ./k8s/labels.nix;
|
||||||
|
storeAuth = import ./lib/store-auth.nix;
|
||||||
|
|
||||||
# The container's journal forwarder pushes to its own receiver on the swarm
|
# The container's journal forwarder pushes to its own receiver on the swarm
|
||||||
# collector, the route `serviceProducers.swarm-nats` in
|
# collector, the route `serviceProducers.swarm-nats` in
|
||||||
|
|
@ -1006,7 +1007,30 @@ let
|
||||||
(toString deployCfg.nats.metricsPort)
|
(toString deployCfg.nats.metricsPort)
|
||||||
]
|
]
|
||||||
++ exporterFlags
|
++ exporterFlags
|
||||||
++ [ monitorUrl ];
|
++ [
|
||||||
|
# Every request to `/metrics` needs this login. The exporter takes
|
||||||
|
# the password only on its command line and compares it as bcrypt
|
||||||
|
# for a value that starts with `$2a$`, so the argument is the hash
|
||||||
|
# the host's unit publishes (./k8s/store-credentials.nix), which
|
||||||
|
# Kubernetes substitutes from the environment. The gateway's
|
||||||
|
# `/metrics` location sends the password. A Secret that does not
|
||||||
|
# exist keeps the container from starting; it does not leave the
|
||||||
|
# exporter open.
|
||||||
|
"-http_user"
|
||||||
|
storeAuth.exporter.user
|
||||||
|
"-http_pass"
|
||||||
|
"$(${storeAuth.exporter.hashEnv})"
|
||||||
|
monitorUrl
|
||||||
|
];
|
||||||
|
env = [
|
||||||
|
{
|
||||||
|
name = storeAuth.exporter.hashEnv;
|
||||||
|
valueFrom.secretKeyRef = {
|
||||||
|
name = storeAuth.exporter.secretName;
|
||||||
|
key = storeAuth.exporter.hashKey;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
# The port the metrics Service targets.
|
# The port the metrics Service targets.
|
||||||
ports = [
|
ports = [
|
||||||
{
|
{
|
||||||
|
|
@ -1049,9 +1073,10 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# The exporter answers a request with every client's name, so only the
|
# The exporter answers a request with every client's name, so it asks every
|
||||||
# node may read it: the Service is reached by name from the host's
|
# request for a login (`-http_user`, `-http_pass` above) and only the node
|
||||||
# gateway, and the policy admits the node's own traffic (which the
|
# reaches it: the Service is reached by name from the host's gateway, which
|
||||||
|
# sends the login, and the policy admits the node's own traffic (which the
|
||||||
# cluster's policy engine always lets in, ./k8s/render.nix) and, from
|
# cluster's policy engine always lets in, ./k8s/render.nix) and, from
|
||||||
# anywhere else, the client port alone.
|
# anywhere else, the client port alone.
|
||||||
objects."${machine}/service" = {
|
objects."${machine}/service" = {
|
||||||
|
|
@ -1177,7 +1202,8 @@ in
|
||||||
the swarm collector's authelia check.
|
the swarm collector's authelia check.
|
||||||
|
|
||||||
This is the exporter container's port in the pod, which the Service `swarm-nats-metrics` publishes on the same
|
This is the exporter container's port in the pod, which the Service `swarm-nats-metrics` publishes on the same
|
||||||
number and only the node reaches.
|
number. Only the node reaches it, and it answers a request only with the
|
||||||
|
login in `lib/store-auth.nix`.
|
||||||
|
|
||||||
⚠️ This and {option}`services.hyperhive.deploy.nats.monitorPort` are two
|
⚠️ This and {option}`services.hyperhive.deploy.nats.monitorPort` are two
|
||||||
more claims on a port
|
more claims on a port
|
||||||
|
|
@ -1399,6 +1425,9 @@ in
|
||||||
resolver ${networkCfg.bridgeIp} valid=10s ipv6=off;
|
resolver ${networkCfg.bridgeIp} valid=10s ipv6=off;
|
||||||
set $swarm_nats_metrics_upstream ${metricsHost}:${toString deployCfg.nats.metricsPort};
|
set $swarm_nats_metrics_upstream ${metricsHost}:${toString deployCfg.nats.metricsPort};
|
||||||
auth_request /__nats_metrics_authz;
|
auth_request /__nats_metrics_authz;
|
||||||
|
# The exporter's login in place of the caller's `Authorization`;
|
||||||
|
# an empty file sends none and the exporter answers 401.
|
||||||
|
include ${storeAuth.exporter.nginxFile};
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2245,8 +2245,8 @@ let
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
# Create without update: the first value stored is the one every later
|
# Create without update: the first value stored is the one every later
|
||||||
# run reads, and no run replaces it. The two leaves are the stores'.
|
# run reads, and no run replaces it. Two leaves are the stores', the third the exporter's.
|
||||||
name = "the store credential publisher's grant is create and read on the two stores' credentials and nothing else, and the PKI unit signs its leaf";
|
name = "the store credential publisher's grant is create and read on the two stores' and the queue exporter's credentials and nothing else, and the PKI unit signs its leaf";
|
||||||
ok =
|
ok =
|
||||||
let
|
let
|
||||||
s = baoGrantHere.systemd.services.swarm-bao-store-auth-policy.script;
|
s = baoGrantHere.systemd.services.swarm-bao-store-auth-policy.script;
|
||||||
|
|
@ -2262,7 +2262,12 @@ let
|
||||||
"create"
|
"create"
|
||||||
"read"
|
"read"
|
||||||
]
|
]
|
||||||
&& lib.length grants == 2
|
&&
|
||||||
|
(grantFor grants "secret/data/swarm/services/nats/exporter-auth").caps == [
|
||||||
|
"create"
|
||||||
|
"read"
|
||||||
|
]
|
||||||
|
&& lib.length grants == 3
|
||||||
&& lib.hasInfix "auth/cert/certs/swarm-store-auth" s
|
&& lib.hasInfix "auth/cert/certs/swarm-store-auth" s
|
||||||
&& lib.hasInfix "allowed_common_names=swarm-store-auth" s
|
&& lib.hasInfix "allowed_common_names=swarm-store-auth" s
|
||||||
&& lib.hasInfix "token_policies=swarm-store-auth" s
|
&& lib.hasInfix "token_policies=swarm-store-auth" s
|
||||||
|
|
|
||||||
|
|
@ -2242,6 +2242,57 @@ let
|
||||||
&& !(noNode.services.nginx.virtualHosts ? ${h.swarm.victorialogs.domain})
|
&& !(noNode.services.nginx.virtualHosts ? ${h.swarm.victorialogs.domain})
|
||||||
&& !(noNode.services.nginx.virtualHosts ? ${h.swarm.victoriametrics.domain});
|
&& !(noNode.services.nginx.virtualHosts ? ${h.swarm.victoriametrics.domain});
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
# The exporter's login has the same three ends as the stores', with the
|
||||||
|
# hash in place of the password in the pod. The literals are spelled here,
|
||||||
|
# not read from the module.
|
||||||
|
name = "the queue's exporter asks every request for a login whose bcrypt hash a Secret supplies, the gateway's location sends the password, and the unit creates, hashes and publishes it";
|
||||||
|
ok =
|
||||||
|
let
|
||||||
|
h = allLocal.services.hyperhive;
|
||||||
|
unit = allLocal.systemd.services.swarm-bao-store-auth;
|
||||||
|
exporter = lib.findFirst (c: c.name == "exporter") null (podSpec "swarm-nats").containers;
|
||||||
|
after =
|
||||||
|
flag: lib.elemAt exporter.args ((lib.lists.findFirstIndex (a: a == flag) (-1) exporter.args) + 1);
|
||||||
|
locations = allLocal.services.nginx.virtualHosts.${h.swarm.nats.domain}.locations;
|
||||||
|
include = "include /var/lib/swarm-store-auth/nats.conf;";
|
||||||
|
rule = "f /var/lib/swarm-store-auth/nats.conf 0600 root root -";
|
||||||
|
in
|
||||||
|
after "-http_user" == "swarm-exporter"
|
||||||
|
# The argument is the variable Kubernetes substitutes, and the Secret it
|
||||||
|
# names holds the hash only, never the password.
|
||||||
|
&& after "-http_pass" == "$(EXPORTER_HASH)"
|
||||||
|
&&
|
||||||
|
exporter.env == [
|
||||||
|
{
|
||||||
|
name = "EXPORTER_HASH";
|
||||||
|
valueFrom.secretKeyRef = {
|
||||||
|
name = "swarm-nats-exporter-auth";
|
||||||
|
key = "hash";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]
|
||||||
|
# The gateway's `/metrics` location sends the password; the
|
||||||
|
# authorization subrequest and the catch-all do not. The location is
|
||||||
|
# the control that the lookup finds one.
|
||||||
|
&& hasInfix include locations."= /metrics".extraConfig
|
||||||
|
&& lib.all (n: !(hasInfix "/var/lib/swarm-store-auth" (locations.${n}.extraConfig or ""))) (
|
||||||
|
lib.filter (n: n != "= /metrics") (lib.attrNames locations)
|
||||||
|
)
|
||||||
|
&& lib.length (lib.attrNames locations) >= 3
|
||||||
|
# The unit mints the password, hashes it as `$2a$` at NATS's own cost
|
||||||
|
# from stdin, and gives the cluster the hash alone.
|
||||||
|
&& hasInfix "secret/swarm/services/nats/exporter-auth" unit.script
|
||||||
|
&& hasInfix "/var/lib/swarm-store-auth/nats.conf" unit.script
|
||||||
|
&& hasInfix "htpasswd -niBC 11 x" unit.script
|
||||||
|
&& hasInfix "[$]2y[$]/$2a$/" unit.script
|
||||||
|
&& hasInfix "--from-literal=hash=" unit.script
|
||||||
|
&& hasInfix "swarm-nats-exporter-auth" unit.script
|
||||||
|
&& !(hasInfix "--from-file=hash" unit.script)
|
||||||
|
&& lib.elem rule allLocal.systemd.tmpfiles.rules
|
||||||
|
# Without the queue there is no file for it.
|
||||||
|
&& !(lib.elem rule noNode.systemd.tmpfiles.rules);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
# The two `auth_request` responders hold no state and log in under one
|
# The two `auth_request` responders hold no state and log in under one
|
||||||
# role, so they are one pod with one account that may run on any node.
|
# role, so they are one pod with one account that may run on any node.
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ let
|
||||||
metricsPort = 7777;
|
metricsPort = 7777;
|
||||||
authName = "auth.t.local";
|
authName = "auth.t.local";
|
||||||
controlPort = 9999;
|
controlPort = 9999;
|
||||||
|
metricsGateway = "127.0.0.1:18083";
|
||||||
namespace = "hyperhive";
|
namespace = "hyperhive";
|
||||||
service = "swarm-nats";
|
service = "swarm-nats";
|
||||||
prune = "${service}-k8s-prune";
|
prune = "${service}-k8s-prune";
|
||||||
|
|
@ -115,6 +116,36 @@ let
|
||||||
print(tls.getpeercert()["serialNumber"])
|
print(tls.getpeercert()["serialNumber"])
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# One nginx with the queue's `/metrics` location as the module renders it: the
|
||||||
|
# Service it dials, the variable between and the include of the exporter's
|
||||||
|
# login. The identity provider's check is a stand-in that answers 200, because
|
||||||
|
# the VM has no login service; nothing else of the vhost.
|
||||||
|
gatewayConf =
|
||||||
|
cfg:
|
||||||
|
let
|
||||||
|
l =
|
||||||
|
cfg.services.nginx.virtualHosts.${cfg.services.hyperhive.swarm.nats.domain}.locations."= /metrics";
|
||||||
|
in
|
||||||
|
pkgs.writeText "metrics-gateway.conf" ''
|
||||||
|
pid /run/metrics-gateway-test/nginx.pid;
|
||||||
|
error_log stderr;
|
||||||
|
events {}
|
||||||
|
http {
|
||||||
|
access_log off;
|
||||||
|
server {
|
||||||
|
listen ${metricsGateway};
|
||||||
|
location = /metrics {
|
||||||
|
proxy_pass ${l.proxyPass};
|
||||||
|
${l.extraConfig}
|
||||||
|
}
|
||||||
|
location = /__nats_metrics_authz {
|
||||||
|
internal;
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
# A port the node's firewall opens, which the second node reaches: the control
|
# A port the node's firewall opens, which the second node reaches: the control
|
||||||
# for every refusal it sees.
|
# for every refusal it sees.
|
||||||
controlListener = pkgs.writeText "control.py" ''
|
controlListener = pkgs.writeText "control.py" ''
|
||||||
|
|
@ -240,6 +271,18 @@ pkgs.testers.runNixOSTest {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services.metrics-gateway = {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
RuntimeDirectory = "metrics-gateway-test";
|
||||||
|
ExecStart = "${pkgs.nginx}/bin/nginx -c ${gatewayConf config} -g 'daemon off;'";
|
||||||
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = 2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.control-listener = {
|
systemd.services.control-listener = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
|
@ -313,6 +356,8 @@ pkgs.testers.runNixOSTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = builtins.readFile ./lib/k3s.py + ''
|
testScript = builtins.readFile ./lib/k3s.py + ''
|
||||||
|
import base64
|
||||||
|
|
||||||
INIT = "/root/bao-init.json"
|
INIT = "/root/bao-init.json"
|
||||||
NS = "${namespace}"
|
NS = "${namespace}"
|
||||||
SERVICE = "${service}"
|
SERVICE = "${service}"
|
||||||
|
|
@ -334,6 +379,11 @@ pkgs.testers.runNixOSTest {
|
||||||
MANIFESTS = "/var/lib/rancher/k3s/server/manifests"
|
MANIFESTS = "/var/lib/rancher/k3s/server/manifests"
|
||||||
SERVICES_ROOT = "${tlsDir}/swarm-services-root.pem"
|
SERVICES_ROOT = "${tlsDir}/swarm-services-root.pem"
|
||||||
TOKEN = "${routerToken}"
|
TOKEN = "${routerToken}"
|
||||||
|
STORE_AUTH_DIR = "/var/lib/swarm-store-auth"
|
||||||
|
EXPORTER_PASSWORD = f"{STORE_AUTH_DIR}/nats.password"
|
||||||
|
EXPORTER_CONF = f"{STORE_AUTH_DIR}/nats.conf"
|
||||||
|
EXPORTER_HASH_FILE = f"{STORE_AUTH_DIR}/nats.hash"
|
||||||
|
GATEWAY = "http://${metricsGateway}/metrics"
|
||||||
STREAM = "ROUTER_TODOS"
|
STREAM = "ROUTER_TODOS"
|
||||||
QUEUE_UP = (
|
QUEUE_UP = (
|
||||||
"systemctl --machine=swarm-nats is-active nats.service "
|
"systemctl --machine=swarm-nats is-active nats.service "
|
||||||
|
|
@ -459,6 +509,46 @@ pkgs.testers.runNixOSTest {
|
||||||
return node.execute(f"nc -z -w 4 {address} {port}")[0] == 0
|
return node.execute(f"nc -z -w 4 {address} {port}")[0] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def metrics_status(url: str, login: str | None, *args: str) -> tuple[int, str]:
|
||||||
|
"""One request to a metrics URL, with the Basic login `user:password`
|
||||||
|
when there is one: the status and the body."""
|
||||||
|
auth = f"-u '{login}' " if login else ""
|
||||||
|
_, out = machine.execute(f"curl -sS --max-time 10 -w '\\n%{{http_code}}' {auth}{' '.join(args)} '{url}'")
|
||||||
|
body, _, code = out.rpartition("\n")
|
||||||
|
return int(code or 0), body
|
||||||
|
|
||||||
|
|
||||||
|
def gateway_until(want: int) -> tuple[int, str]:
|
||||||
|
"""The gateway's answer to a collector's request, asked again for up to
|
||||||
|
30 seconds until its status is `want`: the last status and body."""
|
||||||
|
deadline = time.monotonic() + 30
|
||||||
|
while True:
|
||||||
|
status, body = metrics_status(GATEWAY, None, "-H 'Authorization: Bearer the-collectors-token'")
|
||||||
|
if status == want or time.monotonic() >= deadline:
|
||||||
|
return status, body
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
def gateway_diagnostics(pod_name: str) -> None:
|
||||||
|
"""What to read when the gateway's request is refused for good: the test
|
||||||
|
nginx's journal and error output, the length of the include file (never
|
||||||
|
its content), whether the exporter takes that header replayed straight
|
||||||
|
to it, and the exporter's own log."""
|
||||||
|
def show(title: str, command: str) -> None:
|
||||||
|
print(f"--- {title}")
|
||||||
|
print(machine.execute(f"{command} 2>&1")[1])
|
||||||
|
|
||||||
|
show("metrics-gateway journal", "journalctl -u metrics-gateway --no-pager -n 40")
|
||||||
|
show("include file length", f"wc -c {EXPORTER_CONF}")
|
||||||
|
show(
|
||||||
|
"the file's header replayed straight to the exporter (status)",
|
||||||
|
f"hdr=$(sed -E 's/^proxy_set_header Authorization \"(.*)\";$/\\1/' {EXPORTER_CONF}); "
|
||||||
|
f"curl -s -o /dev/null -w '%{{http_code}}' -H \"Authorization: $hdr\" http://{METRICS_HOST}:{METRICS}/metrics",
|
||||||
|
)
|
||||||
|
show("gateway response headers", f"curl -s -D- -o /dev/null -H 'Authorization: Bearer the-collectors-token' {GATEWAY}")
|
||||||
|
show("exporter log", f"kubectl -n {NS} logs {pod_name} -c exporter --tail=30")
|
||||||
|
|
||||||
|
|
||||||
def counts() -> tuple[int, int]:
|
def counts() -> tuple[int, int]:
|
||||||
"""How many servers and responders the node runs."""
|
"""How many servers and responders the node runs."""
|
||||||
servers = int(machine.execute("pgrep -cx nats-server")[1].strip() or 0)
|
servers = int(machine.execute("pgrep -cx nats-server")[1].strip() or 0)
|
||||||
|
|
@ -503,9 +593,14 @@ pkgs.testers.runNixOSTest {
|
||||||
"swarm-bao-nats-tls-policy",
|
"swarm-bao-nats-tls-policy",
|
||||||
"swarm-bao-nats-auth-policy",
|
"swarm-bao-nats-auth-policy",
|
||||||
"swarm-bao-services-issuer-policy",
|
"swarm-bao-services-issuer-policy",
|
||||||
|
"swarm-bao-store-auth-policy",
|
||||||
"swarm-bao-k8s-jwt-policy",
|
"swarm-bao-k8s-jwt-policy",
|
||||||
]:
|
]:
|
||||||
settle(f'[ "$(systemctl is-active {unit}.service)" = active ]', 900, [f"{unit}.service"])
|
settle(f'[ "$(systemctl is-active {unit}.service)" = active ]', 900, [f"{unit}.service"])
|
||||||
|
# The exporter's login: the unit creates it, hashes it and publishes the
|
||||||
|
# hash, which the pod's exporter container waits for.
|
||||||
|
machine.succeed("systemctl reset-failed swarm-bao-store-auth.service || true")
|
||||||
|
machine.succeed("systemctl restart --no-block swarm-bao-store-auth.service")
|
||||||
machine.wait_until_succeeds(
|
machine.wait_until_succeeds(
|
||||||
"journalctl -u swarm-bao-k8s-jwt-policy --no-pager | grep -F 'Success! Data written to: auth/jwt-k8s/role/swarm-nats-auth'",
|
"journalctl -u swarm-bao-k8s-jwt-policy --no-pager | grep -F 'Success! Data written to: auth/jwt-k8s/role/swarm-nats-auth'",
|
||||||
timeout=300,
|
timeout=300,
|
||||||
|
|
@ -555,6 +650,11 @@ pkgs.testers.runNixOSTest {
|
||||||
assert command[0] == "/bin/wget" and command[-1].endswith("/healthz?js-enabled-only=true"), command
|
assert command[0] == "/bin/wget" and command[-1].endswith("/healthz?js-enabled-only=true"), command
|
||||||
exporter = next(c for c in spec["containers"] if c["name"] == "exporter")
|
exporter = next(c for c in spec["containers"] if c["name"] == "exporter")
|
||||||
assert exporter["ports"] == [{"name": "metrics", "containerPort": METRICS, "protocol": "TCP"}], exporter["ports"]
|
assert exporter["ports"] == [{"name": "metrics", "containerPort": METRICS, "protocol": "TCP"}], exporter["ports"]
|
||||||
|
# The login is on the command line as a hash the Secret supplies, never
|
||||||
|
# as the password.
|
||||||
|
assert exporter["args"][exporter["args"].index("-http_user") + 1] == "swarm-exporter", exporter["args"]
|
||||||
|
assert exporter["args"][exporter["args"].index("-http_pass") + 1] == "$(EXPORTER_HASH)", exporter["args"]
|
||||||
|
assert exporter["env"] == [{"name": "EXPORTER_HASH", "valueFrom": {"secretKeyRef": {"name": "swarm-nats-exporter-auth", "key": "hash"}}}], exporter["env"]
|
||||||
assert not any(c.get("resources") for c in spec["containers"]), spec["containers"]
|
assert not any(c.get("resources") for c in spec["containers"]), spec["containers"]
|
||||||
assert not any("secret" in v for v in spec["volumes"]), spec["volumes"]
|
assert not any("secret" in v for v in spec["volumes"]), spec["volumes"]
|
||||||
assert spec["hostAliases"] == [{"ip": "127.0.0.1", "hostnames": [NAME]}], spec["hostAliases"]
|
assert spec["hostAliases"] == [{"ip": "127.0.0.1", "hostnames": [NAME]}], spec["hostAliases"]
|
||||||
|
|
@ -675,8 +775,9 @@ pkgs.testers.runNixOSTest {
|
||||||
with subtest("the exporter answers the host's own processes by its Service's name, and refuses a client of the bridge and a pod of the cluster"):
|
with subtest("the exporter answers the host's own processes by its Service's name, and refuses a client of the bridge and a pod of the cluster"):
|
||||||
ip = kube(machine, f"get service {METRICS_SERVICE} -o jsonpath='{{.spec.clusterIP}}'").strip()
|
ip = kube(machine, f"get service {METRICS_SERVICE} -o jsonpath='{{.spec.clusterIP}}'").strip()
|
||||||
assert machine.succeed(f"getent ahostsv4 {METRICS_HOST}").split()[0] == ip
|
assert machine.succeed(f"getent ahostsv4 {METRICS_HOST}").split()[0] == ip
|
||||||
body = machine.succeed(f"curl -sf http://{METRICS_HOST}:{METRICS}/metrics")
|
password = machine.succeed(f"cat {EXPORTER_PASSWORD}").strip()
|
||||||
assert "gnatsd_varz_connections" in body, body[:500]
|
status, body = metrics_status(f"http://{METRICS_HOST}:{METRICS}/metrics", f"swarm-exporter:{password}")
|
||||||
|
assert status == 200 and "gnatsd_varz_connections" in body, (status, body[:500])
|
||||||
# The bridge's client has the route to the Service's address through the
|
# The bridge's client has the route to the Service's address through the
|
||||||
# host, and the pod's policy refuses it. A pod of the cluster reaches the
|
# host, and the pod's policy refuses it. A pod of the cluster reaches the
|
||||||
# queue's client port, the control that it can dial out, and not the
|
# queue's client port, the control that it can dial out, and not the
|
||||||
|
|
@ -700,6 +801,57 @@ pkgs.testers.runNixOSTest {
|
||||||
deny = json.loads(kube(machine, "get networkpolicy default-deny-ingress -o json"))["spec"]
|
deny = json.loads(kube(machine, "get networkpolicy default-deny-ingress -o json"))["spec"]
|
||||||
assert deny == {"podSelector": {}, "policyTypes": ["Ingress"]}, deny
|
assert deny == {"podSelector": {}, "policyTypes": ["Ingress"]}, deny
|
||||||
|
|
||||||
|
with subtest("the exporter answers only a request with its login, from the node and through the gateway, and the Secret holds the hash and no password"):
|
||||||
|
url = f"http://{METRICS_HOST}:{METRICS}/metrics"
|
||||||
|
# The password the unit created, in the store, on the host and nowhere
|
||||||
|
# else: the Secret and the manifest hold its bcrypt hash.
|
||||||
|
assert len(password) == 64 and all(c in "0123456789abcdef" for c in password), "the password is not 64 hex digits"
|
||||||
|
assert as_root("bao kv get -mount=secret -field=value swarm/services/nats/exporter-auth").strip() == password
|
||||||
|
exporter_hash = machine.succeed(f"kubectl -n {NS} get secret swarm-nats-exporter-auth -o jsonpath='{{.data.hash}}' | base64 -d")
|
||||||
|
assert exporter_hash.startswith("$2a$11$") and len(exporter_hash) == 60, exporter_hash
|
||||||
|
assert machine.succeed(f"cat {EXPORTER_HASH_FILE}").strip() == exporter_hash
|
||||||
|
assert password not in kube(machine, "get secret swarm-nats-exporter-auth -o json")
|
||||||
|
assert password not in kube(machine, f"get pod {pod_name} -o json")
|
||||||
|
assert machine.succeed(f"stat -c '%a %U %G' {EXPORTER_PASSWORD} {EXPORTER_CONF} {EXPORTER_HASH_FILE} {STORE_AUTH_DIR}").split("\n")[:4] == [
|
||||||
|
"600 root root",
|
||||||
|
"600 root root",
|
||||||
|
"600 root root",
|
||||||
|
"700 root root",
|
||||||
|
]
|
||||||
|
login = base64.b64encode(f"swarm-exporter:{password}".encode()).decode()
|
||||||
|
assert machine.succeed(f"cat {EXPORTER_CONF}").strip() == f'proxy_set_header Authorization "Basic {login}";'
|
||||||
|
# The login opens it, the control for each refusal below. The hash is
|
||||||
|
# no password: the exporter reads only a `$2a$` value as bcrypt, and a
|
||||||
|
# hash taken for plain text would let its own text in. An empty password
|
||||||
|
# is refused for the same reason, which is what a missing `-http_pass`
|
||||||
|
# would let in.
|
||||||
|
assert metrics_status(url, f"swarm-exporter:{password}")[0] == 200
|
||||||
|
for who in (None, "swarm-exporter:wrong", f"other:{password}", f"swarm-exporter:{exporter_hash}", "swarm-exporter:", f"swarm-exporter:{password}0"):
|
||||||
|
status, body = metrics_status(url, who)
|
||||||
|
assert status == 401 and "gnatsd" not in body, (who, status, body[:200])
|
||||||
|
pod_ip_now = kube(machine, f"get pod {pod_name} -o jsonpath='{{.status.podIP}}'").strip()
|
||||||
|
assert metrics_status(f"http://{pod_ip_now}:{METRICS}/metrics", None)[0] == 401
|
||||||
|
assert metrics_status(f"http://{pod_ip_now}:{METRICS}/metrics", f"swarm-exporter:{password}")[0] == 200
|
||||||
|
# Through the gateway's location as the module renders it: the caller's
|
||||||
|
# own bearer is replaced by the login, and the queue's series arrive.
|
||||||
|
# nginx reads the include file as it loads: this one started at boot
|
||||||
|
# with the empty file the tmpfiles rule made, before the unit wrote the
|
||||||
|
# header, so it reloads, as the unit does for the host's nginx. A reload
|
||||||
|
# answers before the new workers take requests, so each request below
|
||||||
|
# is repeated until it answers what the file now says.
|
||||||
|
machine.succeed("systemctl reload metrics-gateway")
|
||||||
|
status, body = gateway_until(200)
|
||||||
|
if status != 200 or "gnatsd_varz_connections" not in body:
|
||||||
|
gateway_diagnostics(pod_name)
|
||||||
|
raise AssertionError((status, body[:500]))
|
||||||
|
# With the include file empty the gateway sends nothing and the exporter
|
||||||
|
# refuses the caller's bearer; the unit writes the file again.
|
||||||
|
machine.succeed(f": > {EXPORTER_CONF} && systemctl reload metrics-gateway")
|
||||||
|
status, _ = gateway_until(401)
|
||||||
|
assert status == 401, status
|
||||||
|
machine.succeed("systemctl restart swarm-bao-store-auth.service && systemctl reload metrics-gateway")
|
||||||
|
assert gateway_until(200)[0] == 200
|
||||||
|
|
||||||
with subtest("a leaf that has to be issued again is issued beside the running server, which reloads it for new connections"):
|
with subtest("a leaf that has to be issued again is issued beside the running server, which reloads it for new connections"):
|
||||||
uid = pod(machine, pod_name)["metadata"]["uid"]
|
uid = pod(machine, pod_name)["metadata"]["uid"]
|
||||||
leaf_dir = machine.succeed(f"grep -F 'pods/{uid}/volumes/kubernetes.io~empty-dir/nats-tls ' /proc/mounts | cut -d' ' -f2").strip()
|
leaf_dir = machine.succeed(f"grep -F 'pods/{uid}/volumes/kubernetes.io~empty-dir/nats-tls ' /proc/mounts | cut -d' ' -f2").strip()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue