Watch
0
0
Fork
You've already forked hyperhive
0

the log and metrics stores ask every request for a credential the gateway supplies

Each store runs with -httpAuth.* and a credential from the secret store, published to the namespace as a Secret by the host. The gateway's locations send it after auth_request has passed, and the collector's scrape and push take the same one, so a process on the node that bypasses the gateway is refused.
This commit is contained in:
atlas 2026-11-27 17:24:08 +01:00 • committed by maia
commit f54aae7927

View file

@ -16,11 +16,11 @@
# reaches this at `https://${cfg.domain}/` gated by the same `auth_request`
# check against authelia that swarm-ui's own vhost uses (`swarmAuthRequest`
# below; `swarm-ui.nix` says why forceSSL is load-bearing: authelia answers a
# plain-http auth subrequest with 400). The store's own listener is unauthenticated and takes
# writes as well as reads. Its Service admits only the node's own traffic, and
# the vhost, which dials it by name, is the ONLY way in: the collector pushes
# through it too, at its own `= /insert/...` location, because the collector
# need not share a host with the store.
# plain-http auth subrequest with 400). The store's own listener asks every
# request for the credential in ./lib/store-auth.nix: each location below that
# dials it replaces the caller's `Authorization` with it once its own check has
# passed. The collector pushes through the vhost too, at its own
# `= /insert/...` location, because it need not share a host with the store.
# ⚠️ That ingest location deliberately does not carry `swarmAuthRequest` — a
# pusher handed its `error_page 401 =302` follows the redirect and POSTs at a
# login page, which answers 200. See the location itself.
@ -42,6 +42,7 @@ let
gatewayCfg = hyperhiveCfg.gateway;
k8sCfg = hyperhiveCfg.k8s;
inherit (import ../images { inherit pkgs lib; }) mkServiceImage;
storeAuth = import ./lib/store-auth.nix;
# Copy of `swarm-ui.nix`'s own `swarmAuthRequest` — not shared code because
# this vhost needs exactly the two locations that reference it (`/` and the
@ -125,6 +126,13 @@ let
'';
storeVariable = "$swarm_logs_store_upstream";
upstream = "http://${storeVariable}";
# The store's locations dial it with the store's credential in place of the
# caller's `Authorization`. The file is empty until the unit that mints the
# credential has run (./k8s/store-credentials.nix), and the
# store then refuses the request. The responders' locations never include it.
viaStore =
viaService storeVariable storeService storePort
+ "include ${storeAuth.nginxFile "victorialogs"};\n";
agentAuthVariable = "$swarm_logs_agent_auth_upstream";
grafanaAuthVariable = "$swarm_logs_grafana_auth_upstream";
@ -137,7 +145,12 @@ let
"-storageDataPath=${dataDir}"
"-httpListenAddr=:${toString storePort}"
"-retentionPeriod=${deployCfg.victorialogs.retentionPeriod}"
# Every route but `/health` and the few built-in ones that answer a
# fixed text asks for it (docs/4-implementation/k8s/runtime.md).
"-httpAuth.username=${storeAuth.user}"
"-httpAuth.password=file://%d/${storeAuth.credentialId}"
];
LoadCredential = [ storeAuth.credentialId ];
StateDirectory = "victorialogs";
};
environment = { };
@ -512,8 +525,7 @@ in
services.hyperhive.gateway.dns.enable = lib.mkDefault true;
# Authenticated front door onto the store's Service — see the file-top
# comment for why the store's own unauthenticated listener is reached
# through this vhost alone.
# comment for the credential each location sends the store.
# `forceSSL`: same asymmetry `swarm-ui.nix` documents —
# authelia answers a plain-http auth subrequest with 400, which
# `auth_request` cannot read as anything but a broken check, so this
@ -524,7 +536,7 @@ in
locations = {
"/" = {
proxyPass = upstream;
extraConfig = viaService storeVariable storeService storePort + swarmAuthRequest;
extraConfig = viaStore + swarmAuthRequest;
};
# The swarm collector's ingest route. `=` so it outranks the `/`
@ -544,7 +556,7 @@ in
"= /insert/opentelemetry/v1/logs" = {
proxyPass = upstream;
extraConfig = ''
${viaService storeVariable storeService storePort}
${viaStore}
auth_request /__swarm_logs_ingest_authz;
'';
};
@ -579,7 +591,7 @@ in
# the store as the caller sent them.
proxyPass = upstream;
extraConfig = ''
${viaService storeVariable storeService storePort}
${viaStore}
auth_request /__swarm_logs_auth;
'';
};
@ -597,7 +609,7 @@ in
"= /metrics" = {
proxyPass = upstream;
extraConfig = ''
${viaService storeVariable storeService storePort}
${viaStore}
auth_request /__hive_authelia;
'';
};
@ -710,8 +722,7 @@ in
# nonsense-path control, because a probe where every arm returns the same
# code is not evidence.
#
# ⚠️ Like the metrics store's, that endpoint is unauthenticated — which is
# why the Service's policy admits only the node and why nothing reaches it
# except through the gateway, where the ingest route is authenticated. (This
# module declares a vhost.)
# ⚠️ The endpoint asks for the store's credential like every other route: the
# ingest location replaces the caller's `Authorization` with it once the
# collector's own check has passed.
}