Matrix and Keycloak SSO integration: what it does and which method applies
Keycloak connects to a self-hosted Matrix homeserver as an upstream OpenID Connect provider. You configure that connection either in Synapse's built-in oidc_providers setting or in Matrix Authentication Service (MAS), which then handles the Matrix-facing login and sessions itself. The choice decides which components you run, where the Keycloak client secret is stored, and which features you can rely on, so make it before you create the Keycloak client or write any configuration. The integration covers three things. Login sends users to Keycloak to authenticate and returns them to Matrix with an identity. Account linking maps the Keycloak subject to a Matrix user ID, which forces decisions about whether to match on username or email and how to treat accounts that already exist locally. Logout uses OIDC back-channel logout: when Synapse has backchannel_logout_enabled set and Keycloak has the back-channel logout URL, ending a Keycloak session also ends the Synapse session. Confirm the equivalent behavior under MAS in its upstream provider documentation before you depend on it.
The integration does not cover directory synchronization. Group membership and user lifecycle changes that originate in a directory are not pushed into Matrix by this login flow, so if you need automatic deactivation when someone leaves the organization, plan that as a separate workstream. SAML is also outside this path. Synapse can accept SAML2 through its saml2_config setting, but MAS does not support SAML and its documentation recommends a bridge such as Dex for SAML or LDAP sources. If any user population depends on SAML assertions from Keycloak, confirm that Keycloak can serve that population through the method you select, or plan a bridge before you commit to MAS.
Choose the Synapse oidc_providers route if you run Synapse alone, want fewer components, and are content with Synapse managing login. Choose MAS for a new deployment or for any deployment that will move to MAS later. Synapse v1.157.0 dropped the deprecated experimental MSC3861 delegation in favor of the stable MAS integration, so an installation that still uses experimental delegation has a migration task, not a small configuration change. Confirm the Synapse version you run against the upgrade notes before you choose.
Before the build starts, record four decisions in writing: the method, the attribute mapping from Keycloak claims to Matrix identifiers, the logout behavior you expect, and whether any user group needs SAML or directory-driven deprovisioning. Each decision changes the method or adds a separate project. Ask the Keycloak administrator for a confidential client dedicated to Matrix, the exact redirect URIs for the method you chose, and a set of test accounts that cover existing local users and new users.
Prerequisites for Keycloak SSO with Matrix
Keycloak SSO for Matrix depends on decisions made before any configuration file changes. Each item below sets a version, a dependency or an owner that the Synapse or MAS settings will rely on, so confirm them together with your Matrix and identity teams.
Synapse release and version pairing
Pick the Synapse release you will run and check it against the platform floors in the upgrade notes. Synapse 1.143.0 and later require PostgreSQL 14 or newer, and 1.142.0 and later require Python 3.10 or newer. Confirm which integration path your version supports, since Synapse v1.157.0 removed the deprecated experimental MSC3861 delegation in favour of the stable Matrix Authentication Service integration. Record the chosen version so later upgrades can be read against it.
Database and runtime floors
Synapse documentation recommends PostgreSQL for production, and SQLite is also supported. Check the database engine and Python interpreter on the hosts that will run the homeserver, not only in a lab copy. Keycloak's supported production databases include PostgreSQL 14 to 18 along with several other engines, while its default dev-file database is for development only. Decide which PostgreSQL major version both systems will use and who owns its patching.
Keycloak release in production
Run a Keycloak release your team already operates in production, so the identity service has a known upgrade and monitoring routine. The current release at the time of writing is 26.8.1, published October 13, 2026. Keycloak plans four minor releases a year and says breaking changes in a minor release will be opt-in. Confirm the version pairing with Synapse or MAS in their own documentation before you choose the target release.
Dedicated Keycloak client for Matrix
Create a client used only for Matrix sign-in, so its secret, redirect URIs and logout settings can be rotated without touching other applications. Set the redirect URI to the callback that Synapse or MAS documents for your chosen path. Add a back-channel logout URL if you want Keycloak logouts to end Synapse sessions. Ask the Keycloak administrator to confirm client authentication settings and token lifetimes before testing begins.
DNS and TLS for server_name and issuer
The server_name value fixes how user IDs such as @user:example.com and room identifiers are formed, and it is hard to change once accounts exist. Plan DNS records for the homeserver and for the Keycloak issuer, and issue valid TLS certificates for both hostnames. If you use delegation, confirm that federation reaches the host on the expected port, since Synapse federates on port 8448 by default.
Named owners for each system
Assign one accountable owner each for the Synapse homeserver, the database, Keycloak, MAS if you use it, and the DNS and certificate process. SSO failures often cross these boundaries, such as a changed issuer URL, an expired certificate or a Keycloak upgrade that alters a client setting. Write down who approves changes to the client, its redirect URIs and signing keys, and who responds to login incidents.
Choosing Synapse OIDC or Matrix Authentication Service for Keycloak SSO
For most teams the choice depends on where login and session decisions should live. Synapse's built-in OpenID Connect support lets the homeserver accept Keycloak logins directly. You add an entry under oidc_providers in the Synapse configuration, using the idp_id keycloak as in the Synapse Keycloak example, and Synapse handles the redirect, token validation and user mapping itself. Matrix Authentication Service (MAS) works differently. It is a separate service that acts as the OAuth 2.0 and OpenID provider for Matrix, and it uses Keycloak as an upstream OpenID Connect provider. Users sign in through MAS, which sends them to Keycloak, and the Matrix session model sits in MAS and is shared with Synapse.
Start with three questions. First, how many users and clients you expect. Both paths can serve a single homeserver, but the number of accounts, devices and other applications that will authenticate through Keycloak should shape your sizing and your Keycloak client layout. Confirm the sizing guidance for your expected load with your Synapse and MAS maintainers or your implementation partner before you commit. Second, whether you need the MAS session and device model, which manages Matrix sessions and devices in a dedicated service. If you have no requirement for that model, the Synapse path has fewer components. Third, whether your team can operate an extra service. MAS adds its own database, configuration, certificates, routing, upgrades and monitoring, and each of these needs a named owner before go-live.
Do not start new work on the removed path. Synapse v1.157.0 dropped the deprecated experimental MSC3861 auth delegation in favour of the stable Matrix Authentication Service integration. Older guides, sample configurations and community posts that describe MSC3861 settings may still circulate, so check any proposed configuration against the current Synapse upgrade notes and the MAS documentation before you copy it. If an existing deployment was built on the experimental delegation, treat the move to the stable integration as a planned migration. Read the upgrade notes for every Synapse version between your current release and your target, and test the change on a copy of your database first, because the upgrade notes warn that rolling back can be difficult after schema changes.
Before you choose, check two requirements that affect the design. Synapse's Keycloak documentation describes OIDC back-channel logout, enabled with backchannel_logout_enabled in Synapse and a back-channel logout URL configured in Keycloak, so that signing out of Keycloak also logs the user out of Synapse. Confirm that the same behavior works on the MAS path for the versions you plan to run before you rely on it. Also note that MAS does not support SAML. If your identity policy requires SAML or LDAP, the MAS documentation recommends a bridge such as Dex, and that route needs its own testing. Finally, record the decision with the Synapse, MAS and Keycloak versions you tested, so the choice can be reviewed at the next upgrade.
How to configure Keycloak as the login provider for Matrix
This sequence connects a Keycloak realm to a Matrix homeserver so users sign in with their Keycloak accounts and receive predictable Matrix IDs. Each step ends with a check you can run before moving on. Exact configuration keys come from the official Synapse OpenID guide or the MAS upstream SSO page, depending on the method you chose.
Confirm the integration method and naming policy
Decide whether Synapse handles OIDC directly or Matrix Authentication Service (MAS) handles it, because the redirect URI and config location depend on that choice. Your platform owner and identity team should agree on the claim that becomes the localpart of each Matrix ID, such as a username or email prefix, and write down the pattern. Confirm with your Matrix and Keycloak administrators whether MAS is already in place. Done when a written decision record names the method, the claim, and an example Matrix ID that follows your naming policy.
Create the Keycloak realm and client
In Keycloak, create or choose a realm for Matrix users and register a confidential OpenID Connect client for the homeserver or MAS. Set the redirect URI exactly as the Synapse OpenID guide or the MAS upstream SSO page specifies for your method, and note the client secret in your secrets store. Restrict the client to the scopes Matrix needs. Done when the realm's OpenID discovery document loads from the issuer URL in a browser or with curl and lists the authorization and token endpoints.
Set server name and public base URL
Set server_name to the domain that will appear in every Matrix ID, such as the part after the colon in an ID. Set the public base URL to the address users reach through their browser, and confirm the value matches the redirect URI registered in Keycloak. If you use delegation or federation, verify the well-known delegation and the federation listener settings against the Synapse federation documentation before going further. Done when the homeserver's public URL responds over HTTPS and the server name in the configuration matches the naming policy from step one.
Add the upstream identity provider entry
For Synapse, add an oidc_providers entry that points to the Keycloak issuer URL, client ID, and secret, with an idp_id such as keycloak. For MAS, add the matching upstream provider block in its configuration. Use the key names from the official guide for your version, since they change between releases. Validate the configuration file with the tool your installation provides. Done when the configuration parses without errors and the login page offers a Keycloak option alongside any existing sign-in methods.
Map claims to the Matrix user ID
Configure the attribute mapping so the Matrix localpart comes from the claim chosen in step one, and map the display name and email if your policy needs them. Sign in once with a test Keycloak account and decode the ID token or the userinfo response, which should show the claim you intend to use with the expected value. The resulting Matrix ID should match the agreed pattern exactly. Done when the decoded token contains the expected claims and the test account's resulting Matrix ID matches the naming policy.
Restart the service and test a login
Restart Synapse or MAS so the new configuration loads, and check the service logs for provider discovery or startup errors. Sign in with a test account through a client, then sign in again to confirm the same Matrix account is reused rather than duplicated. Test one account from each group that will use Keycloak, and include a user who is not an administrator. Done when each test account signs in on the first attempt, the Matrix ID is stable across logins, and no duplicate accounts appear in the user list.
Enable back-channel logout
Enable backchannel_logout_enabled on the Keycloak provider in Synapse, following the Keycloak section of the Synapse OpenID guide, and register the back-channel logout URL in the Keycloak client settings. Keycloak then notifies Synapse when a user logs out of Keycloak, so the Matrix session ends too. Confirm the exact setting names and URL format against the guide for your version. Done when signing out of Keycloak in a test session ends the corresponding Matrix session, and the test is repeated after the next restart.
How Keycloak back-channel logout ends Matrix sessions
Back-channel logout is the mechanism that signs a Matrix user out of Synapse when that user logs out of Keycloak. Synapse's OpenID Connect configuration includes the backchannel_logout_enabled setting, and Keycloak needs a back-channel logout URL configured for the Matrix client. When both are in place, a logout at Keycloak triggers a request from Keycloak to Synapse, which then ends the matching Synapse session. Synapse's Keycloak documentation describes this pairing. Before you build anything around it, confirm the exact endpoint path and the logout behavior for the Synapse version you plan to run, using the Synapse documentation for that release. Record the version in your design notes, because the endpoint and its behavior are the parts most likely to change between releases.
The main trade-off is between front-channel and back-channel logout. Front-channel logout relies on the user's browser to carry logout requests to each relying application. If the browser is closed, blocked, or never loads the logout page, the Matrix session may stay active. Back-channel logout does not depend on the browser because Keycloak sends a server-to-server request. That benefit has a cost: Keycloak must be able to reach the Synapse endpoint over the network. In practice, this means checking firewall rules, reverse proxy routes, internal DNS, and the TLS trust chain between the two systems. If Keycloak cannot deliver the request, the user may be signed out of Keycloak while the Synapse session continues. Plan monitoring for failed logout deliveries so that gap is visible.
Test logout with an active Matrix client session, not only with a browser session. Sign in to Element or another client on desktop and on mobile, confirm the session works, then sign out of Keycloak from a separate browser. Check whether each client loses access, and whether the device appears as ended in the Synapse session list for that user. Review the Synapse logs for the incoming logout request and any errors. Then repeat the test with the network path between Keycloak and Synapse deliberately blocked, so you can see what the users and administrators would observe during an outage. Record the observed behavior for each client type you support, because client token handling differs and the results affect what you tell users about sign-out.
Assign ownership for the logout path before go-live. A named owner should maintain the Keycloak client configuration, the Synapse OIDC settings, and the network route between them, and should review both after every Synapse or Keycloak upgrade. If you plan to adopt Matrix Authentication Service later, do not assume this Synapse setting carries over unchanged. Confirm the logout behavior for that architecture in the MAS documentation and retest. Document what happens when a user is disabled in Keycloak, since that is a separate action from logging out, and confirm with your Synapse version whether it changes existing sessions. Agree on how quickly a user's Matrix access must end after an offboarding event, then test that timing against your real environment.
Mapping Keycloak claims to Matrix user IDs and profile fields
This table lists each Keycloak claim that feeds a Matrix account, the Synapse or MAS field it populates, whether it is required, and what breaks if it is wrong. Read the first two rows first, because the subject and localpart decisions set each user's permanent identity. The server_name fixes how user IDs such as @user:example.com are formed, so settle naming before the first user logs in.
| Keycloak claim or attribute | Matrix or Synapse field | Required or optional | Failure if wrong |
|---|---|---|---|
| Subject (sub) | External identifier for the upstream provider, matched on each login (Synapse OIDC subject claim, MAS upstream subject) | Required | Returning users are not matched, so duplicate accounts can be created on the next login |
| Username (preferred_username or chosen attribute) | Input to the localpart template that forms the part before the colon in the Matrix ID | Required | Clashing or unreadable localparts; changing a Matrix ID after login is costly |
| server_name (configuration, not a claim) | Fixes the domain in every user ID, for example @user:example.com | Required | Changing it after first login orphans accounts and breaks existing references |
| Name (name or given and family name) | Display name template for the Matrix profile | Optional | Users appear under raw usernames in rooms; no effect on access |
| Email (email, with verification status) | Email template for the profile and contact details; confirm whether your version uses it for account matching | Optional, required if email-based policy applies | Matching on an unverified email can attach a login to another person's account |
| Groups or roles claim | No direct Matrix profile field; read by custom mapping or policy logic to decide room or account access | Optional, required if used for access decisions | Removed users keep access, or valid users are locked out; Synapse and MAS need custom logic here |
| Session identifier (sid) for back-channel logout | Ties a Keycloak logout event to the matching Synapse session when back-channel logout is enabled | Optional | Logout in Keycloak leaves Matrix sessions active until they expire |
What changes for admins and users when you adopt Matrix Authentication Service
Adopting Matrix Authentication Service (MAS) adds a service you must run. With MAS in place, clients authenticate against MAS, which acts as the OAuth 2.0 and OpenID provider for Matrix, and MAS in turn signs users in through an upstream provider such as Keycloak. Your team will deploy, upgrade and back up MAS alongside Synapse, its database and its configuration. Before you commit, confirm which MAS and Synapse versions the project documents as compatible for your release, and plan the upgrade order for both. Synapse v1.157.0 removed the deprecated experimental MSC3861 auth delegation in favour of the stable MAS integration, so an installation still on the experimental setup needs a dated migration plan before any other change.
Configuration also splits across two services. Synapse keeps homeserver settings such as server_name, federation and media, while MAS holds the upstream provider definitions, client registrations and the secrets those depend on. Each Keycloak client must use the callback URLs that MAS expects, and each value must be kept in step on both sides during changes. Decide early which team owns each file and secret store, and record which setting lives where. Back-channel logout is the area most likely to need verification. Synapse's Keycloak guidance covers backchannel_logout_enabled, but confirm with the MAS documentation how logout from Keycloak reaches MAS sessions before you rely on it in production.
MAS does not support SAML. If your identity source is SAML-only, the simplest path depends on whether Keycloak already sits in front of it. If Keycloak already brokers the SAML source, MAS can keep using Keycloak as its single upstream and the SAML work stays where it already lives. If Keycloak does not broker it, you need a bridge. The MAS documentation recommends Dex for SAML or LDAP sources, which adds another service to deploy, monitor and upgrade. The sibling topic on LDAP and Active Directory covers the Dex route in more depth, so treat the bridge here as a scoping decision: who runs it, and where its logs and certificates are kept.
Migration raises three questions to answer before cutover. First, existing users and their external identities: map how current Matrix accounts link to the subject claims your upstream provider returns, then test the mapping with a copy of your data, since a mismatch can create duplicate accounts. Second, sessions: plan for active devices and clients to sign in again, and tell users in advance so support requests do not spike. Third, whether Keycloak is already the upstream. If it is, most of the change sits in MAS and Synapse configuration. If it is not, adding Keycloak or a new identity provider widens the scope to cover that provider's own administration and recovery.
Element Server Suite (ESS) includes MAS, and it is available as ESS Community and ESS Pro, with ESS TI-Messenger for German healthcare. ESS is deployed on Kubernetes with Helm charts, which changes the operating model if your team currently runs Synapse on virtual machines. Packaging, licensing and support terms, including whether Element supports a MAS deployment that uses your own Keycloak as upstream, should be confirmed directly with Element before you choose between a self-assembled setup and ESS. Ask Element to state in writing which components it supports, which versions it pairs, and where its support stops.
Security settings that protect Keycloak SSO for Matrix
Signing Matrix users in through Keycloak moves trust into the identity provider and the redirect path between it and the homeserver. The cards below cover the settings that carry that trust, from client secrets and redirect URIs to federation exposure. Each one is a control your team should confirm against its own threat model and written policy before go-live.
Client secret storage and rotation
The Keycloak client that Synapse or MAS uses holds a secret that lets the homeserver exchange authorization codes for tokens. Keep it out of configuration files committed to version control, load it from a secrets store or environment at startup, and restrict who can read it in the Keycloak admin console. Confirm a rotation procedure exists, including how Synapse or MAS is restarted with the new value and how the old secret is revoked.
TLS on every redirect and issuer URL
The issuer URL, authorization endpoint, token endpoint and the homeserver callback URL should all use HTTPS with certificates your team controls and trusts. Mixed schemes or self-signed certificates that clients silently accept weaken the sign-in flow. Check that the issuer in the Synapse or MAS upstream provider configuration matches the issuer Keycloak advertises exactly, including the realm path.
Exact redirect URI values
Configure the Keycloak client with the full callback URL for each homeserver, not wildcards or broad path prefixes. Overly loose redirect URIs let an attacker register or reuse a return address that receives authorization codes. Review the list whenever a new client domain, MAS instance or test environment is added, and remove entries that no longer serve a live deployment.
Realm administrator scope
Limit the people who can change clients, mappers, identity providers and authentication flows in the Keycloak realm that fronts Matrix. A change to a client mapper or a login flow can alter which users receive access or which accounts are trusted. Use named administrator accounts, require strong authentication for them, and record who holds each realm role so changes can be traced in the admin event log.
Back-channel logout reachability
Synapse's back-channel logout depends on Keycloak calling the homeserver's logout endpoint directly. Where your network allows, make that endpoint reachable only from Keycloak's address range, and confirm the request path works through any reverse proxy or ingress. Test that logging out of Keycloak ends the Synapse session, and document what happens when the endpoint is unreachable so support teams know what users will see.
Federation listener exposure
Synapse's federation_domain_whitelist setting limits which remote servers can exchange events with your homeserver, and an empty list disables federation. Set it deliberately for your policy, and firewall the federation listener, usually port 8448, so only intended peers or your reverse proxy can reach it. Confirm the setting and firewall rules together, since the whitelist alone does not limit who can open a connection.
Production configuration and monitoring inputs
Review the Keycloak production configuration guidance, including hostname, proxy and HTTPS settings, and enable the metrics endpoint so login failures, token errors and session counts can feed your monitoring. Connect these signals to alert rules that cover failed Keycloak logins, unexpected admin changes and sudden shifts in sign-in volume. Confirm each control, and each alert, against your own threat model and policy before relying on it.
Common failures in Matrix and Keycloak SSO and how to fix them
This table lists the failures teams most often hit when connecting Matrix to Keycloak, whether through Synapse's built-in OpenID Connect support or through Matrix Authentication Service. Each row gives the symptom, the usual cause and the check that confirms the fix, so you can work from evidence instead of changing settings in turn. Start with the redirect URI and issuer rows, since they fail before any user data moves, and treat the realm change and MAS rows as planning items to settle before cutover.
| Symptom | Likely cause | Fix and the check that confirms it |
|---|---|---|
| Keycloak shows an invalid redirect URI error | The callback URL registered in the Keycloak client does not match the URL Synapse sends | Compare the client's valid redirect URIs with the callback URL built from your public base URL and idp_id, then run one test login |
| Login fails at discovery or the issuer does not match | Issuer URL omits the realm path or uses a different hostname, or the server cannot reach the discovery document | Fetch the realm's OpenID configuration from the Synapse host and compare its issuer value with the configured issuer |
| Matrix user IDs are numeric, random or unexpected | The mapping template reads a claim the token does not carry, or a claim that changes between logins | Decode a test ID token or read userinfo, confirm the claim appears on every login, and check the mapper in the Keycloak client scope |
| Intermittent token expired or not yet valid errors | Clock drift between the Keycloak, Synapse and MAS hosts | Check NTP sync status on each host, then compare the iat and exp values in a test token with host time |
| Logging out of Keycloak leaves the Synapse session active | Back-channel logout request blocked by network rules or an untrusted private CA, or backchannel_logout_enabled not set | Confirm the logout URL in Keycloak and the setting in Synapse, then check Keycloak event logs and Synapse logs for the delivery attempt |
| Existing users get new accounts or cannot sign in after a realm change | Keycloak issues new user identifiers in a new realm, so the stored link to the old identity no longer matches | Record subject values for test users before and after the change, and rehearse the identity mapping in a staging realm before cutover |
| Login works on one path but a second login page or error appears | The team configured an oidc_providers entry and an upstream provider in MAS for the same Keycloak client | Decide which service owns login, remove the other provider entry, and confirm the login URL and redirect target with a test sign-in |
Testing Keycloak SSO for Matrix before users move
Run this test plan in a non-production environment before any user is moved to Keycloak sign-in. The first group of tests covers first login for two account types: people who have never had a Matrix account, who should be created on their first sign-in, and people who already hold a password-based account on the homeserver. For existing accounts, decide and test how the Keycloak identity maps to the current Matrix user ID, and what happens when the proposed localpart is already taken. If accounts will be linked, test the linking flow with copied accounts from production data and confirm the outcome in writing before cutover. Record the Matrix user ID, the Keycloak subject and the display name for each test case so results can be compared later.
Logout needs its own tests because a session can end in one place and survive in another. Open Element or another Matrix client, sign in through Keycloak, then end the Keycloak session from the account console or admin console. Confirm that Synapse ends the matching session when back-channel logout is enabled with backchannel_logout_enabled and the back-channel logout URL is set in the Keycloak client. Then test the reverse direction: log out inside the Matrix client and check whether the Keycloak browser session remains, since that determines whether the next person on a shared workstation can sign in silently. Confirm the network path from Keycloak to Synapse, because a blocked callback leaves a session that looks active until its token expires. Repeat these tests on each client platform your users run.
Inspect tokens and claims before you trust the mapping. Sign in with a test user and read the ID token Keycloak issues, checking the subject, the preferred username, the email and any claim used for display name. Confirm that the claim chosen for the Matrix localpart is stable and unique, because a changed username in Keycloak can create a second Matrix account beside the original. Remove a mapped attribute from a test user and check the resulting error message. Then run the failure path: disable a Keycloak user, attempt a new login, and check whether an existing Matrix session continues until its own expiry or ends through back-channel logout. Record each result, since the answers determine what the help desk tells users during the transition.
Rehearse the rollback before cutover, not after it. The Synapse upgrade notes warn that rolling back can be difficult because database schema changes between releases may not reverse cleanly, so the rehearsal should run against a fresh copy of the production PostgreSQL database. Keycloak also migrates its schema automatically at startup by default, so a Keycloak rollback needs its own database backup taken before the change. Define a decision point in writing: the last moment the team will revert configuration, and the point after which it will fix forward instead. Keep the Synapse configuration and the Keycloak client export under version control so the previous state can be rebuilt. Time the rehearsal, record each step, and ask your vendor or support provider to confirm which Synapse and Keycloak versions you can run together before you begin.
Questions teams ask before they hire help for Keycloak SSO with Matrix
How much does a Keycloak SSO integration with Matrix cost?
The cost follows from the written scope, and DeployOpen does not publish a price list. The main drivers are the number of Keycloak realms and clients, how much claim mapping your users and groups need, whether you use Synapse's built-in OIDC support or Matrix Authentication Service (MAS), whether Keycloak runs in a high availability design, how deep your testing goes, and whether existing Matrix accounts must be migrated. Build work is usually one-time. Upgrades, monitoring follow-up and ongoing support recur and can be covered by a retainer. Ask for a quote that itemizes design, build, testing, cutover, documentation and any recurring support as separate lines, so you can see which items your team could take on.
How long does Keycloak SSO for Matrix usually take to set up?
The duration depends on the same drivers as the cost. A single realm with one client and a standard Synapse OIDC setup is the shortest path. Multiple realms, MAS, a clustered Keycloak, account migration and a longer test cycle each add phases. Your own availability also matters, since access approvals, DNS and TLS changes and the production change window are often the slowest steps. DeployOpen agrees timelines in writing as part of a fixed-scope engagement before work starts. When you request a plan, ask for the phases, the dependencies on your team, and the points where a change window is required.
What must our team provide for a Matrix and Keycloak integration?
Plan to provide the following before the build starts:
- Keycloak administrator access for the realm and client configuration, including a review of any existing realms
- DNS records and TLS certificates for the Matrix homeserver and, if used, the MAS hostname
- A naming policy for usernames, display names and Keycloak client identifiers
- Test accounts that cover each role, group and entitlement that should or should not reach Matrix
- A change window for the production cutover and a rollback window if the cutover fails
- A named owner on your side who can approve configuration changes and answer questions about your directory data
Missing items usually delay the schedule more than the technical work does.
Can a competent internal team set up Matrix SSO with Keycloak alone?
A team that already runs Keycloak and Synapse can usually do the basic setup alone. The Synapse OpenID Connect documentation includes a Keycloak example using an oidc_providers entry with the idp_id keycloak, and the Keycloak documentation describes how to configure back-channel logout so users are signed out of Synapse when they sign out of Keycloak. The harder parts are claim mapping that matches your access model, high availability for Keycloak with a synchronously replicated database, testing of logout and account edge cases, and keeping the configuration correct through later upgrades. Many teams build a pilot with a small set of test users first, then decide which parts to keep in house.
Should we use Synapse OIDC or Matrix Authentication Service with Keycloak?
Choose Synapse's oidc_providers configuration when you run Synapse as the only authentication component and want the smallest change. Choose Matrix Authentication Service when you want the Matrix authentication flow handled by a separate service that uses upstream OpenID Connect providers, and Keycloak is one of the supported upstream providers. MAS does not support SAML directly, and the MAS documentation recommends a bridge such as Dex if you need SAML or LDAP. Synapse v1.157.0 dropped the deprecated experimental MSC3861 auth delegation in favor of the stable MAS integration, so check which path your deployment already uses before you plan the change. Confirm the choice against the current Synapse and MAS documentation for your version.
What changes when we upgrade Keycloak or Synapse?
Keycloak now plans four minor releases a year, and since Keycloak 26.0 breaking changes in a minor release are opt-in, which makes minor upgrades easier to schedule. Keycloak migrates its database schema automatically at startup by default. For large deployments the upgrading guide suggests applying the SQL manually. If you use the Keycloak Operator, the project strongly recommends manual approval mode for operator updates. For Synapse, read every set of upgrade notes. Rolling back can be difficult because of database schema changes, Synapse 1.143.0 and later require PostgreSQL 14 or newer, and Synapse drops support for Python and PostgreSQL versions after upstream end of life. Plan a test upgrade of both systems against a copy of production data.
Does Keycloak high availability change how Matrix logins behave?
Keycloak documents three high availability architectures: a single cluster, optionally spread across availability zones, multi-cluster deployments without external Infinispan (v2), and the deprecated multi-cluster v1 design. Both supported designs need a synchronously replicated database. For Matrix, the practical concerns are that Keycloak must present the same issuer and endpoint URLs to Synapse or MAS whichever node answers, that the TLS and DNS names stay stable during failover, and that session and logout behavior is tested while one node is down. Ask the team to test a node failure and a database failover during the pilot, and confirm how your chosen Synapse or MAS version handles upstream endpoint changes in its documentation.
How are existing Matrix accounts moved to Keycloak logins?
Existing Matrix accounts can be linked to Keycloak identities, but the mapping must be decided before go-live. The key questions are which Keycloak attribute identifies each person, how that attribute becomes the Matrix localpart, what happens to accounts that have no matching Keycloak user, and whether existing passwords or devices are affected. Use your naming policy to fix these rules, then test them with a copy of the current user list and a set of test accounts. Also check which accounts are administrators and confirm that they keep access after cutover. Confirm the exact mapping behavior in the Synapse and MAS documentation for your version, because it differs between the two approaches.
How DeployOpen scopes, delivers and supports Matrix and Keycloak SSO
DeployOpen plans, implements and documents Matrix and Keycloak SSO inside infrastructure you control, whether you choose Synapse's built-in OpenID Connect support or Matrix Authentication Service. Engagements are fixed-scope, with the scope, deliverables and timelines agreed in writing before work starts.
How we scope
- Written scope fixes which Keycloak realms, clients and Matrix homeservers are in and out of the engagement
- Scope records whether Synapse OIDC or Matrix Authentication Service is the sign-in path, with reasons
- Scope lists logout behavior, user mapping rules and the systems that rely on each login
How we build
- Configure the Keycloak client, redirect URIs and back-channel logout URL for each Matrix component
- Set up the Synapse or MAS upstream provider entry and test sign-in, token refresh and sign-out
- Verify that a Keycloak logout ends the Matrix session, and document each failure case found
How we hand over
- Deliver configuration files, client settings and a runbook covering both Keycloak and the Matrix service
- Document the upgrade sequence, including Synapse release notes review and Keycloak version pinning
- Walk your operators through login troubleshooting, client secret rotation and account lifecycle tasks
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, agreed separately from the build
- Retainer scope can cover Synapse and Keycloak upgrades, planned in advance rather than applied ad hoc
- Ask us to confirm the support hours, response terms and included components in the written quote

