Watch
0
0
Fork
You've already forked hyperhive
0

gateway reaches the controller over tls with its own client leaf when the tcp listener is on

This commit is contained in:
atlas 2026-11-15 16:10:59 +01:00 • committed by mara
commit 187ed82de0

View file

@ -106,12 +106,46 @@ let
matrixCfg = swarmCfg.matrix;
serverName = if matrixCfg.serverName != null then matrixCfg.serverName else apex;
servesMatrixDiscovery = matrixCfg.gatewayHost != null && serverName == apex;
# How the gateway reaches the controller. Its unix socket by default. With
# the controller's TCP listener on, over TLS by the listener's name, with
# the gateway's client leaf — the listener refuses a handshake without it
# (./swarm-controller.nix). `controllerDial` is empty on the socket, so the
# two locations below render exactly what they rendered before the
# listener existed.
# `toString` below so an unset `domain` reaches the assertion that names it
# instead of failing evaluation first.
controllerTcp = swarmCfg.controller.tcp;
controllerUpstream =
if controllerTcp.enable then
"https://${toString controllerTcp.domain}:${toString controllerTcp.port}"
else
"http://unix:${deployCfg.swarm-controller.socketPath}:";
# `proxy_http_version` and `Connection` because `recommendedProxySettings`,
# which sets them, is off on a location that pins its own `Host`: without
# them nginx speaks HTTP/1.0 to the upstream, which ends the SSE streams'
# keep-alive.
controllerDial = lib.optionalString controllerTcp.enable ''
${gatewayCfg.lib.verifiedProxyToWithClientCert (toString controllerTcp.domain) {
certificate = deployCfg.swarm-controller.tcp.gatewayClientCertFile;
key = deployCfg.swarm-controller.tcp.gatewayClientKeyFile;
}}
proxy_http_version 1.1;
proxy_set_header Connection "";
'';
controllerDialAttrs = lib.optionalAttrs controllerTcp.enable {
# nixpkgs appends its own `Host $host` after `extraConfig`, which would
# override the pinned one — see the comment on verifiedProxyTo in
# hive-gateway/vhost-lib.nix.
recommendedProxySettings = false;
};
in
{
# No `enable` of its own: the UI is on wherever
# `services.hyperhive.deploy.swarm-controller.enable` is, because it reaches
# that daemon over its unix socket. There is no `domain` option: the UI
# answers on the swarm apex, which the swarm already declares once.
# that daemon over its unix socket, or over its TCP listener when that is on.
# There is no `domain` option: the UI answers on the swarm apex, which the
# swarm already declares once.
# ⚠️ Neither `services.hyperhive.swarm.ui` nor `deploy.swarm-ui` is a
# namespace for anything but the old spellings: the UI's `package` lives
@ -295,8 +329,8 @@ in
# shape as the per-hive dashboard's own `/api/` proxy) so the
# path swarm-controller registered a route at is the path
# nginx forwards, no prefix-stripping to keep in sync by hand.
"/api/" = {
proxyPass = "http://unix:${deployCfg.swarm-controller.socketPath}:";
"/api/" = controllerDialAttrs // {
proxyPass = controllerUpstream;
# `Remote-User` from authelia's answer, set here so it replaces
# any the client sent: swarm-controller takes it as the sender of
# the text the operator types to an agent (`agent_input.rs`).
@ -313,7 +347,8 @@ in
# must not sit in nginx's buffer. The controller's 15s
# keep-alive keeps them under nginx's 60s default read timeout.
proxy_buffering off;
'';
''
+ controllerDial;
};
# A refused request gets the login page only when it asks for a page.
# The swarm UI calls `/api/` with `fetch` and `EventSource`, and a
@ -356,9 +391,14 @@ in
# carve-out is exactly as wide as the endpoint that justifies it:
# a future `/webhook/<something-else>` does not inherit the
# bypass by living under a shared prefix.
"/webhook/forge/" = {
proxyPass = "http://unix:${deployCfg.swarm-controller.socketPath}:";
};
"/webhook/forge/" =
controllerDialAttrs
// {
proxyPass = controllerUpstream;
}
// lib.optionalAttrs controllerTcp.enable {
extraConfig = controllerDial;
};
# Swagger UI: same "nginx hosts the themed dist straight from
# the store, only /api/openapi.json is dynamic" shape as the
# hive dashboard's `swaggerUiLocations` (./hive-c0re/vhosts.nix).