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
|
|
@ -32,6 +32,17 @@ let
|
|||
auth_request_set $target_url $scheme://$http_host$request_uri;
|
||||
'';
|
||||
loginRedirect = "https://${autheliaCfg.domain}/?rd=$target_url";
|
||||
|
||||
# What `swarmctl login` reads to find the swarm's SSO provider (RFC 9728): the
|
||||
# `/api/` 401 names this document in its challenge, and the document names the
|
||||
# authorization server. `resource` is the audience a `swarmctl` token carries
|
||||
# (`swarmctl/src/remote.rs`, `swarm-authelia.nix`).
|
||||
protectedResourcePath = "/.well-known/oauth-protected-resource/api/";
|
||||
protectedResource = builtins.toJSON {
|
||||
resource = "https://${apex}/api/";
|
||||
authorization_servers = [ "https://${autheliaCfg.domain}" ];
|
||||
};
|
||||
challenge = ''Bearer realm="swarm", resource_metadata="https://${apex}${protectedResourcePath}"'';
|
||||
swarmAuthRequest = ''
|
||||
${authRequest}
|
||||
error_page 401 =302 ${loginRedirect};
|
||||
|
|
@ -334,15 +345,23 @@ in
|
|||
${gatewayCfg.lib.securityHeaders}
|
||||
if ($http_authorization) {
|
||||
${gatewayCfg.lib.securityHeaders}
|
||||
add_header WWW-Authenticate 'Bearer realm="swarm"' always;
|
||||
add_header WWW-Authenticate '${challenge}' always;
|
||||
return 401;
|
||||
}
|
||||
if ($http_accept ~* "text/html") {
|
||||
return 302 ${loginRedirect};
|
||||
}
|
||||
add_header WWW-Authenticate 'Bearer realm="swarm"' always;
|
||||
add_header WWW-Authenticate '${challenge}' always;
|
||||
return 401;
|
||||
'';
|
||||
# The document the challenge names. Public by design: a client reads it
|
||||
# before it has a login, and it holds only the names of the swarm's own
|
||||
# API and its SSO provider.
|
||||
"= ${protectedResourcePath}".extraConfig = ''
|
||||
${gatewayCfg.lib.securityHeaders}
|
||||
default_type application/json;
|
||||
return 200 '${protectedResource}';
|
||||
'';
|
||||
# ⚠️ THE ONE PROXIED LOCATION ON THIS VHOST WITH NO `auth_request`,
|
||||
# and that is deliberate rather than an omission.
|
||||
#
|
||||
|
|
|
|||
Loading…
Reference in a new issue