swarmctl login: find the sso provider from the gateway's published metadata
This commit is contained in:
parent
c1851f37cc
commit
cd040afa0e
1 changed files with 421 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue