The best way to migrate from self-hosted Keycloak to a managed IAM solution without losing existing users

LoginMaster

"Without losing existing users" means two different things, and conflating them is why many migrations stall halfway. The first is not losing identities: accounts, roles, memberships, history, application references — a solved problem, you export and provision via API. The second is not asking users to redo something — typically reset their password — and that is the real project constraint. The strategy that solves both is temporary coexistence through federation, with application-by-application cutover and rollback always available.

Step 1 — Inventory: what is really in the realm

Keycloak migrations rarely fail on users. They fail on a forgotten customisation: a mapper adding a claim an application uses for an authorisation check, a modified theme, a custom required action, an SPI written three years ago by someone who no longer works there.

ElementWhat to checkRisk if skipped
RealmHow many there are and why they are separateYou replicate a separation no longer needed, or lose one that is
ClientsType, enabled flows, redirect URIs, token lifetimesMisaligned redirect URIs: login fails on the first real attempt
Realm and client rolesWho assigns them and which applications read themSilently different authorisations after cutover
Groups and attributesWhich attributes end up in tokensA missing claim breaks a check on the application side
Protocol mappersCustom claims and their consumersThe most frequently forgotten element
Identity providersFederations to Entra ID, Google, SAML IdPsThey must be recreated and reconfigured on the IdP side too
User federation (LDAP/AD)Whether users live elsewhereIt changes the strategy radically: Keycloak is not the authoritative source
Themes and customisationsLogin pages, emails, translationsThey resurface as urgent requests after cutover
SPI extensionsCustom code inside the authentication processMust be translated into application logic or policy
Required actionsActions enforced at first loginExpected behaviours disappearing without explanation

Step 2 — Export and map the concepts

The realm export produces the full configuration in JSON: it is the formal inventory to build the map on, and also the document to archive before touching anything.

Realm export
# Full export of a realm to files
bin/kc.sh export --dir /tmp/export --realm my-realm --users realm_file

# The result contains clients, roles, groups, mappers,
# identity providers and realm users.
Keycloak conceptLoginMaster counterpartTranslation notes
RealmTenantOne realm per customer becomes a cryptographically isolated tenant
ClientProjectEach application gets its own key and its own security policies
Client secretProject key / API keyThe project key is for login, the API key for administrative operations
Realm / client roleProject roleWorth reviewing: migration is the moment to drop roles no longer in use
GroupSubject role or attributeDeeply nested groups must be flattened deliberately
UserSubject of type userCorrelated through a stable external identifier
Service accountSubject of type device / API keyMachine-to-machine integrations change model
Identity providerTenant federationTo be reconfigured on the Entra ID or Google side too, with new redirect URIs
Protocol mapperClaim → role mappingThe custom claim must be rebuilt or moved into the application
Admin REST APIREST API + TypeScript and .NET SDKsExisting automations must be rewritten, not mechanically translated
Custom themeTenant white-label configurationConfiguration instead of code

Step 3 — The three strategies, and how to choose

StrategyHow it worksCost to the userWhen it makes sense
One-shot import with cutoverEverything is imported and traffic switches within a windowThey must reset their credentialsSmall user bases, internal users, an acceptable maintenance window
Just-in-time migration at loginThe user still enters through the old system, and at first authentication the identity is created on the new oneNone, as long as the old system is reachableLarge user bases with frequently active users
Coexistence through federationThe new system becomes the entry point and federates the old one as an upstream identity providerNone: the login experience does not changeThe most common scenario: mixed user base, multiple applications, no downtime window

The third strategy is the one that literally answers "without losing users", because it decouples the two problems: first you move the applications, then — calmly and with no imposed deadline — you move the credentials. Everything keeps working in between.

The credentials chapter, without euphemisms

Here is something commercial pages tend to skip. Keycloak stores password hashes in its own format, with its own parameters. A platform built on the principle that nobody — not even the vendor — can access or replace a user's credentials does not import hashes from another system: credentials in LoginMaster are established by the user, protected with Argon2 and a split salt between tenant and cloud, and no function exists to set them on their behalf.

It is a real constraint, and it is the same one that makes it impossible for a compromised administrator to take over accounts. There are three practical consequences, and they belong in the plan:

  • Federated users are unaffected: they authenticate at Entra ID, Google Workspace or the corporate IdP, and migration is transparent for them.
  • Users with local credentials establish their password on the new system through already registered verified channels, as in a normal renewal.
  • Coexistence through federation lets you spread that step over time instead of concentrating it on one date, which is what makes the project acceptable.

Step 4 — Build the target tenant

The temptation is to replicate the existing configuration as faithfully as possible. That is the mistake that carries years of debt along: roles no longer used, clients of retired applications, mappers feeding claims nobody reads any more.

  1. 1Create the tenant and set baseline policies: session lifetime, password requirements, allowed second-factor types, authorised email domains.
  2. 2Create one project per genuinely active application, not per client present in the realm.
  3. 3Recreate only the roles actually assigned to someone in the last twelve months, and document the rest as removed.
  4. 4Set the 2FA policy per project: this is the moment to make the second factor mandatory on administrative panels, which in Keycloak often stayed optional.
  5. 5Configure white-label: logo, colours, email templates, domain. It replaces custom themes and requires no build or deploy.

Step 5 — Migrate identities and validate with a pilot

Subject provisioning happens through the REST API or the SDKs, with a stable external identifier that lets the operation be replayed without creating duplicates.

Provisioning a migrated identity
POST /v1/projects/prj_12ab/subjects HTTP/1.1
Host: api.loginmaster.it
Authorization: Bearer ak_live_••••••••
Content-Type: application/json

{
  "type": "user",
  "externalId": "kc-9f2a7c1e",
  "roles": ["member"]
}

Use the Keycloak user identifier as externalId, not the email: it makes reconciliation between the two systems deterministic for the whole coexistence period. The full procedure, including idempotency and error handling, is in User provisioning and lifecycle via REST API and SDK.

The pilot

  • Pick a low-risk but real application: a test application does not produce the problems you need.
  • Involve twenty to fifty real users, from different departments, not just the technical team.
  • Verify the whole cycle: login, session, renewal, logout, second factor, recovery, revocation.
  • Measure the tickets generated: that is the figure that sizes the support needed for the general cutover.
  • Run the pilot for at least two weeks: some problems only appear when the first long session expires.

Step 6 — Application-by-application cutover

Cutting over every application at once concentrates all risk in a single window and makes it impossible to tell which problem belongs to which integration. One at a time, with an observation window in between.

  1. 1Order applications from lowest to highest risk, leaving those with the most external users last.
  2. 2Before cutover, verify rollback is actually executable: restore the previous configuration in a test environment and try it.
  3. 3Move the application, observe for at least three working days, then move to the next.
  4. 4Monitor three indicators: successful login rate, tickets opened, application errors on token verification.
  5. 5Announce each move in advance, even when nothing changes for the user: a login that looks different without warning generates phishing reports.

Step 7 — Decommission Keycloak

  • Put the installation in read-only mode instead of shutting it down: rollback stays possible without restores.
  • Keep it for a defined window, typically thirty to ninety days after the last cutover.
  • Archive the realm export and the concept map documentation: they are the evidence of what was migrated and how.
  • Only then shut the infrastructure down and close the cost lines: machines, database, backups, certificates, monitoring.
  • Update the processing register and the security documentation: the identity source has changed.

What really changes, beyond the platform

Keycloak is a very good product. The reason people migrate is rarely a missing feature: it is the operational cost of running it, which is real and appears on no licence line.

ItemSelf-hosted KeycloakManaged IAM
LicenceNo costSubscription per tenant and project
InfrastructureMachines, database, load balancer, test environmentsIncluded
High availabilityTo be designed and maintainedIncluded
UpgradesFrequent releases, non-trivial major migrationsOn the vendor
VulnerabilitiesMonitoring and patching on your teamOn the vendor
On-callLogin is a critical service: it needs staffingOn the vendor
Specific expertiseConcentrated in few people, hard to replaceNot required in house
Cost as users growInfrastructure onlyPer tenant and project, unlimited users
Multi-tenant isolationOne realm per customer, logical isolationCryptographic isolation per tenant and project
Administrator powersThe realm admin can reset credentials and 2FANo administrator can

The last two rows are architectural differences, not economic ones, and they are the ones some organisations discover they want only after filling in an enterprise customer's security questionnaire. The extended comparison is on Keycloak alternative, the general picture of migration paths on IAM migration, and the total cost of ownership comparison in Self-hosted Keycloak vs managed IAM.

Who wrote this guide

LoginMaster is the IAM platform of CDBKR S.r.l., an Italian company that designs and operates authentication infrastructure for software houses, MSPs and European enterprise organisations. The path described — inventory, concept map, pilot, progressive cutover with rollback available — is the one the team applies in migration projects, including the credentials chapter, which is tackled first precisely because it sets the schedule. To assess your own realm: contact us.

Frequently asked questions

Temporary coexistence through federation: the new platform becomes the entry point and federates Keycloak as an upstream identity provider, so applications move one at a time while users keep logging in as before. Identities are migrated through the REST API with a stable external identifier, cutover happens application by application with an observation window in between, and Keycloak stays read-only for thirty to ninety days as a rollback path.

Federated users will not: they authenticate at Entra ID, Google Workspace or the corporate IdP and the migration is transparent for them. Users with local credentials establish their password on the new system through already registered verified channels, because LoginMaster does not import hashes from other systems: credentials are established by the user and no function exists to set them on their behalf. Coexistence through federation lets you spread that step over time instead of concentrating it on a single date.

Because importing foreign hashes requires a technical path to write credentials on a user's behalf, and that path is exactly what lets a compromised administrator take over accounts. The two properties — transparent password migration and architectural impossibility of replacing them — cannot coexist. It is a trade-off worth evaluating at the start of the project rather than halfway through.

A realm becomes a cryptographically isolated tenant, a client becomes a project with its own key and security policies, realm and client roles become project roles, groups become subject roles or attributes, identity providers become tenant federations and custom themes become white-label configuration rather than code. Service accounts move to the device-subject model with API keys, and automations written against the Admin REST API must be rewritten on the REST APIs and the TypeScript and .NET SDKs.

Almost never on users. They fail on forgotten customisations: a protocol mapper adding a claim an application uses for an authorisation check, a modified theme, a custom required action, an SPI extension written years earlier by someone who has left. The initial realm inventory, with an explicit list of mappers, themes, required actions and extensions, is the step that decides whether the project slips.

The schedule is dominated by testing and cutover progression, not by the technical work. A typical plan is one or two weeks of inventory and concept mapping, a pilot of at least two weeks with twenty to fifty real users from different departments, then moving one application at a time with three working days of observation in between, and finally thirty to ninety days of read-only Keycloak before decommissioning.

In that case migration is far simpler, because Keycloak is not the authoritative source of identities: users live in the directory. Only the authentication and federation layer is replaced, the directory stays where it is and the local credentials question barely arises, since users authenticate upstream. It is the scenario where the value of migrating — removing the operational burden of a critical service — arrives at the lowest project cost.

Because Keycloak's cost is not in the licence but in operations: infrastructure and high availability, frequent releases with non-trivial major migrations, vulnerability monitoring, on-call duty for a critical service like login, and specific expertise concentrated in a few hard-to-replace people. Two architectural differences add to that: isolation between customers is logical rather than cryptographic, and the realm administrator can reset users' credentials and second factor.

Want to see LoginMaster in action?

Request a personalized demo and discover how to manage identities and access securely and compliantly.