Watch
0
0
Fork
You've already forked hyperhive
0

swarmctl login: find the sso provider from the gateway's published metadata

This commit is contained in:
atlas 2026-11-23 20:55:42 +01:00 • committed by mara
commit cd040afa0e

View file

@ -729,16 +729,37 @@ let
api = l."/api/".extraConfig;
refused = l."@swarm_api_unauthorized".extraConfig;
sec = allLocal.services.hyperhive.gateway.lib.securityHeaders;
challenge = ''Bearer realm="swarm", resource_metadata="https://t.local/.well-known/oauth-protected-resource/api/"'';
in
lib.hasInfix "error_page 401 = @swarm_api_unauthorized;" api
&& !(lib.hasInfix "=302" api)
&& lib.hasInfix ''proxy_set_header Authorization "";'' api
&& lib.hasInfix "if ($http_authorization) {\n ${sec}\n add_header WWW-Authenticate 'Bearer realm=\"swarm\"' always;\n return 401;\n}" refused
&& lib.hasInfix "if ($http_authorization) {\n ${sec}\n add_header WWW-Authenticate '${challenge}' always;\n return 401;\n}" refused
&& lib.hasInfix "if ($http_accept ~* \"text/html\") {\n return 302 https://auth.t.local/?rd=$target_url;\n}" refused
&& lib.hasPrefix sec refused
&& lib.hasInfix "}\nadd_header WWW-Authenticate 'Bearer realm=\"swarm\"' always;\nreturn 401;" refused
&& lib.hasInfix "}\nadd_header WWW-Authenticate '${challenge}' always;\nreturn 401;" refused
&& lib.hasInfix "error_page 401 =302 https://auth.t.local/" l."/".extraConfig;
}
{
# `swarmctl login` finds the SSO provider from the `/api/` challenge's
# `resource_metadata` document. The document is served with no
# `auth_request`, as JSON naming the API as `resource` and authelia as
# its authorization server. The `/` clause is the control: the page
# route carries an `auth_request`, so a pass means the two differ.
# Turned red by dropping `authorization_servers` from `protectedResource`
# in `swarm-ui.nix`.
name = "the swarm vhost publishes its API's authorization server without a login";
ok =
let
l = allLocal.services.nginx.virtualHosts."t.local".locations;
doc = l."= /.well-known/oauth-protected-resource/api/".extraConfig;
in
lib.hasInfix "default_type application/json;" doc
&& lib.hasInfix ''"resource":"https://t.local/api/"'' doc
&& lib.hasInfix ''"authorization_servers":["https://auth.t.local"]'' doc
&& !(lib.hasInfix "auth_request" doc)
&& lib.hasInfix "auth_request" l."/".extraConfig;
}
{
# authelia 4.39.20 refuses a bearer-scoped public client missing any of
# these at startup, after a green deploy; and a public client must not