refactor(3202): authelia declares its own vhost and dns name
Moves the authelia vhost out of the gateway's vhosts.nix and its `address=` rule out of dnsmasq.nix, into swarm-authelia.nix. Both land inside that module's existing `cfg.enable` guard, which is the load-bearing part: every hive in a swarm knows `authelia.url`, but only the host that RUNS the container may claim the name. A client hive declaring the vhost would answer for a service it does not run, and publishing the DNS record would point every agent on its bridge at that wrong answer. The kit grows a fourth member, `errorPages`, because the vhost aims its 502/503/504 at the gateway's styled sso-unavailable page. Republished rather than imported per module: a service rendering its own would drift from the rest of the gateway the first time the theme changed.
This commit is contained in:
parent
d60a0585d6
commit
56ab6d26c1
6 changed files with 91 additions and 56 deletions
|
|
@ -36,53 +36,6 @@ let
|
|||
publicPort = cfg.httpsPort;
|
||||
publicPortSuffix = if publicPort == 443 then "" else ":${toString publicPort}";
|
||||
|
||||
# Authelia sub-domain vhost. `server_name = authelia.domain`, all of
|
||||
# `/` → authelia. Empty attrset unless THIS host runs the container:
|
||||
# every hive knows the swarm's `authelia.url`, but only the one
|
||||
# serving it may claim the name — a client hive declaring this vhost
|
||||
# would answer for a service it does not run.
|
||||
#
|
||||
# ⚠️ The server name must be exactly `autheliaCfg.domain`, not a
|
||||
# near-miss: authelia validates `authelia_url ⊂ session cookie domain`
|
||||
# at STARTUP, so a mismatch is a container that refuses to boot rather
|
||||
# than a login that misbehaves.
|
||||
#
|
||||
# ⚠️ And deliberately NO `dashboardAuth` here. That block is the
|
||||
# gateway's `auth_basic`; applying it to the SSO provider would put
|
||||
# the login page behind the login mechanism it exists to replace.
|
||||
autheliaVhost = lib.optionalAttrs autheliaCfg.enable {
|
||||
"${autheliaCfg.domain}" = (vhostTlsFor autheliaCfg.domain) // {
|
||||
listen = vhostListen;
|
||||
extraConfig = securityHeaders;
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:${toString autheliaCfg.port}/";
|
||||
proxyWebsockets = true;
|
||||
extraConfig = ''
|
||||
proxy_buffering off;
|
||||
# authelia decides by the ORIGINAL request, not by the hop it
|
||||
# sees — the login redirect and the session cookie's domain
|
||||
# both derive from these. Without them every request looks
|
||||
# like it arrived at 127.0.0.1 over plain http.
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Uri $request_uri;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
# A dead upstream here means "not bootstrapped" far more often
|
||||
# than "misconfigured proxy", and a bare 502 says the opposite.
|
||||
proxy_intercept_errors on;
|
||||
error_page 502 503 504 = /__hive_sso_unavailable;
|
||||
'';
|
||||
};
|
||||
locations."= /__hive_sso_unavailable" = {
|
||||
extraConfig = ''
|
||||
internal;
|
||||
alias ${errorPages.ssoUnavailable};
|
||||
default_type text/html;
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Swarm UI vhost — the swarm's front page, on the swarm apex, and the
|
||||
# FIRST `auth_request` anywhere in this gateway (everything else is
|
||||
# `auth_basic` + htpasswd).
|
||||
|
|
@ -481,7 +434,7 @@ in
|
|||
'';
|
||||
};
|
||||
}
|
||||
// autheliaVhost
|
||||
|
||||
// matrixVhost
|
||||
// swarmUiVhost;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue