Deploying Matrix Authentication Service with Synapse for a new homeserver
Matrix Authentication Service (MAS) is the component to plan for when a new Synapse homeserver should hand sign-in to an existing identity provider. It is an OAuth 2.0 and OpenID provider for Matrix that implements the OIDC-based authentication described in MSC3861. It runs beside Synapse as a separate service with its own domain and its own PostgreSQL database, and it does not support SAML natively. Your team decides early whether MAS is the right front door, because the choice shapes the domain layout, the database build and the identity work that follows.
MAS is a good fit when your organization already runs an OpenID Connect provider such as Keycloak, Microsoft Entra ID, Google or Authentik, and wants Matrix accounts governed there. MAS uses those upstream providers rather than replacing them, so you keep one place for joiners, leavers and multi-factor policy. It is a weaker fit when your directory only speaks SAML or LDAP. The MAS documentation recommends a bridge such as Dex in that case, which adds a component to build, patch and monitor. If your identity provider speaks SAML and you do not want a bridge, the Synapse-native SSO options listed in the configuration manual, including SAML2 through saml2_config, may be the simpler path. Confirm the protocol your identity provider supports before you commit to either route.
Before you start the build, confirm three things with the identity and platform owners: which upstream providers MAS will trust, who can register new Matrix clients and administer users, and whether the MAS and Synapse versions you plan to deploy support the MSC3861 flow you expect. Check the current MAS setup documentation for those version and configuration details rather than relying on older guides. Plan the separate PostgreSQL database and the email settings for MAS now, because a sign-in path that works in a test environment can still fail on those when real users arrive.
How a Matrix login flows through MAS, the upstream provider and Synapse
The login starts in the client, which reaches Matrix Authentication Service through the reverse proxy routes for the compatibility layer. MAS hands the user to the upstream OpenID Connect provider, such as Keycloak or Microsoft Entra ID, and receives the identity back. MAS then issues the tokens that Synapse accepts, so Synapse never sees the upstream password. Check that each database is separate, that /_synapse/admin stays off the public internet, and that the trust boundary between the reverse proxy and the internal services is enforced.
Login path through the proxy, MAS, the upstream provider and Synapse, with trust boundaries marked.
Which MAS layout fits your environment
A new homeserver with a single identity provider is the simplest layout to reason about. You choose one OpenID Connect provider that already holds your staff accounts, or that you stand up for Matrix alone, and point MAS at it. The homeserver, MAS and Element Web each get a hostname under a domain you control, so the permanent server name stays short while services can move later. Expect one MAS database and one upstream client registration to manage.
- Domain layout: fix the server name first, then give MAS its own subdomain and document the redirect paths it will use.
- Upstream provider: pick one OIDC provider, such as Keycloak, Microsoft Entra ID, Google or Authentik, based on the user directory it already has.
- Extra components: a dedicated PostgreSQL database for MAS, separate from the Synapse database, plus SMTP settings if MAS sends mail.
- Synapse link: Synapse must delegate login to MAS, which needs a shared secret and a MAS endpoint that Synapse can reach over the internal network.
- Registration: decide whether open self-registration stays off, so accounts come only from the upstream provider.
Check which system owns the user lifecycle, because disabling a person there is what should remove their Matrix access.
Where Keycloak already runs the identity estate, MAS usually becomes one more client in an existing realm. The work centers on client registration, claim mapping and agreeing with the Keycloak administrators who can change realm settings. A poorly planned realm change can stop sign-in for every Matrix user at once, so the Keycloak owners need a seat in the design from the start.
- Domain layout: confirm whether MAS shares a public domain with Keycloak or sits on its own subdomain, because the redirect URIs in the realm must match MAS exactly.
- Client registration: create a confidential OIDC client in the realm for MAS and register the callback path that MAS uses.
- Claims and mapping: check that tokens carry the claims MAS needs for the Matrix localpart and display name, and test them with a pilot group.
- Extra components: the MAS database and a reverse proxy route, while Keycloak itself is normally already in place and run by another team.
- Ownership: write down who may change realm settings, clients and mappers, and who is told before a Keycloak upgrade.
Check the exact claim names and redirect URIs in a staging realm before you change anything in production.
Microsoft Entra ID is a common identity provider for organizations that already run Microsoft 365. MAS supports it as an upstream OpenID Connect provider, so the pattern resembles the Keycloak layout. The difference is where the controls live: the app registration, tenant policies and conditional access sit in Microsoft's administration tools and belong to your Microsoft administrators, not to the Matrix team.
- App registration: create a registration in your tenant with redirect URIs for MAS, and track the expiry date of its client secret or certificate.
- Tenant scope: decide whether every user in the tenant may sign in to Matrix or only members of an assigned group.
- Conditional access: multi-factor and device rules apply at sign-in, so test a full Matrix login under the same policies your users will face.
- External users: confirm how guests and external collaborators will authenticate, since they may need a separate path or an explicit exception.
- Extra components: the MAS database, a reverse proxy route and the email settings for any notifications MAS sends.
Confirm the owners of the tenant, the app registration and the secret rotation schedule before users are invited.
MAS does not speak SAML or LDAP directly. Its documentation recommends a bridge such as Dex, which accepts those protocols on one side and presents OpenID Connect on the other. Read the upstream identity provider setup before choosing the bridge. This layout adds a service to run, credentials to rotate and a place where group claims can be lost, so it needs the most testing of the four layouts.
- Bridge placement: run the bridge as its own service with its own hostname, reachable from MAS and from the SAML or LDAP source.
- Protocol mapping: translate SAML attributes or LDAP fields into the claims MAS expects, and verify the result end to end.
- Credentials: assign owners to LDAP bind accounts and SAML signing certificates, and set up alerts before their renewal dates.
- Extra components: the bridge and its configuration, any database the bridge requires, and the MAS database.
- Synapse SAML settings: Synapse can read SAML2 configuration itself, so confirm in the documentation whether those settings can run alongside MAS, since the usual pattern sends all logins through MAS.
Test a sign-in for a leaver as well as a new joiner, because removal is the step most often missed in bridged setups.
Configuration options and when each one fits
This table compares the main decisions for running MAS beside Synapse: hostname, database, upstream identity provider, SAML handling and install method. Read each row against your identity estate and your operating model, then confirm the trade-off before you commit to a design.
| Decision | What it controls | When it fits | Trade-off to confirm |
|---|---|---|---|
| MAS hostname on its own domain | The public address for login, OAuth 2.0 and the compatibility endpoints that Synapse and clients call | Separate host such as auth.example.com when you want MAS to keep a stable address if Synapse moves | Certificate, DNS and reverse proxy routes for a second hostname, and confirming the exact hostname your MAS version expects |
| Dedicated PostgreSQL database for MAS | Where MAS stores users, sessions and client registrations, separate from Synapse data | Dedicated database or role when you want independent backup, restore and access control for each service | Another database to back up, monitor and upgrade, and confirm the PostgreSQL version your MAS release supports |
| Shared PostgreSQL server, separate database | Same database server with a separate database and credentials for MAS | Smaller estates that already run a managed PostgreSQL instance and want one operations path | Shared resource contention and a single failure domain, so confirm backup and restore scope per database |
| Upstream OIDC provider such as Keycloak, Entra ID, Google or Authentik | Where users actually authenticate and which accounts MAS trusts | Organizations that already run an OpenID Connect identity provider and want MAS to delegate sign-in to it | Claim mapping, group handling and account linking must be tested with real users before rollout |
| SAML bridge such as Dex | Translates SAML assertions from an enterprise IdP into OpenID Connect for MAS | Required when your identity provider only offers SAML and the upstream OIDC route is not available | An extra service to deploy, secure and patch, and an extra hop in the login path to confirm |
| Direct OIDC without a bridge | Connects MAS straight to the upstream OIDC provider with fewer moving parts | Preferred when the identity provider supports OpenID Connect and your team can operate it | Requires the provider to supply the attributes MAS needs, so confirm scopes and claims early |
| Standalone MAS installation | MAS is installed and configured directly by your team on its own hosts or containers | Teams that want to control versions, configuration files and the proxy themselves | Your team owns upgrades, secrets, monitoring and the Synapse configuration changes that link the two |
| MAS deployed through Element Server Suite | MAS is installed as part of the ESS Helm chart with values managed in the chart | Teams already standing up ESS on Kubernetes who want the chart to wire components together | Chart version pinning and the ESS feature set must be checked against your required MAS settings |
Setup sequence for MAS linked to Synapse
This sequence takes a new homeserver from an agreed server name to a running Matrix Authentication Service that issues tokens for Synapse, with a check at each step so the team knows the layer is working before the next one depends on it. It is written for the platform engineers who will operate both services.
Decide the MAS domain under the server name layout
The platform lead confirms the permanent server_name and the subdomain for MAS, such as auth.example.com (illustrative), before any configuration is written. The MAS hostname becomes part of the public login URL, the OIDC issuer and the redirect URIs that the upstream provider will trust, so changing it later means re-registering clients. Done when the hostname, its DNS record and its TLS certificate plan are written down and agreed with the team that owns the Synapse and Element Web names.
Create the MAS PostgreSQL database and role
The database administrator creates a dedicated PostgreSQL role and database for MAS, separate from the Synapse database, and grants that role rights only on its own database. Confirm the PostgreSQL major version you run is in its supported range, since the versioning policy lists the support end date for each release. Done when a connection test from the MAS host with the new role succeeds and the Synapse role cannot read the MAS database.
Register MAS as an OIDC client with the upstream provider
An identity administrator registers MAS as an OpenID Connect client at the upstream provider, such as Keycloak, Microsoft Entra ID, Google or Authentik, using the redirect URI that MAS documents for its upstream login callback. Record the client ID, the client secret and the issuer URL in your secrets store, not in plain configuration. Done when the provider's discovery document loads from the MAS host and the client shows as enabled with the expected redirect URI. Note that MAS does not speak SAML, so a SAML-only provider needs a bridge first.
Configure MAS and Synapse to point at each other
The platform engineer sets the MAS configuration with the upstream provider, the database connection and the public URL, then adds the matching MAS section to the Synapse configuration so Synapse delegates authentication to MAS and trusts its introspection endpoint with a shared secret. Both sides must agree on the issuer, client ID and secret. Restart Synapse only after MAS starts cleanly. Done when MAS logs show it has loaded its configuration and migrated its schema, and Synapse starts without configuration errors.
Route the compatibility layer through the reverse proxy
The engineer configures the reverse proxy so the MAS hostname serves the OIDC and account pages, and the Matrix client paths that Synapse must receive go to Synapse while the MAS compatibility endpoints go to MAS. Confirm the exact path list in the current MAS documentation for your version, and keep the Synapse admin API off public routes. Done when a request to the MAS discovery endpoint returns a valid JSON document over HTTPS and a client-API request from outside the network reaches the expected service.
Verify login and token refresh
A tester signs in through Element Web or another Matrix client using a test account, which should trigger the redirect to the upstream provider and back to MAS. Then the tester leaves the session open past the access token lifetime configured in MAS and confirms the client refreshes silently rather than prompting for a password. Done when the login completes, the session appears in the MAS account page, and the refresh succeeds without a new sign-in. Record the token lifetimes you tested against.
Verify a test room end to end
The tester creates a room with the test account, invites a second test account created through the same upstream provider, and exchanges messages in both directions. The tester also checks that a federation-related request from the second account's server behaves as your federation policy intends. Done when both accounts send and receive messages, the room state appears in Synapse logs without authentication errors, and the test results are saved with the configuration version so the team can repeat them after upgrades.
Which admin tasks move from Synapse to MAS
Once MAS owns authentication, the account lifecycle moves with it. User creation, password resets, device and session management and registration rules are handled by MAS rather than by Synapse's own login. Synapse still stores the rooms, events and media, and it still identifies users by their Matrix IDs, but the decision to let someone sign in, register, change a password or end a session now sits in MAS. Your team should write down, for each task your current runbooks cover, which system performs it after the switch. Typical rows are account creation, deactivation, password reset, email verification, registration token issuance, device listing and forced logout. Any task that stays on Synapse needs an owner and a documented path, or it will quietly fail when someone follows an old procedure.
The practical effect lands on admin scripts and on the Synapse admin API. Scripts that call Synapse's registration or password endpoints directly, or that read login state from Synapse's database, will stop producing the result they expect once MAS is the authority. Inventory every script, cron job, moderation bot and ticketing integration that touches /_synapse/admin or user records, and classify each call as read-only, account-changing or session-changing. Account-changing and session-changing calls need a new route through MAS or a re-test against the MAS interface. Read-only calls may still work, but confirm that each field they read is still populated under the new flow. Keep the admin API off the public internet while you do this, as the proxy and hardening sections describe.
Confirm the exact admin commands against the current MAS documentation before you change any script. The command names, the CLI subcommands, the configuration keys and the admin API routes depend on the MAS and Synapse versions you run, and they have changed between releases, so this page does not list them. Ask the MAS and Synapse documentation for the version you plan to deploy, and test each replacement in a staging homeserver that uses a copy of your production database. Record the results in your change log, including which legacy calls were removed, which were replaced and who approved the replacements. Your administrators should also agree which accounts hold MAS admin rights, since those rights no longer come from Synapse's configuration alone.
Security and operational considerations for MAS and Synapse
MAS and Synapse share trust, data and sign-in paths, so the weak points sit at their seams: secrets, databases, exposed endpoints and the upstream identity provider. The cards below cover the decisions to settle before go-live and the checks to repeat after each change.
Keep signing keys and client secrets out of version control
MAS holds its signing keys and the client secrets it uses with each upstream OpenID Connect provider, and Synapse holds the shared secret used for the MAS link. Store these in a secret manager or in files injected at runtime, and keep only templates in your repository. Check that no key material appears in Git history, container images or CI logs, and record who can rotate each secret and how a rotation affects active sessions.
MAS upstream SSO docsSeparate MAS and Synapse databases
Give MAS its own PostgreSQL database and role, separate from the Synapse database and its credentials. A compromised or misconfigured service then cannot read or change the other's data, and each can be upgraded, restored or moved on its own schedule. Confirm that each role has rights only to its own database and that the connection settings for each service point to the correct one.
Restrict admin and internal endpoints
Keep the Synapse admin API, the replication listener and MAS management routes off the public internet. Expose only the client, federation and MAS login paths that users and other servers need, and restrict the rest at the reverse proxy and firewall. Confirm the restrictions with an external scan after every change to routing, because a single missing location block can publish an administrative interface.
Plan token and session lifetimes with the upstream provider
Session length in MAS and session length at your identity provider both decide how long a user stays signed in and how fast a disabled account loses access. Agree on these values with the team that runs the upstream provider before go-live. Test what happens when a user is deactivated upstream, and confirm whether MAS ends existing sessions or only blocks new sign-ins.
Back up both databases together
Back up the MAS and Synapse databases on a shared schedule, and take a snapshot of the MAS and Synapse configuration and secret stores alongside them. A restore that brings back one database without the other can leave user accounts, device records and sign-in links out of step. Test a full restore into a separate environment, including a login through the restored MAS, before you rely on the backup.
Set retention for sign-in event logs
Sign-in events from MAS and access logs from the reverse proxy record user identifiers, IP addresses and device details. Decide how long each log type is kept based on your data protection obligations and incident response needs, and document who can read them. Confirm where logs are shipped, that they are protected in transit and at rest, and that deletion runs automatically when the retention period ends.
Questions teams ask before deploying MAS
What does a MAS deployment cost, and what drives the price up?
The cost is the effort of the work, paid either to your own staff or to a partner, and it is mostly one-time: design, build, migration and testing. The largest drivers are the number of upstream identity providers you connect, how many environments you need (usually at least staging and production), and whether existing Synapse accounts must be moved onto MAS. Each extra provider adds configuration, attribute mapping and login testing. Recurring costs are upgrades, identity provider changes and the infrastructure that runs MAS and its own PostgreSQL database. Ask any quote to itemize these, state which environments are included, and say whether account migration is in scope.
How long does a MAS deployment take?
Duration depends on how many identity providers must work on day one, whether the team already runs a working OpenID Connect provider, and how many existing accounts must be migrated. A deployment that reuses one provider with a known configuration takes far less time than one that adds several providers, custom claims and a migration from password-based Synapse accounts. Plan time for DNS and certificate issuance, the mail settings MAS needs before users can register, and a staging run with real test accounts. Ask for a timeline that lists these milestones separately, so you can see which items depend on other teams.
What must our team provide before the work starts?
You need to provide administrative access to the identity provider, such as Keycloak, Microsoft Entra ID, Google or Authentik, so a client application can be registered and claims can be checked. You also need DNS control for a separate MAS hostname, TLS certificates for it, and a PostgreSQL server where MAS gets its own database. Access to the Synapse configuration and its reverse proxy is required, along with a mail relay for verification and recovery messages. Confirm early who approves changes to the identity provider and who holds the database administrator role, because these approvals often set the schedule.
Can our in-house team deploy MAS without a partner?
Yes, if your team already operates Synapse, a reverse proxy, PostgreSQL and an OpenID Connect provider, and can test login flows end to end. The work is mostly configuration and integration rather than new software, but mistakes in redirect URIs, claim mapping or the compatibility layer routes are easy to make and hard to diagnose from logs alone. A partner makes sense when the team lacks one of these skills, when the deadline is short, or when a formal test record is needed for a security review. Whichever route you pick, write down the scope, the tests and the rollback steps before the first change.
Does Element Server Suite include MAS?
ESS includes Matrix Authentication Service as one of its components, along with Synapse Pro, LDAP and SCIM integration and auditing, according to Element's description of the suite. ESS Community is free for non-professional deployments and evaluations, while ESS Pro is aimed at professional and government use. Whether a given edition's chart and support terms fit your environment should be confirmed with Element before you commit, because licensing and support scope differ between editions. If you already run Synapse outside ESS, adding MAS by hand is a separate project and does not require moving to the full suite.
How is MAS different from configuring Synapse OIDC directly?
With direct Synapse OIDC, Synapse itself talks to the upstream identity provider through its oidc_providers setting and keeps the login and session logic. MAS moves that job into a separate OAuth 2.0 and OpenID service that Matrix clients use, and it talks to the identity provider on the homeserver's behalf. This separation means account creation, session management and device handling are handled by MAS, and Synapse becomes a resource server that trusts MAS tokens. The trade-off is one more service, one more database and one more reverse proxy route to run, plus a migration step for existing users. MAS also does not support SAML directly, so SAML sources need a bridge such as Dex.
What breaks most often when MAS is linked to Synapse?
The most common failures are mismatched issuer or redirect URIs between the identity provider and MAS, a compatibility layer path that the reverse proxy does not forward to Synapse, and shared secrets that differ between MAS and Synapse. Clients may also show login loops when cookies or forwarded headers are set incorrectly. Check each of these first, using the MAS and Synapse logs at the time of a failed login. Keep the Synapse admin API off the public internet during testing, and confirm that existing password logins are either disabled or deliberately kept according to your migration plan.
How DeployOpen scopes and delivers MAS deployments
DeployOpen plans, builds, documents and supports self-hosted Matrix services inside the client's own infrastructure. For Matrix Authentication Service alongside Synapse, the work starts with a written scope that names the domains, databases, identity providers and admin tasks involved, then moves through a tested build and a handover the client's own team can run.
How we scope
- Confirm the permanent server name and the separate hostnames for Synapse, MAS and the compatibility routes before any build.
- Map the upstream identity provider, such as Keycloak or Microsoft Entra ID, and record which users and admin accounts move to MAS.
- Agree in writing which admin tasks shift from Synapse to MAS and who performs each one after go-live.
How we build
- Provision a dedicated PostgreSQL database for MAS, separate from the Synapse database, in the client's environment.
- Configure reverse proxy routes for the compatibility layer and link MAS to Synapse using the agreed shared secret handling.
- Test a login, token refresh, logout and a Synapse admin action end to end before any user is moved.
How we hand over
- Deliver configuration files, route maps, database layout and runbooks that name each component and its owner.
- Document the rollback limits and the backup points taken before the cutover, so your team can reproduce them.
- Walk your administrators through the MAS admin interface and the tasks that no longer run through Synapse.
How we support
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Ask any provider to confirm which MAS and Synapse versions their upgrade plan covers before you sign.

