-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSC3861: load the issuer and account management URLs from OIDC discovery #17407
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65120fe
MSC3861: load the issuer and account management URLs from OIDC discovery
sandhose 86d7fee
Newsfile.
sandhose ee0cd1a
Import `cast` from `typing` instead of `typing_extensions`.
sandhose 2ff5321
Fix loading the account management URL from the issuer
sandhose 90b6a4f
Merge remote-tracking branch 'origin/develop' into quenting/msc3861-l…
sandhose 0119d40
Use the cached metadata call
sandhose b035669
Merge remote-tracking branch 'origin/develop' into quenting/msc3861-l…
sandhose 5d9d269
Don't fallback to the config issuer if loading the metadata fails
sandhose f4dc986
Merge remote-tracking branch 'origin/develop' into quenting/msc3861-l…
sandhose 089a542
Use the right account management URL in the UIA fallback
sandhose 17a90f7
Fix tests now that we're always fetching the issuer metadata
sandhose 40c854c
Fix well-known tests now that we're fetching through the metadata
sandhose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MSC3861: load the issuer and account management URLs from OIDC discovery. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,13 @@ | |
# | ||
# | ||
import logging | ||
from typing import TYPE_CHECKING, Optional | ||
from typing import TYPE_CHECKING, Optional, Tuple, cast | ||
|
||
from twisted.web.resource import Resource | ||
from twisted.web.server import Request | ||
|
||
from synapse.http.server import set_cors_headers | ||
from synapse.api.errors import NotFoundError | ||
from synapse.http.server import DirectServeJsonResource | ||
from synapse.http.site import SynapseRequest | ||
from synapse.types import JsonDict | ||
from synapse.util import json_encoder | ||
|
@@ -38,8 +39,9 @@ | |
class WellKnownBuilder: | ||
def __init__(self, hs: "HomeServer"): | ||
self._config = hs.config | ||
self._auth = hs.get_auth() | ||
|
||
def get_well_known(self) -> Optional[JsonDict]: | ||
async def get_well_known(self) -> Optional[JsonDict]: | ||
if not self._config.server.serve_client_wellknown: | ||
return None | ||
|
||
|
@@ -52,13 +54,20 @@ def get_well_known(self) -> Optional[JsonDict]: | |
|
||
# We use the MSC3861 values as they are used by multiple MSCs | ||
if self._config.experimental.msc3861.enabled: | ||
# If MSC3861 is enabled, we can assume self._auth is an instance of MSC3861DelegatedAuth | ||
# We import lazily here because of the authlib requirement | ||
from synapse.api.auth.msc3861_delegated import MSC3861DelegatedAuth | ||
|
||
auth = cast(MSC3861DelegatedAuth, self._auth) | ||
|
||
result["org.matrix.msc2965.authentication"] = { | ||
"issuer": self._config.experimental.msc3861.issuer | ||
"issuer": await auth.issuer(), | ||
} | ||
if self._config.experimental.msc3861.account_management_url is not None: | ||
account_management_url = await auth.account_management_url() | ||
sandhose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if account_management_url is not None: | ||
result["org.matrix.msc2965.authentication"][ | ||
"account" | ||
] = self._config.experimental.msc3861.account_management_url | ||
] = account_management_url | ||
|
||
if self._config.server.extra_well_known_client_content: | ||
for ( | ||
|
@@ -71,26 +80,22 @@ def get_well_known(self) -> Optional[JsonDict]: | |
return result | ||
|
||
|
||
class ClientWellKnownResource(Resource): | ||
class ClientWellKnownResource(DirectServeJsonResource): | ||
"""A Twisted web resource which renders the .well-known/matrix/client file""" | ||
|
||
isLeaf = 1 | ||
|
||
def __init__(self, hs: "HomeServer"): | ||
Resource.__init__(self) | ||
super().__init__() | ||
self._well_known_builder = WellKnownBuilder(hs) | ||
|
||
def render_GET(self, request: SynapseRequest) -> bytes: | ||
set_cors_headers(request) | ||
r = self._well_known_builder.get_well_known() | ||
async def _async_render_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: | ||
r = await self._well_known_builder.get_well_known() | ||
if not r: | ||
request.setResponseCode(404) | ||
request.setHeader(b"Content-Type", b"text/plain") | ||
return b".well-known not available" | ||
raise NotFoundError(".well-known not available") | ||
|
||
logger.debug("returning: %s", r) | ||
request.setHeader(b"Content-Type", b"application/json") | ||
return json_encoder.encode(r).encode("utf-8") | ||
Comment on lines
-74
to
-93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes here don't change the response when the WK can be built: Before:
After:
It does although change the response when the public_baseurl isn't set: Before:
After:
Which is IMO perfectly acceptable |
||
return 200, r | ||
|
||
|
||
class ServerWellKnownResource(Resource): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the right precedence? Generally I would expect config to override autodetection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the problem is that the issuer in the config is used for discovery, and might be slightly different than the one you should actually advertise. Client will fail if the issuer advertised by
/auth_issuer
is not exactly the same as the one in{issuer}/.well-known/openid-configuration
. We've had problems in the past of mismatches because of trailing slashes being in one place but not at the other oneSo IMO, it can be confusing, but I think that pragmatically this is the right precedence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, even still, it still feels wrong to me. Suppose the homeserver fails to fetch the discovery at some point, you're still going to hand out the wrong issuer value to clients then, it will just be extra confusing that this was caused by the discovery failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a really good point. Should we log a warning if there is a mismatch, but still work? Because the discovery has to work just once in Synapse's lifetime, then everything is cached, so hopefully that sort of outage would be very temporary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check it on start up and then refuse to start up if it's wrong instead? I think this would be justified for what is a configuration error. The problem with warnings is that virtually nobody reads them.
I think by 'once in Synapse's lifetime' you mean once every process lifetime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. I preferred to not catch the error if it fails loading. The impact of this, is that
/.well-known/matrix/client
and/_matrix/client/*/auth_issuer
will 501 in case Synapse was never able to contact MAS, instead of potentially showing wrong informations. I think this is better