Keycloak to Keycloak identity brokering between realms or instances

A practical plan for brokering one Keycloak realm or instance to another over OIDC, covering client and provider settings, claim and role mapping, logout propagation, and when a single realm is the simpler design.

On this page

How Keycloak brokers sign-in from one realm or instance to another

When a central workforce realm or Keycloak instance should feed one or more product realms, the supported method is Keycloak's OpenID Connect identity brokering: the downstream realm acts as an OIDC client of the upstream realm, and the upstream realm remains the login authority. Users type their credentials only into the upstream realm, which handles passwords, MFA and account state. The downstream realm never sees a password and trusts the upstream realm's signed tokens, so the trust boundary sits at the upstream client registration and the signing keys behind it.

Each side stores different things. The upstream realm keeps the user record, credentials, groups and roles, and a client entry for the downstream realm with its redirect URIs and secret or client authentication settings. The downstream realm creates a generic OIDC identity provider that points at the upstream issuer, plus a local user record that is linked to the external identity on first login. Identity provider mappers then copy claims or upstream roles into local groups and roles. Those local copies can go stale if the upstream changes, so the mapper sync mode on each login is a design decision to make early, not a detail to leave at its default.

Brokering is one of several designs, not a default. A single realm with separate clients, groups and client scopes is simpler when all applications belong to one organization and need the same users, and it avoids a second set of local accounts to reconcile. Brokering earns its complexity when product realms need separate branding, password policies or administrators, or when a boundary must be enforced between customers. Confirm the generic OIDC provider settings, mapper options and logout behavior for your Keycloak release in the Keycloak server administration guide before you commit to a chain of realms.

What you need before configuring the broker

A Keycloak to Keycloak broker only works when both sides run supported releases, reach each other over trusted HTTPS, and agree on identifiers before anyone opens an admin console. The cards below cover the decisions and checks to settle on both the upstream and downstream instances first.

Matching Keycloak release lines

Both the upstream and downstream instances should run supported releases, and the team should plan to upgrade them on the same schedule. The current release is 26.8.1, published October 13, 2026. Confirm the exact release you will deploy, and whether a Red Hat build of Keycloak subscription applies, with the vendor or against your own environment before you design the broker.

Keycloak upgrading guide

Production database and clustering

Each instance needs a supported production database, not the development file database. Keycloak supports PostgreSQL 14 to 18 among other engines. Both supported high availability designs also require a synchronously replicated database, so confirm that your database platform meets this before you rely on either side for sign-in.

Keycloak database guide

TLS and reverse proxy on every issuer

The production guide calls for TLS on all communication and a reverse proxy with path restrictions. Each realm acts as an OIDC issuer that the other side calls over the network, so every issuer URL must use HTTPS with a certificate that the calling instance trusts. Check that the reverse proxy forwards the public hostname correctly, since a mismatched issuer breaks token validation.

Keycloak production guide

Separate admin and frontend hostnames

Expose the admin console and Administration REST API on a different hostname or context path from the public frontend URLs. The broker configuration on each side points at public endpoints, so keep the admin surface off the network paths the other instance uses. Decide these hostnames before you create clients, because changing an issuer later means updating every broker and redirect URI.

DNS and certificate trust between sides

Confirm that each instance resolves the other's public hostname from its own network, including any split-horizon DNS and private certificate authorities. Test the OIDC discovery document from both directions, because a broker that cannot fetch keys or the token endpoint will fail at the first login. Record which CA bundle each Keycloak trusts so renewals do not break the link unexpectedly.

Agreed client IDs and redirect URIs

Choose the client ID scheme and redirect URI pattern before configuration starts, for example one client per downstream product realm on the upstream realm. Each redirect URI must match exactly on the broker side, including the path Keycloak generates for the identity provider callback. Write the naming convention down with the owners of both realms so later changes go through one review.

Configuration sequence for a realm-to-realm broker

This sequence wires an upstream Keycloak realm to a downstream realm as an OpenID Connect identity provider, so users sign in once upstream and arrive downstream with a linked identity, mapped roles and verified token claims. Each step closes with a check you can run before moving on.

  1. Create the broker client in the upstream realm

    In the upstream realm, the team that owns workforce identity creates a client for the downstream realm, sets client authentication to on so it is confidential, and registers the exact redirect URI of the downstream broker endpoint, which follows the pattern of the downstream realm's base URL and the identity provider alias. Avoid wildcards in redirect URIs. Store the generated client secret in your secrets manager, not in a ticket. Done when the client shows a secret under its credentials tab and the redirect URI matches the downstream value character for character.

  2. Add the OpenID Connect provider downstream

    In the downstream realm, the product team adds an OpenID Connect identity provider and enters the upstream discovery endpoint, which is the realm's .well-known/openid-configuration document. Keycloak fills the issuer, authorization, token, userinfo and JWKS endpoints from that document. Confirm the client ID and secret from the previous step and check that the advertised issuer matches the URL you expect. Done when the discovery document loads without error and the endpoint fields populate automatically.

  3. Set client secret storage and sync mode

    Still on the provider, choose how the downstream realm stores the upstream client secret, preferably through a vault or environment reference instead of plain text in the realm export. Then choose a sync mode. Import mode copies the user on first login and does not update attributes later, while legacy and force modes refresh mapped attributes on each login. Decide this with the team that owns the mappers in the next steps. Done when the secret is not visible in plain text in the admin console and the chosen sync mode is recorded in your change ticket.

  4. Create a test user path in the upstream realm

    Before you involve real workforce accounts, create a dedicated test user in the upstream realm with known attributes, a group membership and a role that the downstream mappers should recognize. Assign the role through the upstream realm so it is present in the token. This gives you a controlled identity for every later check. Done when the test user can sign in to the upstream account console and the group and role appear on that user's profile.

  5. Configure claim and role mappers

    In the downstream provider, add mappers that copy upstream claims into downstream attributes, groups or roles. Use claim-based mappers for the claims that carry roles or groups, and hardcoded mappers only for values that never vary by user. Keep the mapping rules in version-controlled configuration so reviews can compare them with the upstream role catalog. Done when a test login shows the expected groups and roles on the linked downstream user, and no unexpected role is granted.

  6. Enable the redirector or login button

    Decide how users reach the upstream realm. You can show a login button on the downstream login page, or use the Identity Provider Redirector to skip the login form and send users directly upstream, optionally with a client-supplied hint. Test the path with the default provider disabled first so a misconfigured redirect does not lock out administrators. Done when both the button and the direct redirect route a test user to the upstream sign-in page and return to the downstream application.

  7. Verify the first login creates a linked user

    Sign in as the test user through the downstream realm. Check that the browser passes through the upstream login, returns to the downstream redirect URI, and that Keycloak accepts the authorization response, which includes the state and nonce checks performed on the ID token. Then open the downstream user and confirm a linked identity exists for the upstream provider alias with the expected subject. Done when the user appears once, the linked identity is present and a second login reuses the same account instead of creating a duplicate.

  8. Verify logout propagation and token claims

    Decode the ID token and access token issued downstream and confirm the issuer, audience, expiry and the mapped roles or groups match the test user's upstream state. Then test logout. Check whether a downstream logout ends the upstream session, and whether an upstream logout reaches the downstream realm through backchannel logout. Record the actual behavior, because brokered sessions do not always end together by default. Done when the token claims match your mapping table and the logout behavior is written down for the product owners.

Choosing between brokering, one realm, or separate instances

A single realm fits when every user comes from the same population and the same login policy applies to every application. Access differences are handled with groups, client roles and client scopes rather than with separate realms. Administration stays in one place, one set of sign-in flows and password or passkey policies applies, and each application still receives only the claims it needs.

  • Fewer moving parts: one set of users, one authentication flow set and one token issuer to monitor and back up.
  • Authorization by role: groups and client roles carry most access decisions, so product teams do not need their own realm to get different permissions.
  • Shared policy limits: token lifetimes, MFA rules and password policy apply realm-wide, so any product that needs a stricter rule will push you toward a second realm.
  • Branding is shared: all applications present the same login theme unless you build per-client theming, which adds maintenance.
  • Admin scope is broad: realm administrators can change settings that affect every product, so delegated administration needs careful role design.

Before choosing this shape, confirm how many product teams need different login methods or branding, who will administer the realm, and whether any application must accept users that others must never see.

How upstream claims map to downstream users, roles and groups

This table compares each upstream claim or attribute with the Keycloak identity provider mapper, user field, or attribute that receives it, the sync mode applied on each login, and who decides access. Read it as a checklist for the downstream realm, and confirm every claim name against a real token from the upstream Keycloak realm before you build mappers. The main takeaway is that identity fields, group membership and authorization each need their own mapper and their own owner.

Upstream claim or attributeKeycloak mapping targetSync mode and linking behavior
sub (subject)Federated identity link, not a user fieldKeycloak stores the upstream subject as the link key. Confirm the claim value is stable across upstream logins before first-login linking is enabled.
email and email_verifiedUser email field, with the verified flag set by the mapperLink by email only when email_verified is true in the upstream token. Otherwise require the user to confirm the account during first login.
preferred_usernameUsername, or a user attribute if usernames must stay localSet on first import. Changing it upstream later does not rename the downstream user unless you add an update mapper.
given_name and family_nameUser first name and last name fieldsUse the import sync mode for first login, or the force mode if the upstream directory owns names and changes must flow on every login.
Group or role claim (for example groups)Keycloak groups or realm and client roles through a claim-based mapperUse the force mode so removed upstream groups are also removed downstream. Local-only groups are not touched by this mapper.
Custom attributes (for example department or cost center)User attributes through an attribute mapperSet the sync mode to match ownership. Keep attributes that drive authorization in the upstream source of truth and document who edits them.
Authorization decisionsClient roles, client scopes and client policies in the downstream realmDecide per application whether the upstream token drives access or the downstream realm does. Mixing both in one role without a written owner causes drift.

Logout propagation and token lifetimes across brokered realms

A downstream logout does not end the upstream session by default. When a user signs out of a product realm that brokers to a central workforce realm, the central realm's browser session can remain active, so the next sign-in to another product may succeed silently. Decide early whether sign-out in a product realm should also end the central session, and document the answer, because the default behavior is usually not what security reviewers expect. Logout in the central realm is a separate event that does not automatically reach every product realm either.

Keycloak offers front-channel logout and back-channel logout for clients, and each direction has its own settings. Front-channel logout relies on the browser loading logout URLs in each application, which fails when a browser blocks third-party requests or an application is closed. Back-channel logout sends a server-to-server logout token to each client's registered endpoint, which is more reliable but requires network reachability between the realms or instances. In Keycloak 26.8, backchannel logout tokens from external providers must have their signatures validated, so confirm that the upstream realm's signing keys are correctly configured before you rely on propagation. Check these behaviors against the Keycloak server administration guide for your target release.

Token lifetimes need the same alignment. The product realm's access token and SSO session idle and maximum values should not outlive the central realm's session in a way that lets a product keep access after the workforce user is disabled or signed out. Review access token lifespans, SSO session idle and max timeouts, and the offline session settings in each realm, and record the intended combination. Then test logout from every product realm: sign in, sign out in one product, attempt to reach another product, sign out centrally, and confirm each downstream session ends as designed. Repeat these tests after every Keycloak upgrade, since logout behavior is one of the areas most likely to change between releases.

Security controls for a brokered Keycloak chain

A brokered chain adds trust edges: every realm trusts the one upstream of it, and each edge is a place where a leaked secret, a loose redirect or an unchecked token can cross a boundary. The cards below cover the controls that keep each edge narrow, from client credentials and URI matching to transport, admin exposure and metrics.

Client secret handling and rotation

The product realm holds a confidential client secret for the central realm, so that secret is a credential into the workforce realm. Store it in a secrets manager, never in realm exports or source control, and rotate it on a schedule and after any staff change. Check that rotation is coordinated on both sides, because a changed secret on one realm breaks every login until the other side is updated. Confirm how your team will rotate without a login outage.

Keycloak docs

Exact redirect URIs

Broad redirect URI patterns let an attacker who controls a client or a path on the same host receive authorization codes meant for another application. On the broker client in the central realm, register each product realm's broker endpoint as an exact URI, and avoid wildcards. Review the list whenever a product realm is added, moved or renamed, since stale entries often outlive the systems they served.

Restricting which clients may use the broker

Any client in the central realm that can start a brokered login can also inherit the realm's sign-in trust. Limit the central realm to the product realms that must federate through it, and give each product realm its own client with only the scopes and roles it needs. Review the client list on the central realm regularly, and disable clients that no longer have an owner.

TLS on every issuer and endpoint

Each realm reads the upstream issuer's discovery document, keys, authorization endpoint and token endpoint over the network. Plaintext or certificate-unchecked links let an attacker on the path substitute keys or tokens. Require HTTPS for every issuer URL and every endpoint in the chain, use certificates your trust store validates, and keep internal certificate authorities trusted by each Keycloak instance rather than by disabling verification.

Production guide

Separate admin hostname from public frontend URLs

If the central realm's admin console and Administration REST API share a hostname with the public login pages, any exposure of the login path also exposes administration. Serve the admin console and admin REST API on a different hostname or context path from the public frontend URLs, and restrict the admin path at the reverse proxy. Confirm that product realm administrators reach their own realm through the admin endpoint, not through the public login hostname.

Signature and issuer validation

A broker must reject tokens whose signature, issuer or audience does not match the configured upstream. Confirm that each identity provider is configured with the upstream issuer URL exactly, that signing keys come from the upstream's own JWKS, and that tokens from external providers are signature checked on backchannel logout. Keycloak 26.8 makes backchannel logout token signature validation mandatory for external providers, so verify that your configuration reflects it.

Upgrade notes

Trust-on-first-use linking

First broker login can link an upstream identity to an existing local account when the email matches. If the upstream does not verify email ownership, an attacker can claim an existing product account. Disable automatic linking where the upstream is not fully trusted, and require a review or re-authentication step before linking. Document which upstreams are trusted to assert email, because that choice decides who can take over which account.

Metrics exposure at /metrics

Keycloak exposes Prometheus-format metrics at /metrics on the management interface when started with --metrics-enabled=true. Metrics can reveal realm names, client activity and login volumes across the chain. Keep the management interface off public networks, allow scraping only from your monitoring servers, and confirm the endpoint does not appear on the public frontend hostname.

Metrics guide

Common brokering failures and how to fix them

This table lists the failures teams most often hit when a Keycloak realm or instance brokers to an upstream Keycloak, with the probable cause, what to check and the fix pattern for each. Work through the rows in order when a login breaks, because several symptoms share the same root cause.

FailureProbable cause and what to checkFix pattern
Redirect URI mismatchThe upstream client's valid redirect URIs do not match the broker's callback URL, which includes the realm and the alias of the identity provider. Check the exact scheme, host, port and trailing slash in the upstream client settings and the broker's redirect URI shown on the identity provider page.Register the broker's exact callback URL on the upstream client, one entry per environment. Avoid wildcards on production clients.
Invalid issuer or discovery URLThe broker points at a discovery endpoint on the wrong realm, a proxy hostname that differs from the frontend URL, or an issuer string that does not match the token's iss claim. Check the upstream realm's frontend URL setting, since it determines the issuer the upstream advertises.Use the upstream realm's OpenID configuration URL as the discovery URL, set the frontend URL on the upstream instance to the public hostname, and rerun discovery after any change.
Clock skew or expired tokensThe two servers disagree on time, so tokens look expired or not yet valid when they arrive. Check NTP synchronization on both sides and the token lifetimes on the upstream client.Synchronize time on every node with a trusted source, then confirm token lifetimes are long enough for the broker's login flow without being excessive.
Duplicate users on first loginThe broker creates a new local user because the upstream email matches an existing user but the first broker login flow does not link the account, or the upstream email is unverified or differs in case. Check the first login flow settings and whether the email claim is marked verified.Use a first broker login flow that links accounts on verified email, or require the user to confirm the link. Merge duplicates before enabling the flow for all users.
Role claims missing after the first loginIdentity provider mappers that assign roles or groups run only on first login by default, so later changes upstream never reach the broker. Check each mapper's sync mode and compare the user's roles in the broker with the upstream token.Set mappers to import on each login where upstream is the source of truth, and document which roles are managed locally so sync does not remove them unexpectedly.
Logout not reaching the upstream realmSingle logout depends on the broker holding the upstream session and sending a logout request to the upstream end session endpoint. Check that the broker's identity provider has logout configured, that the upstream client accepts the logout redirect and that the browser session still exists.Configure the upstream end session URL and the post logout redirect URI, then test a full logout from each product realm. Treat logout as best effort unless every product realm is checked.
Unreachable upstream causing login loopsThe broker redirects users to an upstream that is down or blocked, and the browser bounces between the two login pages. Check network reachability from the broker nodes, certificate trust, and whether the identity provider redirector is set to skip the login form.Restore connectivity or the trust chain first. If the upstream must stay optional, offer a local login path or a documented fallback instead of an automatic redirect.

Questions teams ask before brokering Keycloak to Keycloak

How much more effort does a brokered Keycloak design add compared with one realm?

A brokered design adds work in every place where one realm would have shared users, clients and roles. You configure a client in the upstream realm for each downstream realm, configure an identity provider in each downstream realm that points back upstream, and then build and test the mappers that carry identity, roles and attributes across. The added effort is mostly in design and testing rather than in clicks. Each extra product realm repeats the client, provider and mapper work, so the total grows with the number of realms and claims involved. Ask for a written list of realms, clients, mappers and logout flows before comparing any quote with a single-realm build.

What drives the effort in a Keycloak to Keycloak brokering project?

Four drivers account for most of the effort:

  • The number of product realms that receive identities from the central realm.
  • The complexity of claim and role mapping, especially when each product uses different role names or group structures.
  • Logout requirements, since front-channel and back-channel logout must reach every downstream realm and application.
  • Testing, which must cover first login, returning users, account linking, disabled users, and what happens when the upstream realm is unavailable.

Mapping and logout usually take more time than the initial connection. Teams that agree on a claim contract early reduce rework later.

What does the client team need to provide for brokering to work?

The client team needs to supply decisions and access that only they can give. Realm owners must agree which realm is the source of identity and which realms consume it. Someone needs to produce a claim inventory listing the claims, groups and roles each product expects. The team should provide test accounts in the upstream realm that cover each persona and edge case, plus access to the admin consoles of every realm involved. Each Keycloak endpoint needs a stable DNS name and a valid TLS certificate, because brokering breaks when issuer URLs change or certificates are not trusted. Confirm these items in writing before the design phase starts.

Can our team set up Keycloak to Keycloak brokering without outside help?

A team with Keycloak administration experience can set up a single brokered pair without outside help, provided it has the time and test environment to verify each flow. The harder part is the design. Decisions about claim contracts, token lifetimes, logout behavior and failure handling affect every product realm and are difficult to change later. Teams that run many realms or that must show their design to auditors often choose to have a partner plan and test the design, then carry out the build themselves or with a partner. DeployOpen plans, implements and tests self-hosted platforms in your own infrastructure, and most engagements are fixed-scope with the scope agreed in writing before work starts.

When is a single Keycloak realm the better choice?

A single realm is usually simpler when the applications share one user population, one set of roles and one administrative team. In that case, separate clients and client scopes give each application its own token contents without a second layer of identity. Brokering adds value when product realms need separate administration, separate password or MFA policies, or separate user populations that must stay isolated. If you only need separate branding or a different login page, a single realm with client-level settings and theme choices is often enough. Write down the isolation requirement first, then decide. If the requirement cannot be met in one realm, brokering is justified.

How does logout behave across brokered Keycloak realms?

Logout does not propagate automatically through every brokered realm. When a user signs out of a downstream application, the downstream realm ends its own session, but the upstream session may remain active unless logout is configured to reach it. Engineers should map each logout path, decide whether front-channel or back-channel logout is used, and test a sign-out from every application. Keycloak 26.8 upgrade notes state that backchannel logout tokens from external providers must have their signatures validated, so confirm that your configuration handles this for each provider. Test session timeouts as well, because an expired upstream session can leave a downstream session in an unexpected state.

What should we test before moving a brokered design to production?

Test the full user lifecycle across every realm pair. Include first login with account linking, returning logins, sign-in for users whose roles changed upstream, disabled upstream accounts, and logout from each application. Test failure paths too, such as the upstream realm being unreachable, an expired certificate, or a changed client secret. Check that mappers produce the expected tokens for each client, and record the results so auditors and product owners can review them. Confirm the high availability plan for the upstream realm, because it becomes a shared dependency for every product realm that brokers to it.

Running brokered realms after go-live

Once the brokering link works, the main risk is drift: one side upgrades, a mapper gets edited, or a client secret rotates on one instance and not the other, and logins begin failing in ways that look like upstream problems. Treat the central realm and every product realm as one system with a shared change calendar. Before any Keycloak minor release, read the upgrading guide for both instances and test the brokered login path in a staging copy of each. The 26.x line ships four minor releases a year, and the project states that breaking changes in a minor release are opt-in, so a minor upgrade is usually a review of new defaults rather than a rewrite. Confirm the exact behavior of your target version in the release notes before scheduling it.

Where both instances run on Kubernetes, pin the Keycloak Operator update policy to manual approval. The Operator documentation strongly recommends this to avoid unintended automatic upgrades, and it matters more when the central realm and a product realm sit on different clusters with different maintenance windows. Keep the upgrade order written down: usually the identity provider side first, then the brokered side, with a rollback path for each. Mappers, client secrets and redirect URIs belong under change control in the same way. Export the realm configuration on every change, record who approved it, and rotate client secrets on a schedule that both administrators agree to, because a rotation on the provider client that is not mirrored in the consumer's identity provider settings stops all brokered sign-ins at once.

Monitor broker logins as their own signal. Enable metrics on each instance with --metrics-enabled=true and scrape the /metrics endpoint on the management interface, so failed token exchanges and error rates on the brokered client are visible next to normal login traffic. Alert on a sudden drop in successful brokered logins, not only on server errors. Periodically review linked accounts and disabled upstream users: when a user is disabled in the central realm, confirm that the product realm's linked account is disabled or that its sessions end, and remove stale links for people who have left. Schedule this review quarterly, or as your access review cycle requires, and confirm with your Keycloak support provider how logout propagation behaves in your version before you rely on it for leaver cases.

How a login travels from a product realm to the workforce realm

The login starts when a user opens a product application that uses the product realm as its OIDC client. The product realm redirects the browser to the workforce realm, which acts as the upstream identity provider and authenticates the user there. The workforce realm then returns an authorization code, the product realm exchanges it for tokens over a back-channel request, and a first-login mapper step creates or links the local user. Check the trust boundary at the token exchange and confirm that the mappers copy only the claims the product realm needs.

Browser redirects, back-channel token exchange and first-login mapping across two realms.

How DeployOpen scopes and delivers a Keycloak brokering project

A brokering project starts with a written scope, agreed before any work begins. For Keycloak to Keycloak brokering, that scope lists each realm or instance involved, which realm is the central workforce source and which are product realms, and the client registrations on both sides. It also records the identity provider settings for each link, the mappers that turn incoming claims into roles and groups, the logout behavior expected across realms, and the test cases that prove each login path works. Because the scope names every realm, client and mapper, the quote follows from it directly. Decisions the client must make before build, such as whether a single realm would serve the need more simply, belong in the scope document too.

DeployOpen deploys and configures the self-hosted Keycloak instances inside the client's own infrastructure, whether that is their cloud accounts, data centers or restricted networks. The work includes TLS, reverse proxy rules for the admin console, and the configuration needed for the security team to review how tokens move between realms. Where the client's compliance program needs evidence, DeployOpen prepares the configuration records, test results and access control documentation that assessors ask for. DeployOpen does not issue audit reports or certifications; the client's independent auditor or certification body makes that determination.

After the first release, the client can keep the work current through an optional retainer. Retainers can cover Keycloak version upgrades, which the project publishes on a regular minor release cadence, and continuous testing of the brokering paths after each change. Ask for the retainer scope, response expectations and upgrade testing approach in writing, alongside the fixed-scope quote, so both the build and the run costs are visible before you commit.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.