Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/nix/host-modules/swarm-victorialogs.nix
atlas 3213bfba7a k8s-services: seed with the stream content type, give the grafana responder its own port name, and print gateway diagnostics on a refusal
the grafana responder's service targeted the port name api, which resolves to the logs responder's container; its port is now grafana-api.

the node-ready wait is raised from 300 to 600 seconds: slow k3s image imports on this test's machine kept the node from registering in vm-nightly 8992 and 8997, so the test never reached the subtests this change fixes.
2026-11-27 18:07:59 +01:00

717 lines
30 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# The swarm's log store: one VictoriaLogs for the whole swarm and the gateway's
# `auth_request` responders for it, each a pod in the host's cluster
# (./k8s/render.nix, docs/4-implementation/k8s/runtime.md).
#
# Why a store at all rather than reading journals directly: an agent can
# verify that a unit was *launched* and never that it is *working*. The
# container journals are not reachable from an agent, so a diagnosis stops at
# the first component that is broken — which is precisely the component whose
# own instrument is least likely to be legible. Collecting logs centrally
# makes the question answerable without host access.
#
# It is the collector that feeds this, not the services directly: one ingest
# point per swarm, same shape as the metrics path.
#
# Gateway vhost is authenticated, unlike the metrics store's: an operator
# 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.
# ⚠️ 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.
#
# The query API has a machine route of the same shape at `^~ /select/logsql/`,
# for the same reason, and with no filtering of what an authenticated caller
# may read — see that location.
{
pkgs,
lib,
config,
...
}:
let
cfg = config.services.hyperhive.swarm.victorialogs;
deployCfg = config.services.hyperhive.deploy;
networkCfg = config.services.hyperhive.network;
hyperhiveCfg = config.services.hyperhive;
gatewayCfg = hyperhiveCfg.gateway;
k8sCfg = hyperhiveCfg.k8s;
inherit (import ../images { inherit pkgs lib; }) mkServiceImage;
# Copy of `swarm-ui.nix`'s own `swarmAuthRequest` — not shared code because
# this vhost needs exactly the two locations that reference it (`/` and the
# internal auth-request target below) and pulling in swarm-ui.nix for one
# string would couple this module to swarm-ui existing at all, which it
# need not. Same three lines, same reasoning as that file's own comment.
swarmAuthRequest = ''
auth_request /__hive_authelia;
auth_request_set $target_url $scheme://$http_host$request_uri;
error_page 401 =302 https://${hyperhiveCfg.swarm.authelia.domain}/?rd=$target_url;
'';
# Cache directives for the ingest route's authelia subrequest. The key is
# the `Authorization` header and the route, and only a 200 is stored, so a
# 401 or 403 always reaches authelia again. A request without an
# `Authorization` header skips the cache both ways
# (`swarm_logs_ingest_nocache` in `appendHttpConfig`), so a cached grant is
# never read by a caller that presented no token. The `Cookie` header is
# dropped from the subrequest, because authelia also accepts a session
# cookie and the key does not cover it. `proxy_ignore_headers` makes the
# `proxy_cache_valid` line the only lifetime, whatever cache headers
# authelia sends.
ingestAuthzCache = ''
proxy_set_header Cookie "";
proxy_cache swarm_logs_ingest_authz;
proxy_cache_key "$http_authorization|$http_host$request_uri";
proxy_cache_valid 200 60s;
proxy_cache_lock on;
proxy_cache_lock_timeout 30s;
proxy_cache_use_stale updating;
proxy_cache_bypass $swarm_logs_ingest_nocache;
proxy_no_cache $swarm_logs_ingest_nocache;
proxy_ignore_headers Cache-Control Expires Set-Cookie Vary;
'';
# The store identity the responders' units name by credential id: the pod
# logs in with its ServiceAccount token instead, and mounts the CA file.
logsAuthStoreIds = [
"bao-client.pem"
"bao-client-key.pem"
]
++ lib.optional (deployCfg.bao.serverCaFile != null) "bao-ca.pem";
baoCfg = hyperhiveCfg.swarm.bao;
# Grafana's bearer, checked by a second `swarm-metrics-auth` instance. It
# reads the store with the same leaf as `swarm-logs-auth`, which is granted
# the one extra path below. The same leaf as `grafanaBearerStorePath` in
# ./swarm-victoriametrics.nix and `grafanaMetricsBearerLeaf` in ./swarm-bao.nix.
grafanaBearerStorePath = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/metrics/bearer";
# The workloads, as the cluster names them: the store, and the one pod that
# holds both responders. Each has a Service of its name, which the gateway
# dials. `legacyContainer` is the name of the container the store ran in
# before it ran in the cluster, whose data directory the volume is.
storeService = "swarm-victorialogs";
authService = "swarm-logs-auth";
grafanaAuthService = "swarm-logs-grafana-auth";
legacyContainer = "swarm-victorialogs";
storePort = 9428;
authPort = 8081;
grafanaAuthPort = 8082;
# The Grafana responder's own `/healthz` and `/readyz`, beside the logs
# responder's on 8080 in the same pod.
grafanaAuthHealthPort = 8083;
dataDir = "/var/lib/victorialogs";
hostDataDir = "/var/lib/nixos-containers/${legacyContainer}${dataDir}";
serviceHost = service: "${service}.${k8sCfg.namespace}.svc.${deployCfg.k8s.clusterDomain}";
# What a location needs to dial a Service: the host's resolver, which hands
# the cluster's domain to CoreDNS, and the name in a variable, so that nginx
# looks it up per request. A name written into `proxy_pass` gets one lookup
# when the configuration loads, which fails the load while the cluster is
# down. A `proxy_pass` with a variable and a URI part sends that URI and not
# the request's own, so the store's locations write none. Each role has a
# variable of its own, so that an auth subrequest's `set` can never change
# where the request it checks is sent.
viaService = variable: service: port: ''
resolver ${networkCfg.bridgeIp} valid=10s ipv6=off;
set ${variable} ${serviceHost service}:${toString port};
'';
storeVariable = "$swarm_logs_store_upstream";
upstream = "http://${storeVariable}";
agentAuthVariable = "$swarm_logs_agent_auth_upstream";
grafanaAuthVariable = "$swarm_logs_grafana_auth_upstream";
# The store's unit: the daemon, its flags and its state directory, which is
# all the pod is rendered from. Nothing evaluates a systemd unit for it.
storeUnit = {
serviceConfig = {
ExecStart = lib.concatStringsSep " " [
"${deployCfg.victorialogs.package}/bin/victoria-logs"
"-storageDataPath=${dataDir}"
"-httpListenAddr=:${toString storePort}"
"-retentionPeriod=${deployCfg.victorialogs.retentionPeriod}"
];
StateDirectory = "victorialogs";
};
environment = { };
path = [ ];
};
# The agents' `auth_request` responder, with the cert and key ids that the
# pod's login drops.
authCredential = id: "/run/credentials/${authService}.service/${id}";
authUnit = {
serviceConfig = {
ExecStart = lib.concatStringsSep " " [
"${deployCfg.victorialogs.authPackage}/bin/swarm-logs-auth"
"--listen 0.0.0.0:${toString authPort}"
# The role ./swarm-bao.nix writes on the store's `cert` mount.
"--store-cert-role swarm-logs-auth"
"--surface logs"
"--verdict-ttl ${toString deployCfg.victorialogs.authVerdictTtl}"
];
LoadCredential = logsAuthStoreIds;
};
environment = {
BAO_ADDR = "https://${baoCfg.domain}:${toString baoCfg.port}";
BAO_CLIENT_CERT = authCredential "bao-client.pem";
BAO_CLIENT_KEY = authCredential "bao-client-key.pem";
}
// lib.optionalAttrs (builtins.elem "bao-ca.pem" logsAuthStoreIds) {
BAO_CACERT = authCredential "bao-ca.pem";
};
path = [ ];
};
# What the responders' pod holds besides `swarm-logs-auth`: Grafana's
# responder, the metrics store's binary pointed at the bearer Grafana's
# datasources share. It logs in under the pod's one ServiceAccount, with the
# environment and mounts of the first container.
authPod =
{
env,
volumeMounts,
metaFor,
securityContext,
}:
let
image = mkServiceImage {
name = grafanaAuthService;
package = deployCfg.victorialogs.grafanaAuthPackage;
bin = "swarm-metrics-auth";
};
probe = path: {
httpGet = {
inherit path;
port = "health";
};
periodSeconds = 10;
};
in
{
containers = [
{
name = "grafana-auth";
image = "${image.imageName}:${image.imageTag}";
imagePullPolicy = "IfNotPresent";
args = [
"--listen"
"0.0.0.0:${toString grafanaAuthPort}"
"--store-cert-role"
"swarm-logs-auth"
"--store-path"
grafanaBearerStorePath
];
env = lib.mapAttrsToList (name: value: { inherit name value; }) (
lib.filterAttrs (n: _: lib.hasPrefix "BAO_" n) env
// {
SWARM_METRICS_AUTH_HEALTH_ADDR = "0.0.0.0:${toString grafanaAuthHealthPort}";
}
);
# Not `api`: a Service resolves a named port to the first container of the
# pod that declares the name, which is the logs responder's.
ports = [
{
name = "grafana-api";
containerPort = grafanaAuthPort;
}
{
name = "health";
containerPort = grafanaAuthHealthPort;
}
];
livenessProbe = probe "/healthz";
readinessProbe = probe "/readyz";
volumeMounts = lib.filter (
m:
lib.elem m.name [
"credentials"
"bao-token"
"tmp"
]
) volumeMounts;
inherit securityContext;
}
];
# The pod's policy, from ./k8s/render.nix, covers this port too: only the
# node reaches it.
objects."${grafanaAuthService}/service" = {
apiVersion = "v1";
kind = "Service";
metadata = metaFor authService // {
name = grafanaAuthService;
};
spec = {
type = "ClusterIP";
selector = (metaFor authService).labels;
ports = [
{
name = "api";
protocol = "TCP";
port = grafanaAuthPort;
targetPort = "grafana-api";
}
];
};
};
images = [ image ];
};
in
{
# What the store IS from any hive's point of view, the name it answers on, is
# `swarm.victorialogs` in ./swarm-victorialogs-service.nix.
# `enable`, `package` and `retentionPeriod` are decisions of the host that
# runs it and live under `deploy.*`.
# Retention is a property of the store this host runs, not something the
# swarm has to agree on: it is read only where the pod is defined, and a hive
# that is a *client* of the log store never consults it. That makes it a
# `deploy.*` value by the same rule as the seal on the secret store —
# options on the auto-deployed service itself.
options.services.hyperhive.deploy.victorialogs.package = lib.mkOption {
type = lib.types.package;
default = pkgs.victorialogs;
defaultText = lib.literalExpression "pkgs.victorialogs";
description = "VictoriaLogs package to run.";
};
options.services.hyperhive.deploy.victorialogs.retentionPeriod = lib.mkOption {
type = lib.types.str;
default = "30d";
example = "90d";
description = ''
How long log data is kept.
Deliberately far shorter than the metrics store's retention: logs
are orders of magnitude larger per unit of time, and their value
decays much faster. A log line answers "what happened during that
incident"; a metric answers "is this worse than last quarter".
'';
};
options.services.hyperhive.deploy.victorialogs.authPackage = lib.mkOption {
type = lib.types.package;
defaultText = lib.literalExpression "hyperhive.packages.\${system}.swarm-logs-auth";
description = ''
The `swarm-logs-auth` package: the gateway's `auth_request` responder
that checks an agent's `swarm-agent.<agent>.<secret>` bearer on
`/select/logsql/` against the secret store.
'';
};
options.services.hyperhive.deploy.victorialogs.grafanaAuthPackage = lib.mkOption {
type = lib.types.package;
defaultText = lib.literalExpression "hyperhive.packages.\${system}.swarm-metrics-auth";
description = ''
The `swarm-metrics-auth` package, run as `swarm-logs-grafana-auth`: the
gateway's `auth_request` responder that checks the bearer Grafana's
logs datasource presents on `/select/logsql/` against the secret store.
⚠️ Not folded into `authPackage` above: that one is `swarm-logs-auth`,
a different binary. Same split as
{option}`services.hyperhive.deploy.nats.authPackage`.
'';
};
options.services.hyperhive.deploy.victorialogs.authBaoClientCertFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/var/lib/swarm-bao-pki/logs-auth.pem";
description = ''
Client certificate `swarm-logs-auth` presents to the swarm's secret store
to read agents' queue secrets. Its subject must be
{option}`services.hyperhive.deploy.bao.logsAuthCommonName`.
Required when `deploy.victorialogs.enable` is set; unset fails at eval.
./glue-logs-auth-bao-identity.nix points it at the leaf
./glue-bao-tls.nix mints on a host that runs the store; on any other
log-store host it is a file the operator places.
A path, never a value.
'';
};
options.services.hyperhive.deploy.victorialogs.authBaoClientKeyFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/var/lib/swarm-bao-pki/logs-auth-key.pem";
description = ''
Private key for {option}`services.hyperhive.deploy.victorialogs.authBaoClientCertFile`.
A path, never a value.
'';
};
options.services.hyperhive.deploy.victorialogs.authVerdictTtl = lib.mkOption {
type = lib.types.ints.unsigned;
default = 60;
description = ''
Seconds `swarm-logs-auth` grants an agent bearer it has verified again
without reading the secret store. A denial is never remembered.
This is also how long a re-minted or deleted queue secret keeps working
at the log store's query route after its last successful check. It is
equally how long a revoked `logs` permission keeps working. `0` checks
the store on every query.
'';
};
options.services.hyperhive.deploy.victorialogs.authRate = lib.mkOption {
type = lib.types.str;
default = "50r/s";
example = "30r/m";
description = ''
nginx `limit_req` rate, per client address, of `/select/logsql/`
requests carrying a `swarm-agent.` bearer, which nginx checks with
`swarm-logs-auth`. Each such request that the responder has not granted
within {option}`services.hyperhive.deploy.victorialogs.authVerdictTtl`
costs a secret store login and read, whether the bearer is right or not.
Counts every agent query, granted or not, and is keyed by client address,
so every agent on one host shares one budget. The default covers about a
hundred agents on a host cold-starting at once, each costing one store
login and read for its first query. Requests over the rate and its burst
are answered 403.
'';
};
options.services.hyperhive.deploy.victorialogs.authBurst = lib.mkOption {
type = lib.types.ints.positive;
default = 500;
description = ''
Requests a client address may make above
{option}`services.hyperhive.deploy.victorialogs.authRate` before nginx
answers 403, served without delay.
'';
};
options.services.hyperhive.deploy.victorialogs.unit = lib.mkOption {
type = lib.types.raw;
readOnly = true;
internal = true;
default = storeUnit;
description = ''
The store's unit, the `serviceConfig`, `environment` and `path` that
../host-modules/k8s/render.nix renders its pod from.
'';
};
options.services.hyperhive.deploy.victorialogs.authUnit = lib.mkOption {
type = lib.types.raw;
readOnly = true;
internal = true;
default = authUnit;
description = ''
The agents' responder's unit, which the first container of the
responders' pod is rendered from.
'';
};
options.services.hyperhive.deploy.victorialogs.pod = lib.mkOption {
type = lib.types.raw;
readOnly = true;
internal = true;
default = authPod;
description = ''
What the responders' pod holds besides the agents' responder: a function
of that container that ../host-modules/k8s/render.nix calls, giving
Grafana's responder, its Service and its image.
'';
};
options.services.hyperhive.deploy.victorialogs.servicePort = lib.mkOption {
type = lib.types.port;
readOnly = true;
internal = true;
default = storePort;
description = "The port the store's Service publishes.";
};
options.services.hyperhive.deploy.victorialogs.authServicePort = lib.mkOption {
type = lib.types.port;
readOnly = true;
internal = true;
default = authPort;
description = "The port the agents' responder's Service publishes.";
};
options.services.hyperhive.deploy.victorialogs.hostDataDir = lib.mkOption {
type = lib.types.str;
readOnly = true;
internal = true;
default = hostDataDir;
description = ''
The store's data directory on the host, which the pod's volume is: the
directory of the container the store ran in. A host that never ran it gets
the directory made.
'';
};
config = lib.mkIf deployCfg.victorialogs.enable {
assertions = [
{
assertion =
deployCfg.victorialogs.authBaoClientCertFile != null
&& deployCfg.victorialogs.authBaoClientKeyFile != null;
message = ''
services.hyperhive.deploy.victorialogs.authBaoClientCertFile and
authBaoClientKeyFile must both be set.
swarm-logs-auth reads agents' queue secrets from the swarm's secret
store with this certificate. They default to the leaf the store
mints where services.hyperhive.deploy.bao.enable is set on this
host; elsewhere, issue a leaf whose CN is
services.hyperhive.deploy.bao.logsAuthCommonName and name it in
both options.
'';
}
];
# Which check a `/select/logsql/` request gets. `auth_request` takes a
# fixed URI, so it names `/__swarm_logs_auth`, which rewrites to the
# target this map picks from the caller's `Authorization`.
services.nginx.appendHttpConfig = ''
map $http_authorization $swarm_logs_auth_target {
"~^Bearer swarm-agent\." /__swarm_logs_agent_auth;
"~^Bearer [0-9a-f]{64}$" /__swarm_logs_grafana_auth;
default /__hive_authelia;
}
limit_req_zone $binary_remote_addr zone=swarm_logs_agent_auth:1m rate=${deployCfg.victorialogs.authRate};
map $http_authorization $swarm_logs_ingest_nocache {
"" 1;
default 0;
}
'';
# The zone behind `ingestAuthzCache`.
services.nginx.proxyCachePath.swarm_logs_ingest_authz = {
enable = true;
keysZoneName = "swarm_logs_ingest_authz";
keysZoneSize = "1m";
maxSize = "10m";
inactive = "10m";
};
# The gateway name, inside `deployCfg.victorialogs.enable` — same
# "only the host that runs the service may claim the name" guard every
# sibling swarm-service module uses (`swarm-grafana.nix`,
# `swarm-victoriametrics.nix`).
services.hyperhive.gateway.localNames = [ cfg.domain ];
# This host serves the vhost and resolves the cluster's names for it
# through the hive's dnsmasq.
services.hyperhive.gateway.enable = lib.mkDefault true;
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.
# `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
# vhost needs `forceSSL` rather than the `addSSL` every unauthenticated
# sibling vhost uses.
services.hyperhive.gateway.vhosts."${cfg.domain}" = {
forceSSL = true;
locations = {
"/" = {
proxyPass = upstream;
extraConfig = viaService storeVariable storeService storePort + swarmAuthRequest;
};
# The swarm collector's ingest route. `=` so it outranks the `/`
# prefix above — without a more specific location it would ride that
# catch-all, and that is the whole hazard here.
#
# ⚠️ Deliberately NOT `swarmAuthRequest`. That block ends in
# `error_page 401 =302`, which is right for a browser and wrong for a
# pusher: handed a redirect it follows the redirect and POSTs its
# batch at a login page, which answers 200. Ingest then reports
# healthy while storing nothing. A machine route lets the 401 reach
# the client unchanged.
#
# `auth_request` does not inherit across sibling locations (see the
# note on `swarmAuthRequest` above), so naming it here is required
# rather than redundant.
"= /insert/opentelemetry/v1/logs" = {
proxyPass = upstream;
extraConfig = ''
${viaService storeVariable storeService storePort}
auth_request /__swarm_logs_ingest_authz;
'';
};
# The read side of that same split: the route a caller holding a
# bearer token queries, as opposed to the `/` above which is the
# operator's browser. Bare `auth_request` for the ingest route's
# exact reason — `error_page 401 =302` hands an unauthenticated
# machine caller authelia's login page as a **200 with an HTML
# body**, so a client that reads the status code records a
# successful query that returned no rows. 401 is the only answer
# here that a caller cannot mistake for an empty result.
#
# `^~` so it outranks the `/` catch-all and stays ahead of any
# regex location a later change adds. The prefix is the whole
# LogsQL query API and nothing else — `query`, `tail`, `hits`,
# `facets`, the `stats_query*` and the `field_*`/`stream_*`
# routes — while the browser UI sits beside it under
# `/select/vmui`. Both read off the pinned build, not the docs.
#
# The query is forwarded unmodified — no scoping parameter is
# injected, so any authenticated caller reads the whole swarm's
# logs. That is the rule in force, not an omission: read
# permissions are a later thing, and this location is where one
# attaches when it exists.
#
# Three checks: an agent's own `swarm-agent.` bearer goes to
# `swarm-logs-auth`, Grafana's 64-hex bearer to `swarm-metrics-auth`,
# anything else to authelia (`appendHttpConfig` above picks).
"^~ /select/logsql/" = {
# No URI part, so the request path and its query string reach
# the store as the caller sent them.
proxyPass = upstream;
extraConfig = ''
${viaService storeVariable storeService storePort}
auth_request /__swarm_logs_auth;
'';
};
# The store's own health, which it publishes as prometheus metrics
# on the listener it serves queries on. The swarm collector requests
# exactly this URL, declared as `publishedScrapeTargets.victorialogs`
# in ./swarm-otel-service.nix; the two must agree, since that string
# is also the token's audience.
#
# Bare `auth_request` to authelia, as on the ingest route above, and
# never `/__swarm_logs_auth`, which admits an agent's bearer:
# authelia's rules for this URL admit the collector's client and
# deny every other subject (see `metricsRules` in ./swarm-authelia.nix).
"= /metrics" = {
proxyPass = upstream;
extraConfig = ''
${viaService storeVariable storeService storePort}
auth_request /__hive_authelia;
'';
};
# `rewrite … last` re-matches locations, so the subrequest lands in
# one of the two internal locations named by the map.
"= /__swarm_logs_auth" = {
extraConfig = ''
internal;
rewrite ^ $swarm_logs_auth_target last;
'';
};
# The `Authorization` header rides the subrequest unchanged.
#
# Any well-formed agent bearer the responder has not recently granted
# costs a secret store login and read, so the rate per client address
# is capped here, ahead of the responder. 403 when over: the only
# statuses `auth_request` passes through are 401 and 403, and
# `swarm-logs` retries a 401.
"= /__swarm_logs_agent_auth" = {
proxyPass = "http://${agentAuthVariable}/";
extraConfig = ''
${viaService agentAuthVariable authService authPort}
internal;
limit_req zone=swarm_logs_agent_auth burst=${toString deployCfg.victorialogs.authBurst} nodelay;
limit_req_status 403;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
'';
};
# Grafana's bearer, 64 hex digits (`openssl rand -hex 32`), checked by
# `swarm-metrics-auth`. The responder reads the store at most once per
# its cache TTL whatever the bearers, so no rate limit sits in front.
"= /__swarm_logs_grafana_auth" = {
proxyPass = "http://${grafanaAuthVariable}/";
extraConfig = ''
${viaService grafanaAuthVariable grafanaAuthService grafanaAuthPort}
internal;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
'';
};
# The ingest route's copy of the subrequest below, plus the verdict
# cache. Separate because `/__hive_authelia` also serves the browser
# and scrape routes, which must not be cached.
"= /__swarm_logs_ingest_authz" = {
proxyPass = "https://${hyperhiveCfg.swarm.authelia.domain}/api/authz/auth-request";
recommendedProxySettings = false;
extraConfig = ''
internal;
${gatewayCfg.lib.verifiedProxyTo hyperhiveCfg.swarm.authelia.domain}
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-Method $request_method;
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
${ingestAuthzCache}
'';
};
# The subrequest itself — same target, same header set, same
# reasoning as `swarm-ui.nix`'s own copy (measured against the
# pinned authelia binary, not copied from an example).
"= /__hive_authelia" = {
proxyPass = "https://${hyperhiveCfg.swarm.authelia.domain}/api/authz/auth-request";
# nixpkgs appends its OWN `Host $host` after extraConfig,
# which would override verifiedProxyTo's — see the comment
# on verifiedProxyTo in hive-gateway/vhost-lib.nix.
recommendedProxySettings = false;
extraConfig = ''
internal;
${gatewayCfg.lib.verifiedProxyTo hyperhiveCfg.swarm.authelia.domain}
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-Method $request_method;
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
};
};
};
# The store's volume is its old container's data directory, which a host
# that never ran the container does not have. The rule leaves an existing
# directory's owner and mode alone: the pod's group is given the tree when
# it starts.
systemd.tmpfiles.rules = [ "d ${hostDataDir} - - - -" ];
# The pods reach the secret store through the hive bridge.
services.hyperhive.network.enable = lib.mkDefault true;
};
# 🔑 OTLP ingest is served at `/insert/opentelemetry/v1/logs`, measured
# against the pinned build rather than read from docs. The path differs
# from the metrics store's `/opentelemetry/api/v1/push`, so an exporter
# configured by analogy with the metrics one is silently wrong.
#
# ⚠️ And the status code cannot tell you which is which: a wrong path, a
# right path with a wrong body, and a nonsense path ALL answer 400. Only
# the server log distinguishes them — the real route complains about the
# encoding ("json encoding isn't supported ... use protobuf"), while
# anything else logs "unsupported path requested". Verified with a
# 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.)
}