Moving from a self-hosted Keycloak
How your realms move from a Keycloak you run, Red Hat Single Sign-On or the Red Hat build of Keycloak to your RealmDeploy tenant, what moves with them, and how the switch works.
You export your realms, they are imported into a staging copy first, you test, and then you switch your DNS. On Premium and Enterprise we do the import and the checks with you, in the plan's service hours; on Starter you follow these steps yourself, with a second realm as your staging copy (see Migration).
This works the same for upstream Keycloak, Red Hat Single Sign-On 7.x and the Red Hat build of Keycloak: they share the realm export format.
What moves, and what does not
| Moves | Does not move |
|---|---|
| Realms with their settings | Active sessions: every user signs in once after the switch |
| Clients and their secrets | The master realm: your tenant has its own |
| Roles and groups | Custom providers (SPIs), extensions and themes |
| Identity providers | Changes made in your Keycloak after the export |
| Users, including their password hashes | |
| The realms' signing keys |
Because password hashes move, users keep their passwords. Because the signing keys move, tokens your Keycloak issued keep validating, as long as the issuer URL stays the same, that is, you keep the same hostname.
Before you start
Tell us, through the contact form or in the dashboard:
- Your Keycloak version. We import with our version, which must be the same or newer. We cannot import into an older Keycloak.
- The realms to move, and roughly how many users each has.
- Any custom providers or themes. Your tenant runs the stock Keycloak image, so anything custom has to be removed or replaced with a built-in feature before the migration.
- Outside connections your realms use: SMTP, identity providers, LDAP. We open them in your tenant before the import.
- When you want to switch. We agree a cutover window with you.
1. Export your realms
Export from a Keycloak that is not taking writes: either stop your Keycloak, or run the export from a second instance against a copy of your database. Run this once per realm:
bin/kc.sh export --dir /tmp/kc-export --users realm_file --realm <realm>The same command works on the Red Hat build of Keycloak. On Red Hat Single Sign-On 7.x, which runs on JBoss EAP, the export runs at server start with system properties:
bin/standalone.sh -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.file=/tmp/<realm>-export.json \
-Dkeycloak.migration.realmName=<realm> \
-Dkeycloak.migration.usersExportStrategy=REALM_FILEStop the server once the export is written. Do not export master. The admin console's Partial export is not a substitute: it leaves users out and masks secrets.
The export contains password hashes, client secrets and private keys, so treat it as a secret. Encrypt it to the key we give you before you send it, never send it by email or chat, and delete it from your machines once the migration is done. We delete our copies too.
2. Dry run on a staging copy
We import your export into a staging tenant first. Test it with a real client of yours: sign in with an existing user and password, and check the flows your apps use.
3. Import into your tenant
When the dry run passes, we import into your tenant, with Keycloak stopped while the import runs. On Starter, you create the realm from the export file in the admin console instead (Create realm → Resource file). Then check:
- The number of realms, and of users in each realm, match your Keycloak.
- Clients, identity providers and their secrets are present.
- A test user signs in with their existing password through your hostname.
- The realms' signing keys match yours: the key IDs (
kid) at/realms/<realm>/protocol/openid-connect/certsare the same on both sides.
Cutover
- A day before: lower the TTL of your hostname's DNS record, so the change spreads quickly.
- In the cutover window: point the record at the hostname we give you (see Custom domains and TLS). Anything changed in your old Keycloak after the export does not come along.
- The first hour: we watch sign-ins, realm error rates and server errors.
Rolling back is pointing DNS back at your old Keycloak. Anything changed in your tenant after the switch stays behind.
Afterwards
Delete every copy of the export. Users sign in once, because sessions did not move; their passwords are the same.