-
Notifications
You must be signed in to change notification settings - Fork 361
Dedicated MAS API #18520
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
Merged
Merged
Dedicated MAS API #18520
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d32c32b
Dedicated API for MAS -> Synapse communication
sandhose 23e7b88
Tests for the dedicated MAS users APIs
sandhose 9ba9989
Tests for the dedicated MAS devices APIs
sandhose 25fade5
Newsfile
sandhose cfb1ff4
Add doc comments for all new endpoints
sandhose 86e8435
Fix starting up & tests if authlib is not installed
sandhose ae7c6ff
Change test order for consistency
sandhose f1647b7
Fix test comment accuracy
sandhose eb5e7a6
Rename endpoint create_device -> upsert_device
sandhose f91a698
Put 'email' in a constant
sandhose 47c0161
Rename variable for clarity
sandhose 31b32b3
Expand on why we log early
sandhose c1f666e
Use RequestBodyModel instead of BaseModel
sandhose 48d7d7b
Rename assert_mas_request -> assert_request_is_from_mas
sandhose 2eb98c0
Fix typo in tests
sandhose cc6da94
Skip MAS API tests if authlib is not available
sandhose 02bf776
Remove broken test case
sandhose 1fa7898
Import the MemoryReactor from the right place to keep compatibility w…
sandhose 7e8c19e
Use a TypedDict instead of a BaseModel for MasQueryUserResource.Response
sandhose f8b4656
Use keyword args with the `TypedDict`
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 hidden or 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 @@ | ||
Dedicated internal API for Matrix Authentication Service to Synapse communication. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,71 @@ | ||
# | ||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||
# | ||
# Copyright (C) 2025 New Vector, Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# See the GNU Affero General Public License for more details: | ||
# <https://www.gnu.org/licenses/agpl_3.0.html>. | ||
# | ||
# | ||
|
||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
from twisted.web.resource import Resource | ||
|
||
from synapse.rest.synapse.mas.devices import ( | ||
MasCreateDeviceResource, | ||
MasDeleteDeviceResource, | ||
MasSyncDevicesResource, | ||
MasUpdateDeviceDisplayNameResource, | ||
) | ||
from synapse.rest.synapse.mas.users import ( | ||
MasAllowCrossSigningResetResource, | ||
MasDeleteUserResource, | ||
MasIsLocalpartAvailableResource, | ||
MasProvisionUserResource, | ||
MasQueryUserResource, | ||
MasReactivateUserResource, | ||
MasSetDisplayNameResource, | ||
MasUnsetDisplayNameResource, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from synapse.server import HomeServer | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MasResource(Resource): | ||
""" | ||
Provides endpoints for MAS to manage user accounts and devices. | ||
|
||
All endpoints are mounted under the path `/_synapse/mas/` and only work | ||
using the MAS admin token. | ||
""" | ||
|
||
def __init__(self, hs: "HomeServer"): | ||
Resource.__init__(self) | ||
self.putChild(b"query_user", MasQueryUserResource(hs)) | ||
self.putChild(b"provision_user", MasProvisionUserResource(hs)) | ||
self.putChild(b"is_localpart_available", MasIsLocalpartAvailableResource(hs)) | ||
self.putChild(b"delete_user", MasDeleteUserResource(hs)) | ||
self.putChild(b"create_device", MasCreateDeviceResource(hs)) | ||
self.putChild(b"delete_device", MasDeleteDeviceResource(hs)) | ||
self.putChild( | ||
b"update_device_display_name", MasUpdateDeviceDisplayNameResource(hs) | ||
) | ||
self.putChild(b"sync_devices", MasSyncDevicesResource(hs)) | ||
self.putChild(b"reactivate_user", MasReactivateUserResource(hs)) | ||
self.putChild(b"set_displayname", MasSetDisplayNameResource(hs)) | ||
self.putChild(b"unset_displayname", MasUnsetDisplayNameResource(hs)) | ||
self.putChild( | ||
b"allow_cross_signing_reset", MasAllowCrossSigningResetResource(hs) | ||
) |
This file contains hidden or 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,43 @@ | ||||||||||||||||
# | ||||||||||||||||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||||||||||||||||
# | ||||||||||||||||
# Copyright (C) 2025 New Vector, Ltd | ||||||||||||||||
# | ||||||||||||||||
# This program is free software: you can redistribute it and/or modify | ||||||||||||||||
# it under the terms of the GNU Affero General Public License as | ||||||||||||||||
# published by the Free Software Foundation, either version 3 of the | ||||||||||||||||
# License, or (at your option) any later version. | ||||||||||||||||
# | ||||||||||||||||
# See the GNU Affero General Public License for more details: | ||||||||||||||||
# <https://www.gnu.org/licenses/agpl_3.0.html>. | ||||||||||||||||
# | ||||||||||||||||
# | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
from typing import TYPE_CHECKING, cast | ||||||||||||||||
|
||||||||||||||||
from synapse.api.errors import SynapseError | ||||||||||||||||
from synapse.http.server import DirectServeJsonResource | ||||||||||||||||
|
||||||||||||||||
if TYPE_CHECKING: | ||||||||||||||||
from synapse.app.generic_worker import GenericWorkerStore | ||||||||||||||||
from synapse.http.site import SynapseRequest | ||||||||||||||||
from synapse.server import HomeServer | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
class MasBaseResource(DirectServeJsonResource): | ||||||||||||||||
def __init__(self, hs: "HomeServer"): | ||||||||||||||||
# Importing this module requires authlib, which is an optional | ||||||||||||||||
# dependency but required if msc3861 is enabled | ||||||||||||||||
from synapse.api.auth.msc3861_delegated import MSC3861DelegatedAuth | ||||||||||||||||
Comment on lines
+30
to
+32
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. Looks good. This is backed up by synapse/synapse/config/experimental.py Lines 116 to 122 in 875269e
|
||||||||||||||||
|
||||||||||||||||
DirectServeJsonResource.__init__(self, extract_context=True) | ||||||||||||||||
auth = hs.get_auth() | ||||||||||||||||
assert isinstance(auth, MSC3861DelegatedAuth) | ||||||||||||||||
self.msc3861_auth = auth | ||||||||||||||||
self.store = cast("GenericWorkerStore", hs.get_datastores().main) | ||||||||||||||||
self.hostname = hs.hostname | ||||||||||||||||
|
||||||||||||||||
def assert_mas_request(self, request: "SynapseRequest") -> None: | ||||||||||||||||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
if not self.msc3861_auth.is_request_using_the_admin_token(request): | ||||||||||||||||
raise SynapseError(403, "This endpoint must only be called by MAS") |
Oops, something went wrong.
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.
Has this plan changed? It looks like the new approach uses a shared secret
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.
This will likely get refactored as part of stabilising MAS support, getting it out of experimental features. The plan is to keep using a shared secret both ways as it simplifies configuration and avoids weird roundtrips