k8s: the gateway's group reads the store credential files nginx includes
This commit is contained in:
parent
0d6065cf8f
commit
f65aed2147
7 changed files with 119 additions and 64 deletions
|
|
@ -367,9 +367,9 @@ writes to the store and Grafana that reads it.
|
||||||
`swarm/services/victorialogs/store-auth` when the store holds none, as the host's
|
`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
|
`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
|
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;
|
`/var/lib/swarm-store-auth/victorialogs.conf` (`root:` the gateway's group, `0640`, in a `0750` directory of the same owner;
|
||||||
nginx's main process reads its configuration as root, so the file needs no
|
NixOS runs nginx's master and workers as `User=nginx`, so the group is the
|
||||||
other reader, and it's never in the nix store), which the vhost's store
|
only reader besides root, and the file is never in the nix store), which the vhost's store
|
||||||
locations `include`, then reloads nginx, and publishes the password as the
|
locations `include`, then reloads nginx, and publishes the password as the
|
||||||
Secret the way the host publishes the CA ConfigMap. The unit is `Type=simple`
|
Secret the way the host publishes the CA ConfigMap. The unit is `Type=simple`
|
||||||
and retries every 30 seconds, so a boot or a switch with the secret store still
|
and retries every 30 seconds, so a boot or a switch with the secret store still
|
||||||
|
|
|
||||||
|
|
@ -122,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` |
|
||||||
|
|
@ -130,9 +130,9 @@ 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, 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` |
|
| 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 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 and the nginx group, `0640`, in a directory of `0750`): the `Authorization` header the vhost's store locations send, and `/var/lib/swarm-store-auth/victorialogs.password` (root only, `0600`), 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 and the nginx group, `0640`, in a directory of `0750`): the `Authorization` header the vhost's store locations send, and `/var/lib/swarm-store-auth/victoriametrics.password` (root only, `0600`), 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 |
|
| 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 and the nginx group, `0640`, in a directory of `0750`): the `Authorization` header the gateway's `/metrics` location for the queue sends; `/var/lib/swarm-store-auth/nats.password` (the password, root only) 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 |
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@ let
|
||||||
storeAuth = import ../lib/store-auth.nix;
|
storeAuth = import ../lib/store-auth.nix;
|
||||||
storeRetry = import ../lib/store-retry.nix { };
|
storeRetry = import ../lib/store-retry.nix { };
|
||||||
|
|
||||||
|
# The gateway's group: nginx's master and workers run as its user, and read
|
||||||
|
# the files `include`d into the store locations.
|
||||||
|
nginxGroup = config.services.nginx.group;
|
||||||
|
|
||||||
# The stores this host runs, by the name `store-auth.nix` takes.
|
# The stores this host runs, by the name `store-auth.nix` takes.
|
||||||
stores =
|
stores =
|
||||||
lib.optional deployCfg.victorialogs.enable "victorialogs"
|
lib.optional deployCfg.victorialogs.enable "victorialogs"
|
||||||
|
|
@ -59,16 +63,22 @@ in
|
||||||
config = lib.mkIf (stores != [ ] || exporterOn) (
|
config = lib.mkIf (stores != [ ] || exporterOn) (
|
||||||
lib.mkMerge [
|
lib.mkMerge [
|
||||||
{
|
{
|
||||||
|
# The group exists on a host where the NixOS nginx unit is off too, since
|
||||||
|
# the files below are made with it.
|
||||||
|
users.groups.${nginxGroup} = { };
|
||||||
|
|
||||||
# The files exist before nginx first reads its configuration, because
|
# The files exist before nginx first reads its configuration, because
|
||||||
# an `include` of a missing file is a fatal error there. `f` creates
|
# an `include` of a missing file is a fatal error there. `f` creates
|
||||||
# a file and never overwrites one, and an empty file sets no header:
|
# a file and never overwrites one, and an empty file sets no header:
|
||||||
# the store then refuses the request, which is the only thing a
|
# the store then refuses the request, which is the only thing a
|
||||||
# gateway without the credential can get from it.
|
# gateway without the credential can get from it. The directory and
|
||||||
|
# the nginx files are the gateway's group's to read, which nginx needs
|
||||||
|
# to start; the passwords and the hash stay in files only root reads.
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d ${storeAuth.dir} 0700 root root - -"
|
"d ${storeAuth.dir} 0750 root ${nginxGroup} - -"
|
||||||
]
|
]
|
||||||
++ map (store: "f ${storeAuth.nginxFile store} 0600 root root -") stores
|
++ map (store: "f ${storeAuth.nginxFile store} 0640 root ${nginxGroup} -") stores
|
||||||
++ lib.optional exporterOn "f ${exporter.nginxFile} 0600 root root -";
|
++ lib.optional exporterOn "f ${exporter.nginxFile} 0640 root ${nginxGroup} -";
|
||||||
}
|
}
|
||||||
|
|
||||||
(lib.mkIf (node.enable && k8sCfg.enable) {
|
(lib.mkIf (node.enable && k8sCfg.enable) {
|
||||||
|
|
@ -137,7 +147,7 @@ in
|
||||||
${import ../lib/atomic-write-secret.nix { }}
|
${import ../lib/atomic-write-secret.nix { }}
|
||||||
${import ../lib/refresh-consumer.nix { }}
|
${import ../lib/refresh-consumer.nix { }}
|
||||||
|
|
||||||
install -d -m 0700 ${storeAuth.dir}
|
install -d -m 0750 -o root -g ${lib.escapeShellArg nginxGroup} ${storeAuth.dir}
|
||||||
|
|
||||||
# A password of 64 hex digits, as Grafana's bearer is.
|
# A password of 64 hex digits, as Grafana's bearer is.
|
||||||
mint_password() {
|
mint_password() {
|
||||||
|
|
@ -160,11 +170,14 @@ in
|
||||||
directive="proxy_set_header Authorization \"Basic $(printf '%s:%s' "$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 0640 root:${nginxGroup} "$nginx_file" "$directive"
|
||||||
reload=1
|
reload=1
|
||||||
elif written_after_start nginx.service "$nginx_file"; then
|
elif written_after_start nginx.service "$nginx_file"; then
|
||||||
reload=1
|
reload=1
|
||||||
fi
|
fi
|
||||||
|
# A file that already holds the value keeps the owner it was written with.
|
||||||
|
chown root:${nginxGroup} "$nginx_file"
|
||||||
|
chmod 0640 "$nginx_file"
|
||||||
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
|
password_changed=1
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ rec {
|
||||||
# `victorialogs` or `victoriametrics`.
|
# `victorialogs` or `victoriametrics`.
|
||||||
leaf = store: "swarm/services/${store}/store-auth";
|
leaf = store: "swarm/services/${store}/store-auth";
|
||||||
|
|
||||||
# On the host, a directory only root reads: the password the Secret is made from,
|
# On the host, a directory for root and the gateway's group (`0750`): the nginx
|
||||||
# and the nginx file the gateway's locations include.
|
# file the gateway's locations include, which the group reads (`0640`), and the
|
||||||
|
# password the Secret is made from, which only root reads.
|
||||||
dir = "/var/lib/swarm-store-auth";
|
dir = "/var/lib/swarm-store-auth";
|
||||||
passwordFile = store: "${dir}/${store}.password";
|
passwordFile = store: "${dir}/${store}.password";
|
||||||
nginxFile = store: "${dir}/${store}.conf";
|
nginxFile = store: "${dir}/${store}.conf";
|
||||||
|
|
|
||||||
|
|
@ -2256,7 +2256,7 @@ let
|
||||||
let
|
let
|
||||||
h = allLocal.services.hyperhive;
|
h = allLocal.services.hyperhive;
|
||||||
unit = allLocal.systemd.services.swarm-bao-store-auth;
|
unit = allLocal.systemd.services.swarm-bao-store-auth;
|
||||||
rule = store: "f /var/lib/swarm-store-auth/${store}.conf 0600 root root -";
|
rule = store: "f /var/lib/swarm-store-auth/${store}.conf 0640 root nginx -";
|
||||||
# One store's vhost: every location that dials it includes the file,
|
# One store's vhost: every location that dials it includes the file,
|
||||||
# and no other location does.
|
# and no other location does.
|
||||||
vhost =
|
vhost =
|
||||||
|
|
@ -2348,10 +2348,20 @@ let
|
||||||
&& hasInfix "store-auth.pem" h.deploy.bao.storeAuthClientCertFile
|
&& hasInfix "store-auth.pem" h.deploy.bao.storeAuthClientCertFile
|
||||||
&& lib.elem (rule "victorialogs") allLocal.systemd.tmpfiles.rules
|
&& lib.elem (rule "victorialogs") allLocal.systemd.tmpfiles.rules
|
||||||
&& lib.elem (rule "victoriametrics") allLocal.systemd.tmpfiles.rules
|
&& lib.elem (rule "victoriametrics") allLocal.systemd.tmpfiles.rules
|
||||||
|
# nginx runs as `User=nginx`: the directory and the nginx files are its
|
||||||
|
# group's to read, written that way and fixed when they already hold the
|
||||||
|
# value, and the passwords stay root's.
|
||||||
|
&& lib.elem "d /var/lib/swarm-store-auth 0750 root nginx - -" allLocal.systemd.tmpfiles.rules
|
||||||
|
&& hasInfix "install -d -m 0750 -o root -g nginx /var/lib/swarm-store-auth" unit.script
|
||||||
|
&& hasInfix ''atomic_write_secret 0640 root:nginx "$nginx_file" "$directive"'' unit.script
|
||||||
|
&& hasInfix ''chown root:nginx "$nginx_file"'' unit.script
|
||||||
|
&& hasInfix ''chmod 0640 "$nginx_file"'' unit.script
|
||||||
|
&& hasInfix ''atomic_write_secret 0600 root:root "$password_file" "$password"'' unit.script
|
||||||
# Without either store there is no unit, no file and no location.
|
# Without either store there is no unit, no file and no location.
|
||||||
&& !(noNode.systemd.services ? swarm-bao-store-auth)
|
&& !(noNode.systemd.services ? swarm-bao-store-auth)
|
||||||
&& !(lib.elem (rule "victorialogs") noNode.systemd.tmpfiles.rules)
|
&& !(lib.elem (rule "victorialogs") noNode.systemd.tmpfiles.rules)
|
||||||
&& !(lib.elem (rule "victoriametrics") noNode.systemd.tmpfiles.rules)
|
&& !(lib.elem (rule "victoriametrics") noNode.systemd.tmpfiles.rules)
|
||||||
|
&& !(lib.elem "d /var/lib/swarm-store-auth 0750 root nginx - -" noNode.systemd.tmpfiles.rules)
|
||||||
&& !(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});
|
||||||
}
|
}
|
||||||
|
|
@ -2369,7 +2379,7 @@ let
|
||||||
flag: lib.elemAt exporter.args ((lib.lists.findFirstIndex (a: a == flag) (-1) exporter.args) + 1);
|
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;
|
locations = allLocal.services.nginx.virtualHosts.${h.swarm.nats.domain}.locations;
|
||||||
include = "include /var/lib/swarm-store-auth/nats.conf;";
|
include = "include /var/lib/swarm-store-auth/nats.conf;";
|
||||||
rule = "f /var/lib/swarm-store-auth/nats.conf 0600 root root -";
|
rule = "f /var/lib/swarm-store-auth/nats.conf 0640 root nginx -";
|
||||||
in
|
in
|
||||||
after "-http_user" == "swarm-exporter"
|
after "-http_user" == "swarm-exporter"
|
||||||
# The argument is the variable Kubernetes substitutes, and the Secret it
|
# The argument is the variable Kubernetes substitutes, and the Secret it
|
||||||
|
|
|
||||||
|
|
@ -826,9 +826,9 @@ pkgs.testers.runNixOSTest {
|
||||||
assert password not in kube(machine, f"get pod {pod_name} -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] == [
|
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",
|
||||||
|
"640 root nginx",
|
||||||
"600 root root",
|
"600 root root",
|
||||||
"600 root root",
|
"750 root nginx",
|
||||||
"700 root root",
|
|
||||||
]
|
]
|
||||||
login = base64.b64encode(f"swarm-exporter:{password}".encode()).decode()
|
login = base64.b64encode(f"swarm-exporter:{password}".encode()).decode()
|
||||||
assert machine.succeed(f"cat {EXPORTER_CONF}").strip() == f'proxy_set_header Authorization "Basic {login}";'
|
assert machine.succeed(f"cat {EXPORTER_CONF}").strip() == f'proxy_set_header Authorization "Basic {login}";'
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,13 @@ pkgs.testers.runNixOSTest {
|
||||||
# which needs certificates this host does not mint, so a second nginx
|
# which needs certificates this host does not mint, so a second nginx
|
||||||
# carries the passthrough alone, as `k8s-bao-login` does.
|
# carries the passthrough alone, as `k8s-bao-login` does.
|
||||||
services.nginx.enable = lib.mkForce false;
|
services.nginx.enable = lib.mkForce false;
|
||||||
|
# The user the module would create: the stub gateway below runs as it, so a
|
||||||
|
# file it includes has to be the gateway's to read, as under the real unit
|
||||||
|
# (`User = cfg.user`).
|
||||||
|
users.users.nginx = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = "nginx";
|
||||||
|
};
|
||||||
networking.hosts."${bridgeIp}" = [
|
networking.hosts."${bridgeIp}" = [
|
||||||
baoName
|
baoName
|
||||||
natsName
|
natsName
|
||||||
|
|
@ -510,16 +517,20 @@ pkgs.testers.runNixOSTest {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
User = "nginx";
|
||||||
|
Group = "nginx";
|
||||||
RuntimeDirectory = "logs-gateway-test";
|
RuntimeDirectory = "logs-gateway-test";
|
||||||
ExecStart = "${pkgs.nginx}/bin/nginx -c ${gatewayConf config} -g 'daemon off;'";
|
ExecStart = "${pkgs.nginx}/bin/nginx -e stderr -c ${gatewayConf config} -g 'daemon off;'";
|
||||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = 2;
|
RestartSec = 2;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environment.etc."logs-gateway.conf".source = gatewayConf config;
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
pkgs.kubectl
|
pkgs.kubectl
|
||||||
|
pkgs.nginx
|
||||||
pkgs.curl
|
pkgs.curl
|
||||||
pkgs.jq
|
pkgs.jq
|
||||||
pkgs.openssl
|
pkgs.openssl
|
||||||
|
|
@ -1095,7 +1106,7 @@ pkgs.testers.runNixOSTest {
|
||||||
assert machine.succeed(f"cat {STORE_PASSWORD}").strip() == stored
|
assert machine.succeed(f"cat {STORE_PASSWORD}").strip() == stored
|
||||||
secret = machine.succeed(f"kubectl -n {NS} get secret swarm-victorialogs-credentials -o jsonpath='{{.data.store-auth}}' | base64 -d").strip()
|
secret = machine.succeed(f"kubectl -n {NS} get secret swarm-victorialogs-credentials -o jsonpath='{{.data.store-auth}}' | base64 -d").strip()
|
||||||
assert secret == stored
|
assert secret == stored
|
||||||
assert machine.succeed(f"stat -c '%a %U %G' {STORE_PASSWORD} {STORE_CONF} {STORE_AUTH_DIR}").split("\n")[:3] == ["600 root root", "600 root root", "700 root root"]
|
assert machine.succeed(f"stat -c '%a %U %G' {STORE_PASSWORD} {STORE_CONF} {STORE_AUTH_DIR}").split("\n")[:3] == ["600 root root", "640 root nginx", "750 root nginx"]
|
||||||
assert stored not in machine.succeed(f"cat {MANIFESTS}/{VL}.yaml"), "the manifest holds no credential"
|
assert stored not in machine.succeed(f"cat {MANIFESTS}/{VL}.yaml"), "the manifest holds no credential"
|
||||||
# Insert, select, a delete route, the admin routes, the store's own
|
# Insert, select, a delete route, the admin routes, the store's own
|
||||||
# metrics and the UI answer 401 with no credential and with a caller's
|
# metrics and the UI answer 401 with no credential and with a caller's
|
||||||
|
|
@ -1159,6 +1170,26 @@ pkgs.testers.runNixOSTest {
|
||||||
assert machine.succeed(f"cat {STORE_CONF}") == saved
|
assert machine.succeed(f"cat {STORE_CONF}") == saved
|
||||||
wait_for_record(AGENT_TOKEN, "switch", "written before the switch")
|
wait_for_record(AGENT_TOKEN, "switch", "written before the switch")
|
||||||
|
|
||||||
|
with subtest("the gateway's user reads the credential file and not the password, and a file only root reads keeps nginx from loading its configuration"):
|
||||||
|
# The stub gateway runs as the user the module's nginx unit runs as
|
||||||
|
# (`User = cfg.user`), so what it includes has to be that user's to read.
|
||||||
|
nginx_check = "runuser -u nginx -- ${pkgs.nginx}/bin/nginx -e stderr -t -c /etc/logs-gateway.conf 2>&1"
|
||||||
|
assert machine.succeed("systemctl show --property=User --value logs-gateway").strip() == "nginx"
|
||||||
|
machine.succeed(f"runuser -u nginx -- cat {STORE_CONF}")
|
||||||
|
machine.fail(f"runuser -u nginx -- cat {STORE_PASSWORD}")
|
||||||
|
machine.succeed(nginx_check)
|
||||||
|
# Control: the same file owned and moded as it was, root's alone.
|
||||||
|
machine.succeed(f"chown root:root {STORE_CONF} && chmod 0600 {STORE_CONF}")
|
||||||
|
status, out = machine.execute(nginx_check)
|
||||||
|
assert status != 0 and f'open() "{STORE_CONF}" failed (13: Permission denied)' in out, (status, out)
|
||||||
|
# The unit finds the value right and the owner wrong, and puts it back.
|
||||||
|
machine.succeed("systemctl restart swarm-bao-store-auth.service")
|
||||||
|
store_credential_published()
|
||||||
|
assert machine.succeed(f"stat -c '%a %U %G' {STORE_CONF}").strip() == "640 root nginx"
|
||||||
|
machine.succeed(nginx_check)
|
||||||
|
machine.succeed("systemctl reload logs-gateway")
|
||||||
|
machine.wait_until_succeeds("systemctl is-active logs-gateway", timeout=30)
|
||||||
|
|
||||||
with subtest("a record posted to the ingest route and the store's own metrics come through the gateway, and a restarted pod still holds both records"):
|
with subtest("a record posted to the ingest route and the store's own metrics come through the gateway, and a restarted pod still holds both records"):
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
@ -1485,7 +1516,7 @@ pkgs.testers.runNixOSTest {
|
||||||
assert machine.succeed(f"cat {VM_PASSWORD}").strip() == stored
|
assert machine.succeed(f"cat {VM_PASSWORD}").strip() == stored
|
||||||
secret = machine.succeed(f"kubectl -n {NS} get secret swarm-victoriametrics-credentials -o jsonpath='{{.data.store-auth}}' | base64 -d").strip()
|
secret = machine.succeed(f"kubectl -n {NS} get secret swarm-victoriametrics-credentials -o jsonpath='{{.data.store-auth}}' | base64 -d").strip()
|
||||||
assert secret == stored
|
assert secret == stored
|
||||||
assert machine.succeed(f"stat -c '%a %U %G' {VM_PASSWORD} {VM_CONF}").split("\n")[:2] == ["600 root root", "600 root root"]
|
assert machine.succeed(f"stat -c '%a %U %G' {VM_PASSWORD} {VM_CONF}").split("\n")[:2] == ["600 root root", "640 root nginx"]
|
||||||
assert stored not in machine.succeed(f"cat {MANIFESTS}/{VM}.yaml"), "the manifest holds no credential"
|
assert stored not in machine.succeed(f"cat {MANIFESTS}/{VM}.yaml"), "the manifest holds no credential"
|
||||||
# Writes, imports, queries, exports, the routes that delete and
|
# Writes, imports, queries, exports, the routes that delete and
|
||||||
# snapshot, the config and reload routes, the store's own metrics and
|
# snapshot, the config and reload routes, the store's own metrics and
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue