diff --git a/docs/integrations/matrix.md b/docs/integrations/matrix.md index e358462f4..de4601b43 100644 --- a/docs/integrations/matrix.md +++ b/docs/integrations/matrix.md @@ -54,9 +54,7 @@ homeserver. ⚠️ **they're still not interchangeable, and the difference is the cost of changing one.** `gatewayHost` is a routing detail clients rediscover through `.well-known`, so it's safe to move on a running -deployment. The controller's host serves that `.well-known` on the swarm -domain, and a homeserver pinned to a hive domain gets it on that hive's -vhost. The matrix id format bakes `serverName` into every user and +deployment. The matrix id format bakes `serverName` into every user and room id, so adopting a new one does **not** rename the existing users and rooms — it strands them, because their ids still name a homeserver that no longer answers. @@ -80,10 +78,6 @@ A rebuild on a host that already has a homeserver prints a naming the value it's about to default to. It never fails the rebuild, so pin the value before the homeserver mints any ids under the default. -A pinned hive domain answers `.well-known/matrix/*` itself, built from -`gatewayHost`, on any host that runs that hive's gateway. It doesn't need -the homeserver on the same host. - ## Reach @@ -104,7 +98,7 @@ homeserver it crosses the network, so the default is TLS; hive-c0re verifies the gateway's certificate against the hive trust bundle. Federation peers find the homeserver through `.well-known/matrix/server` -at the server name, which names `:443` +on the hive domain, which names `:443` ([`gateway.md::Discovery flow`](../networking/gateway.md#discovery-flow-matrix)). Port 8448 isn't used. diff --git a/docs/networking/gateway.md b/docs/networking/gateway.md index 15b8a7053..613a03791 100644 --- a/docs/networking/gateway.md +++ b/docs/networking/gateway.md @@ -1,6 +1,6 @@ # hive-gateway -Every host's nginx: the one front door for whatever this host serves. A swarm service running here (forge, matrix, SSO, the swarm UI, the metrics and log stores) declares its own vhost through the gateway; the gateway itself adds the hive's own surface — dashboard, per-agent UIs, and discovery for a server name pinned to the hive domain. +Every host's nginx: the one front door for whatever this host serves. A swarm service running here (forge, matrix, SSO, the swarm UI, the metrics and log stores) declares its own vhost through the gateway; the gateway itself adds the hive's own surface — dashboard, per-agent UIs, matrix discovery. _For the operator configuring `services.hyperhive.gateway.*` on a host._ nginx and the hive resolver (dnsmasq) run on the host next to hive-c0re: they bind `:80`/`:443` and the bridge address. @@ -22,7 +22,7 @@ You rarely switch it on yourself. `gateway.enable` defaults to off, and every mo | `/metrics` | the queue exporter's `/metrics` on loopback, behind an authelia `auth_request`; every other path, `/` included, returns `403`, so `/varz` and `/connz` are never reachable | `swarm-nats.nix`, the queue's host | | `grafana.`, `metrics.`, `logs.`, `otel.`, `bao.` | the matching swarm service | that service's module → [`swarm/services.md`](../swarm/services.md) | -A service module declares its vhost as `services.hyperhive.gateway.vhosts.`: the locations, `forceSSL` and any `extraConfig` it needs. The gateway renders it into `services.nginx.virtualHosts.` and adds the `listen` set, the certificate for that name and the [security headers](#security-headers) (ahead of the vhost's own `extraConfig`), and drops `addSSL` from a vhost that sets `forceSSL`. The eval fails for a vhost that sets `listen`, `addSSL`, `onlySSL`, `enableACME`, `useACMEHost`, `sslCertificate` or `sslCertificateKey` itself, and for any vhost declared while `gateway.enable` is false. A name with a certificate from outside the gateway's leaves (the queue's) sets `certificate = { cert; key; }` instead. `hive-gateway/vhosts.nix` declares the gateway's own catch-all (`_`) the same way, `hive-c0re/vhosts.nix` the dashboard and the hive domain, and `glue-matrix-hive-discovery.nix` adds the matrix redirect to the hive domain where the homeserver runs, and discovery there when the hive domain is the pinned server name. The catch-all sets `securityHeaders = false` because it sends no response, and the gateway renders a vhost's `default` at `mkDefault` priority. +A service module declares its vhost as `services.hyperhive.gateway.vhosts.`: the locations, `forceSSL` and any `extraConfig` it needs. The gateway renders it into `services.nginx.virtualHosts.` and adds the `listen` set, the certificate for that name and the [security headers](#security-headers) (ahead of the vhost's own `extraConfig`), and drops `addSSL` from a vhost that sets `forceSSL`. The eval fails for a vhost that sets `listen`, `addSSL`, `onlySSL`, `enableACME`, `useACMEHost`, `sslCertificate` or `sslCertificateKey` itself, and for any vhost declared while `gateway.enable` is false. A name with a certificate from outside the gateway's leaves (the queue's) sets `certificate = { cert; key; }` instead. `hive-gateway/vhosts.nix` declares the gateway's own catch-all (`_`) the same way, `hive-c0re/vhosts.nix` the dashboard and the hive domain, and `glue-matrix-hive-discovery.nix` adds matrix discovery to the hive domain where the homeserver runs. The catch-all sets `securityHeaders = false` because it sends no response, and the gateway renders a vhost's `default` at `mkDefault` priority. **The hive's own vhosts**: the dashboard's, named `.hives.` (`swarm.dashboardDomain`), and one named for the hive domain. They exist only on a host that runs a hive (`deploy.hive-controller.enable`); a host without a hive has none of these rows: @@ -33,8 +33,7 @@ A service module declares its vhost as `services.hyperhive.gateway.vhosts. | `.hives./health/` | hive-c0re (`7000`) | always | | `.hives./api/docs/` | themed Swagger UI dist (static), behind authelia | always | | `.hives./agent//` | per-agent harness over its unix socket | `agents.conf` (runtime-generated) | -| `/.well-known/matrix/{client,server}` | inline JSON | `deploy.swarm-controller.enable`, and `swarm.matrix.serverName` is the swarm domain (the default) | -| `/.well-known/matrix/{client,server}` | inline JSON | `swarm.matrix.serverName` is this hive's domain (a pinned homeserver) | +| `/.well-known/matrix/{client,server}` | inline JSON | `deploy.matrix.enable` | | `/matrix/` | 301 → `chat./` | `deploy.matrix.enable` and `gatewayHost` set | | `/` (every other path) | 301 → `.hives.`, same path | always | @@ -118,7 +117,7 @@ Give the gateway the real cert (`tls.certDir` or `tls.acme`) so it serves proper The dashboard answers on `.hives.` (`swarm.dashboardDomain`, derived from the hive name and `swarm.domain`), behind an authelia `auth_request`. Log in with your authelia account; only accounts in the `admins` group get in, the same rule as the swarm UI. Add one with `swarmctl user add --group admins` ([`swarm/sso.md`](../swarm/sso.md)). -The name sits under the swarm domain so authelia's session cookie reaches it, whatever the hive's own domain is. Any path on the hive domain other than the matrix routes redirects there, so old bookmarks still land. +The name sits under the swarm domain so authelia's session cookie reaches it, whatever the hive's own domain is. Any path on the hive domain other than matrix discovery redirects there, so old bookmarks still land. **What it gates:** `/`, `/api/` and `/api/docs/`. **Not gated:** `/health/` (for uptime monitors; status only) and the per-agent `/agent//` routes, which come from `agents.conf` and carry no `auth_request`. @@ -209,11 +208,9 @@ When enabled, every vhost adds `Strict-Transport-Security: max-age=…[; include ## Discovery flow (matrix) -The server name's own vhost serves discovery, whichever host runs the homeserver. By default that vhost is the swarm apex on the controller's host; a homeserver pinned to a hive domain gets it on that hive's vhost instead. Both build the JSON from `swarm.matrix.gatewayHost` alone, and the `base_url` carries no port. +The operator points a client at ``: -The operator points a client at the server name (`` below): - -1. The client fetches `https:///.well-known/matrix/client` → `{"m.homeserver":{"base_url":"https://chat."}}`. +1. The client fetches `https:///.well-known/matrix/client` → `{"m.homeserver":{"base_url":"https://chat."}}`. 2. It connects to `chat./_matrix/client/...`. 3. The gateway proxies `/_matrix/*` to tuwunel over its unix socket, `/run/hive-matrix/tuwunel.sock`. diff --git a/docs/swarm/README.md b/docs/swarm/README.md index cef2c113a..e9c4666ce 100644 --- a/docs/swarm/README.md +++ b/docs/swarm/README.md @@ -553,7 +553,7 @@ mechanism. 2. **Matrix federation** — when this host runs the homeserver (`deploy.matrix.enable`), tuwunel federates with the peer's matrix server (discovered via the peer's - `.well-known/matrix/server` delegation, which the controller's host or the pinned hive's gateway serves). + `.well-known/matrix/server` delegation, which the gateway serves). Federation validates the peer's TLS certificate against the matrix **container's** trust bundle, independent of this directory. diff --git a/docs/swarm/ui.md b/docs/swarm/ui.md index b6b00fedf..1a8626321 100644 --- a/docs/swarm/ui.md +++ b/docs/swarm/ui.md @@ -805,7 +805,7 @@ which a service's own module already has to push its domain into to be resolvable — see `nix/host-modules/hive-gateway/dnsmasq.nix` and `.../default.nix`'s `networking.hosts`. `vhosts.nix` itself is scoped to the surface the hive's own domain serves (dashboard, per-agent routing, -pinned-hive discovery); a swarm service declares its own vhost next to its +matrix discovery); a swarm service declares its own vhost next to its own options, the way `swarm-ui.nix` and `swarm-authelia.nix` do. diff --git a/nix/host-modules/glue-matrix-hive-discovery.nix b/nix/host-modules/glue-matrix-hive-discovery.nix index 1f33d4b6b..12c78ae8c 100644 --- a/nix/host-modules/glue-matrix-hive-discovery.nix +++ b/nix/host-modules/glue-matrix-hive-discovery.nix @@ -1,17 +1,16 @@ -# Glue: matrix's links on the hive domain's vhost. +# Glue: serve the swarm homeserver's discovery on the hive domain's vhost +# wherever both run. # # ONE PAIRING PER FILE — matrix → hive domain vhost, and nothing else. +# Deleting this leaves federation and clients with no `.well-known/matrix/*` +# answer at the server name, and the legacy `/matrix/*` links 404. # -# Two pieces, each under its own condition: -# - `.well-known/matrix/{client,server}` is served here only when the hive -# domain IS the homeserver's server name (a homeserver that pinned -# `swarm.matrix.serverName` to it): the spec reads delegation off the -# *server name*. The host need not run the homeserver, since the JSON is -# built from `swarm.matrix.gatewayHost` alone. For the default server name -# (the swarm domain) the swarm UI's apex vhost answers (./swarm-ui.nix). -# - `/matrix/*` redirects to the homeserver where the homeserver runs. +# The locations sit on the hive domain because the matrix spec reads +# delegation off the *server name*: it is the hive answering "where is my +# homeserver", not the homeserver answering for itself (./hive-matrix.nix's +# vhost on `gatewayHost` carries the rest). # -# ⚠️ Both conditions repeat the one ./hive-c0re/vhosts.nix declares the hive +# ⚠️ The condition repeats the one ./hive-c0re/vhosts.nix declares the hive # domain vhost under. With it looser, this file alone would declare that # vhost, with discovery and no `/` redirect. { @@ -25,58 +24,53 @@ let matrixCfg = hyperhiveCfg.swarm.matrix; homeserverUrl = "https://${matrixCfg.gatewayHost}"; - - onHiveVhost = - matrixCfg.gatewayHost != null - && hyperhiveCfg.deploy.hive-controller.enable - && gatewayCfg.enable - && hyperhiveCfg.swarm.dashboardDomain != null; - - # Same default as `effectiveServerName` in ./hive-matrix.nix. - serverName = - if matrixCfg.serverName != null then matrixCfg.serverName else hyperhiveCfg.swarm.domain; in { - config = lib.mkMerge [ - (lib.mkIf (onHiveVhost && hyperhiveCfg.deploy.matrix.enable) { - # `/matrix/*` → 301 → `gatewayHost`'s vhost/$1 (`chat.` - # by default; legacy deep-link shim for the fluffychat sub-domain). - # See `docs/networking/gateway.md`. - services.hyperhive.gateway.vhosts.${hyperhiveCfg.domain}.locations."/matrix/" = { - extraConfig = '' - rewrite ^/matrix/(.*)$ ${homeserverUrl}/$1 permanent; - ''; - }; - }) + config = + lib.mkIf + ( + hyperhiveCfg.deploy.matrix.enable + && matrixCfg.gatewayHost != null + && hyperhiveCfg.deploy.hive-controller.enable + && gatewayCfg.enable + && hyperhiveCfg.swarm.dashboardDomain != null + ) + { + services.hyperhive.gateway.vhosts.${hyperhiveCfg.domain}.locations = { + # `/matrix/*` → 301 → `gatewayHost`'s vhost/$1 (`chat.` + # by default; legacy deep-link shim for the fluffychat sub-domain). + # See `docs/networking/gateway.md`. + "/matrix/" = { + extraConfig = '' + rewrite ^/matrix/(.*)$ ${homeserverUrl}/$1 permanent; + ''; + }; - (lib.mkIf (onHiveVhost && hyperhiveCfg.domain == serverName) { - services.hyperhive.gateway.vhosts.${hyperhiveCfg.domain}.locations = { - # `.well-known/matrix/{client,server}` discovery JSON, pointing - # clients and peers at `gatewayHost`: the homeserver has no other - # address. CORS `*` per matrix spec. See `docs/networking/gateway.md`. - "= /.well-known/matrix/client" = { - extraConfig = '' - default_type application/json; - ${gatewayCfg.lib.securityHeaders} - add_header Access-Control-Allow-Origin *; - return 200 '{"m.homeserver":{"base_url":"${homeserverUrl}"}}'; - ''; - }; - # `m.server` is NOT a URL: per the matrix server-server spec - # (Resolving Server Names) a delegated host with NO port resolves - # to the federation default 8448 (after the SRV check) — the - # https-implies-443 rule does NOT apply here. So the port must be - # explicit even when it's the HTTPS default, unlike the client - # base_url above. Without it, peers federate to :8448 - # (closed) while the endpoint actually lives on the gateway's 443 - # vhost. See docs/networking/gateway.md discovery flow. - "= /.well-known/matrix/server" = { - extraConfig = '' - default_type application/json; - return 200 '{"m.server":"${matrixCfg.gatewayHost}:443"}'; - ''; + # `.well-known/matrix/{client,server}` discovery JSON, pointing + # clients and peers at `gatewayHost`: the homeserver has no other + # address. CORS `*` per matrix spec. See `docs/networking/gateway.md`. + "= /.well-known/matrix/client" = { + extraConfig = '' + default_type application/json; + ${gatewayCfg.lib.securityHeaders} + add_header Access-Control-Allow-Origin *; + return 200 '{"m.homeserver":{"base_url":"${homeserverUrl}"}}'; + ''; + }; + # `m.server` is NOT a URL: per the matrix server-server spec + # (Resolving Server Names) a delegated host with NO port resolves + # to the federation default 8448 (after the SRV check) — the + # https-implies-443 rule does NOT apply here. So the port must be + # explicit even when it's the HTTPS default, unlike the client + # base_url above. Without it, peers federate to :8448 + # (closed) while the endpoint actually lives on the gateway's 443 + # vhost. See docs/networking/gateway.md discovery flow. + "= /.well-known/matrix/server" = { + extraConfig = '' + default_type application/json; + return 200 '{"m.server":"${matrixCfg.gatewayHost}:443"}'; + ''; + }; }; }; - }) - ]; } diff --git a/nix/host-modules/hive-c0re/vhosts.nix b/nix/host-modules/hive-c0re/vhosts.nix index f92199bc6..49e39bba0 100644 --- a/nix/host-modules/hive-c0re/vhosts.nix +++ b/nix/host-modules/hive-c0re/vhosts.nix @@ -2,8 +2,8 @@ # like every service's: the dashboard's vhost (`swarm.dashboardDomain`), which # carries the dashboard behind authelia, per-agent routing and the swagger UI; # and the vhost named for the hive domain, which redirects everything to the -# dashboard's name. The matrix redirect, and discovery for a server name pinned to -# the hive domain, are added by ../glue-matrix-hive-discovery.nix. +# dashboard's name. Matrix discovery on the hive domain is added by +# ../glue-matrix-hive-discovery.nix. { lib, config, diff --git a/nix/host-modules/hive-gateway/vhosts.nix b/nix/host-modules/hive-gateway/vhosts.nix index 6e33f6f64..5a9305c60 100644 --- a/nix/host-modules/hive-gateway/vhosts.nix +++ b/nix/host-modules/hive-gateway/vhosts.nix @@ -4,7 +4,7 @@ # # Scope: a service declares its own vhost and dns name in its own module, # the same way — the hive's dashboard and hive domain in -# ../hive-c0re/vhosts.nix, pinned-hive discovery in +# ../hive-c0re/vhosts.nix, matrix discovery in # ../glue-matrix-hive-discovery.nix. That keeps a service's gateway surface # next to the service, and keeps this file to what the gateway itself # serves. diff --git a/nix/host-modules/hive-matrix-service.nix b/nix/host-modules/hive-matrix-service.nix index a23408391..52301cb64 100644 --- a/nix/host-modules/hive-matrix-service.nix +++ b/nix/host-modules/hive-matrix-service.nix @@ -28,7 +28,7 @@ in identity to a single hive's domain would make relocating the container between hives look like a different homeserver. Combined with the `.well-known/matrix/{client,server}` routes - the controller's host serves at that domain, clients auto-discover the + the gateway serves at that domain, clients auto-discover the actual matrix endpoint without needing a subdomain. Override here only if you need a different server_name shape (e.g. `chat.example.org` for a bespoke hostname). diff --git a/nix/host-modules/hive-matrix.nix b/nix/host-modules/hive-matrix.nix index 3adc511b2..d998967f6 100644 --- a/nix/host-modules/hive-matrix.nix +++ b/nix/host-modules/hive-matrix.nix @@ -454,10 +454,11 @@ in # longest-prefix rule puts `/_matrix/` # ahead of `/` with no ordering needed. # - # ⚠️ The `.well-known/matrix/*` delegation is deliberately NOT here: - # the spec requires it at the *server name*. It is served by the swarm - # apex (./swarm-ui.nix) for the default server name, or by the hive - # domain's vhost (./glue-matrix-hive-discovery.nix) for a pinned one. + # ⚠️ The `.well-known/matrix/*` delegation is deliberately NOT here. + # It stays on the hive's own vhost because the spec requires it to + # be served at the *server name*, which is the hive domain — it is + # the hive answering "where is my homeserver", not the homeserver + # answering for itself. services.hyperhive.gateway.vhosts = lib.optionalAttrs (cfg.gatewayHost != null) { "${cfg.gatewayHost}" = { locations = { diff --git a/nix/host-modules/swarm-ui.nix b/nix/host-modules/swarm-ui.nix index c275c53cc..7d74cd37b 100644 --- a/nix/host-modules/swarm-ui.nix +++ b/nix/host-modules/swarm-ui.nix @@ -64,16 +64,6 @@ let # rather than a coercion error from here — same idiom as # `swarm-otel-service.nix`'s `domainBase`. apex = if swarmCfg.domain == null then "swarm.invalid" else swarmCfg.domain; - - # Matrix discovery is answered at the server name, so the apex serves it when - # that is the swarm domain (the default). A homeserver pinned to a hive - # domain is answered by that hive's vhost (./glue-matrix-hive-discovery.nix). - # Built from `gatewayHost` alone, so it does not matter which host runs the - # homeserver. The URLs carry no port: `gateway.httpsPort` only sets what the - # gateway listens on. - matrixCfg = swarmCfg.matrix; - serverName = if matrixCfg.serverName != null then matrixCfg.serverName else apex; - servesMatrixDiscovery = matrixCfg.gatewayHost != null && serverName == apex; in { # No `enable` of its own: the UI is on wherever @@ -104,8 +94,8 @@ in config = lib.mkIf deployCfg.swarm-controller.enable { assertions = [ { - # The hive domain has its own vhost (the redirect to the dashboard, and - # discovery for a pinned server name). A second vhost claiming the same + # The hive domain has its own vhost (matrix discovery, the redirect + # to the dashboard). A second vhost claiming the same # server_name is not an error to nginx — it picks one and logs a # conflict — so the failure would surface as "the swarm UI is # sometimes a redirect", which is far harder to read than an @@ -114,8 +104,8 @@ in message = '' services.hyperhive.swarm.domain (${apex}) must differ from services.hyperhive.domain (${hiveDomain}) — the hive domain is - already served by the gateway's own vhost for it (the redirect to - the dashboard, and discovery for a pinned server name), and two vhosts + already served by the gateway's own vhost for it (matrix + discovery, the redirect to the dashboard), and two vhosts claiming one server_name silently resolve to whichever nginx picks. @@ -206,25 +196,6 @@ in extraConfig = swarmAuthRequest; }; } - // lib.optionalAttrs servesMatrixDiscovery { - # Same JSON, headers and `:443` as the hive-domain copy in - # ./glue-matrix-hive-discovery.nix (see there for why `m.server` names - # the port). No `auth_request`: peers and clients fetch these unauthenticated. - "= /.well-known/matrix/client" = { - extraConfig = '' - default_type application/json; - ${gatewayCfg.lib.securityHeaders} - add_header Access-Control-Allow-Origin *; - return 200 '{"m.homeserver":{"base_url":"https://${matrixCfg.gatewayHost}"}}'; - ''; - }; - "= /.well-known/matrix/server" = { - extraConfig = '' - default_type application/json; - return 200 '{"m.server":"${matrixCfg.gatewayHost}:443"}'; - ''; - }; - } // { # swarm-controller's whole HTTP surface, including the live # `/api/openapi.json` spec — proxied untouched (no URI segment diff --git a/nix/module-eval/core-toggle.nix b/nix/module-eval/core-toggle.nix index ac342de95..ebcc733e9 100644 --- a/nix/module-eval/core-toggle.nix +++ b/nix/module-eval/core-toggle.nix @@ -662,15 +662,9 @@ let ]; } { - # The hive domain answers discovery only for a server name pinned to it, - # which `bare` does not do. Its vhost exists (the redirect is there), so - # the absence arms cannot pass on a misspelled name. - name = "an unpinned hive serves no matrix discovery on its domain"; + name = "a hive with matrix off serves no matrix discovery endpoint"; ok = - let - l = bare.services.nginx.virtualHosts."h1.t.local".locations; - in - l ? "/" && !(l ? "= /.well-known/matrix/client") && !(l ? "= /.well-known/matrix/server"); + !(builtins.hasAttr "= /.well-known/matrix/client" bare.services.nginx.virtualHosts."_".locations); } { # main got eval-borked twice by this exact class of bug (once on the diff --git a/nix/module-eval/matrix-core.nix b/nix/module-eval/matrix-core.nix index f0c312092..c45f0e907 100644 --- a/nix/module-eval/matrix-core.nix +++ b/nix/module-eval/matrix-core.nix @@ -19,7 +19,6 @@ let ; }) hive - hiveWithController runGroup ; @@ -37,16 +36,6 @@ let # A hive host that does not run the homeserver: its hive-c0re reaches the # homeserver across the network. matrixElsewhere = shared.bareWithController; - - # A homeserver whose server name was pinned to the hive domain, on the - # controller's host, with no homeserver of its own: the discovery answer - # sits on the hive domain and needs neither the homeserver nor the apex. - matrixPinned = hiveWithController { - swarm.matrix.serverName = "h1.t.local"; - deploy.swarm-controller.enable = true; - deploy.swarm-ui.package = pkgs.emptyDirectory; - }; - cases = [ { # Two limits governed a matrix upload and nothing kept them in agreement, @@ -140,55 +129,32 @@ let == "https://chat.t.local"; } { - # The legacy redirect reaches the hive domain's vhost from a glue - # module, merged into the vhost hive-c0re declares, and only where the - # homeserver runs. The matrix-elsewhere arm reads the same vhost, which - # still exists there with its redirect, so its absence of the redirect - # cannot pass on a misspelled name. Under the default server name (the - # swarm domain) the hive domain answers no discovery on either host. - # The fixture's gateway is on a non-default TLS port, which none of the - # URLs carry. - name = "an unpinned hive domain's vhost carries the matrix redirect where the homeserver runs, and no discovery"; + # The discovery locations reach the hive domain's vhost from a glue + # module, merged into the vhost hive-c0re declares. The matrix-elsewhere + # arm reads the same vhost, which still exists there with its redirect, + # so its absence of discovery cannot pass on a misspelled name. The + # fixture's gateway is on a non-default TLS port, which none of the URLs + # carry. + name = "matrix discovery sits on the hive domain's vhost only where the homeserver runs"; ok = let here = matrixNoBaoIdentity.services.nginx.virtualHosts."h1.t.local".locations; elsewhere = matrixElsewhere.services.nginx.virtualHosts."h1.t.local".locations; in matrixNoBaoIdentity.services.hyperhive.gateway.httpsPort == 8443 + && lib.hasInfix ''{"m.homeserver":{"base_url":"https://chat.t.local"}}'' ( + here."= /.well-known/matrix/client".extraConfig or "" + ) + && lib.hasInfix ''{"m.server":"chat.t.local:443"}'' ( + here."= /.well-known/matrix/server".extraConfig or "" + ) && lib.hasInfix "rewrite ^/matrix/(.*)$ https://chat.t.local/$1 permanent;" ( here."/matrix/".extraConfig or "" ) && lib.hasInfix "return 301 https://h1.hives.t.local$request_uri;" here."/".extraConfig - && !(here ? "= /.well-known/matrix/client") - && !(here ? "= /.well-known/matrix/server") && elsewhere ? "/" - && !(elsewhere ? "/matrix/") - && !(elsewhere ? "= /.well-known/matrix/client"); - } - { - # A homeserver pinned to the hive domain keeps its discovery on that - # vhost, even though the host runs no homeserver, and not on the apex, which is a - # different server name. The apex arm is read on a vhost that - # exists (its `/` and `/api/` are there), so it cannot pass on a - # misspelled name. - name = "a server name pinned to the hive domain is answered on the hive domain's vhost and not on the apex"; - ok = - let - onHive = matrixPinned.services.nginx.virtualHosts."h1.t.local".locations; - apex = matrixPinned.services.nginx.virtualHosts."t.local".locations; - in - !matrixPinned.services.hyperhive.deploy.matrix.enable - && lib.hasInfix ''{"m.homeserver":{"base_url":"https://chat.t.local"}}'' ( - onHive."= /.well-known/matrix/client".extraConfig or "" - ) - && lib.hasInfix ''{"m.server":"chat.t.local:443"}'' ( - onHive."= /.well-known/matrix/server".extraConfig or "" - ) - && onHive ? "/" - && apex ? "/" - && apex ? "/api/" - && !(apex ? "= /.well-known/matrix/client") - && !(apex ? "= /.well-known/matrix/server"); + && !(elsewhere ? "= /.well-known/matrix/client") + && !(elsewhere ? "/matrix/"); } ]; in diff --git a/nix/module-eval/swarm-services-switch.nix b/nix/module-eval/swarm-services-switch.nix index 27128cff2..7c65716e1 100644 --- a/nix/module-eval/swarm-services-switch.nix +++ b/nix/module-eval/swarm-services-switch.nix @@ -366,27 +366,6 @@ let name = "a named exposeHostPorts opens its bridge port on the host's own say-so"; ok = builtins.elem 5432 (bridgePortsOrNone exposedPortsNoHive); } - { - # The default server name is the swarm domain, so the apex answers - # discovery from `gatewayHost` alone: this fixture runs no homeserver and - # no hive. The URLs carry no port, and `m.server` names 443 because the - # spec reads a bare host as 8448. The `/` arm is the presence control on - # the vhost; the pinned counterpart is in ./matrix-core.nix. - name = "the swarm apex serves both matrix discovery routes under the default server name"; - ok = - let - l = swarmUiHere.services.nginx.virtualHosts."t.local".locations; - in - l ? "/" - && lib.hasInfix ''{"m.homeserver":{"base_url":"https://chat.t.local"}}'' ( - l."= /.well-known/matrix/client".extraConfig or "" - ) - && lib.hasInfix ''{"m.server":"chat.t.local:443"}'' ( - l."= /.well-known/matrix/server".extraConfig or "" - ) - && !(lib.hasInfix "auth_request" l."= /.well-known/matrix/client".extraConfig) - && !(lib.hasInfix "auth_request" l."= /.well-known/matrix/server".extraConfig); - } { name = "the old swarm UI package spelling sets the controller's UI package, which the vhost serves"; ok = @@ -568,7 +547,7 @@ let vh = swarmServicesHere.services.nginx.virtualHosts; l = vh."h1.hives.t.local".locations; in - l ? "/api/" && l ? "/health/" && vh."h1.t.local".locations ? "/" + l ? "/api/" && l ? "/health/" && vh."h1.t.local".locations ? "= /.well-known/matrix/client" ) && !(noHiveLeafAnywhere swarmServicesHere); }