Skip to content

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 20 commits into from
Jul 21, 2025
Merged

Dedicated MAS API #18520

merged 20 commits into from
Jul 21, 2025

Conversation

sandhose
Copy link
Member

@sandhose sandhose commented Jun 6, 2025

This introduces a dedicated API for MAS to consume. Companion PR on the MAS side: element-hq/matrix-authentication-service#4801

This has a few advantages over the previous admin API:

  • it works on workers (this will be documented once we stabilise MSC3861 as a whole)
  • it is more efficient because more focused
  • it propagates trace contexts from MAS
  • it is only accessible to MAS (through the shared secret) and will let us remove the weird hack that made this token 'admin' with a ghost '@__oidc_admin:' user

The next MAS version should support it, but will be opt-in. The version after that should use this new API by default

@sandhose sandhose force-pushed the quenting/dedicated-mas-api branch from 38c521d to bd442af Compare July 16, 2025 15:39
@github-actions github-actions bot deployed to PR Documentation Preview July 16, 2025 15:40 Active
@github-actions github-actions bot deployed to PR Documentation Preview July 17, 2025 17:25 Active
@sandhose sandhose force-pushed the quenting/dedicated-mas-api branch from 8c26530 to 46a4f9d Compare July 18, 2025 14:18
@sandhose sandhose force-pushed the quenting/dedicated-mas-api branch from 46a4f9d to 25fade5 Compare July 18, 2025 19:24
@sandhose sandhose changed the title WIP: dedicated MAS API Dedicated MAS API Jul 18, 2025
@sandhose sandhose marked this pull request as ready for review July 18, 2025 19:28
@sandhose sandhose requested a review from a team as a code owner July 18, 2025 19:28
Copy link
Contributor

@MadLittleMods MadLittleMods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't verified the MAS side and whether these are useful.

Appears sane though. Just a bunch of user utilities available as MAS-only endpoints that can be served by workers (I assume).

Comment on lines 498 to 500
# XXX: This is a temporary solution so that the admin API can be called by
# the OIDC provider. This will be removed once we have OIDC client
# credentials grant support in matrix-authentication-service.
Copy link
Contributor

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

Copy link
Member Author

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


self.device_handler = hs.get_device_handler()

class PostBody(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class PostBody(BaseModel):
class PostBody(RequestBodyModel):

(applies elsewhere)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have done that in c1f666e (except for the query user response as it's a response, not a request 🤷)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(except for the query user response as it's a response, not a request 🤷)

We can still use ParseModel for anything else.

For the query user response case, I'm not sure Pydantic is thing to use since we're not parsing anything. And since we convert it to a dict anyway, perhaps it should be a TypedDict 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, have done that in 7e8c19e

user_id=user_id.to_string()
)
current_email_list = {
t.address for t in current_threepid_list if t.medium == "email"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"email" could be a constant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no global constant to grab, so I made it a local one in f91a698

Copy link
Contributor

@MadLittleMods MadLittleMods Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better than before but ideally, we'd probably share this everywhere. We could add it to synapse/api/constants.py

Doesn't have to be a thing to change in this PR

@sandhose sandhose force-pushed the quenting/dedicated-mas-api branch from 6567a84 to 31b32b3 Compare July 21, 2025 08:05
@sandhose sandhose requested a review from MadLittleMods July 21, 2025 15:01
@sandhose
Copy link
Member Author

@MadLittleMods thanks for the review! I think I fixed everything you've raised, plus fixed the test suite not running on olddeps

Comment on lines +30 to +32
# Importing this module requires authlib, which is an optional
# dependency but required if msc3861 is enabled
from synapse.api.auth.msc3861_delegated import MSC3861DelegatedAuth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. This is backed up by

# Only allow enabling MSC3861 if authlib is installed
if value and not HAS_AUTHLIB:
raise ConfigError(
"MSC3861 is enabled but authlib is not installed. "
"Please install authlib to use MSC3861.",
("experimental", "msc3861", "enabled"),
)

@sandhose sandhose enabled auto-merge (squash) July 21, 2025 15:33
Co-authored-by: Eric Eastwood <erice@element.io>
@sandhose sandhose merged commit 8a4e2e8 into develop Jul 21, 2025
44 checks passed
@sandhose sandhose deleted the quenting/dedicated-mas-api branch July 21, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants