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
|
|
@ -333,6 +333,36 @@ with subtest(
|
|||
assert status != 0 and f"not logged in to {SWARM_URL}" in out, (status, out)
|
||||
machine.succeed(f"{VIA_SOCKET} swarmctl schedule list")
|
||||
|
||||
with subtest("swarmctl login discovers the swarm's SSO provider from the gateway"):
|
||||
# The swarm's own CA signs the gateway's leaf. A VM has no browser, so the login runs to the
|
||||
# point where it prints the authorization URL and waits for the answer, which the timeout ends.
|
||||
# Reaching that URL takes the gateway's 401 challenge, its published metadata, and authelia
|
||||
# accepting the pushed authorization request.
|
||||
ca = "/var/lib/hive-tls/swarm-services-root.pem"
|
||||
auth = f"https://auth.{SWARM_URL.removeprefix('https://')}"
|
||||
challenge = machine.succeed(
|
||||
f"curl --silent --cacert {ca} -D - -o /dev/null {SWARM_URL}/api/"
|
||||
)
|
||||
assert challenge.startswith("HTTP/") and " 401" in challenge.splitlines()[0], (
|
||||
challenge
|
||||
)
|
||||
assert (
|
||||
f'resource_metadata="{SWARM_URL}/.well-known/oauth-protected-resource/api/"'
|
||||
in challenge
|
||||
), challenge
|
||||
metadata = machine.succeed(
|
||||
f"curl --fail --silent --cacert {ca} {SWARM_URL}/.well-known/oauth-protected-resource/api/"
|
||||
)
|
||||
assert json.loads(metadata) == {
|
||||
"resource": f"{SWARM_URL}/api/",
|
||||
"authorization_servers": [auth],
|
||||
}, metadata
|
||||
status, out = machine.execute(
|
||||
f"timeout 30 swarmctl --swarm {SWARM_URL} --ca-file {ca} login --callback-port 8765 2>&1"
|
||||
)
|
||||
assert status == 124, (status, out)
|
||||
assert f"{auth}/api/oidc/authorization?client_id=swarmctl&request_uri=" in out, out
|
||||
|
||||
with subtest("the agents are deployed and need a login"):
|
||||
settle(
|
||||
f"curl --fail --silent --unix-socket {SOCKET} {API}/api/agents/status "
|
||||
|
|
|
|||
Loading…
Reference in a new issue