Migrate from Keycloak to Firebase
Ce contenu n’est pas encore disponible dans votre langue.
This guide covers moving users from Keycloak to Firebase: what carries over and what doesn’t, how their passwords and second factors are handled, and the commands to run. It sticks to what is specific to this pair. The export guide for Keycloak and the import guide for Firebase cover each side in full, including a rehearsal with synthetic users.
What carries over
Section titled “What carries over”| Keycloak to Firebase | |
|---|---|
| Passwords | Not carried over: Firebase can’t import PBKDF2 and Argon2. Users reset their password. |
| Second factors | Not carried over: users enroll again on Firebase. |
| User IDs | The Keycloak user UUID becomes the Firebase uid, up to 128 characters. |
The Keycloak export leaves behind:
- Group and role memberships
- Federated (social) identities
- HOTP credentials, which CMF has no type for
- Required actions, consents and timestamps
Before you start
Section titled “Before you start”- iamigrate installed (see Installation).
- Shell access to the Keycloak server or container, to run
kc.sh export. The Admin REST API never returns password hashes, so iamigrate reads a realm export rather than a live instance. - Firebase. A Firebase project with Authentication enabled and the Email/Password sign-in method turned on (use a disposable project for the rehearsal), plus a service account key or an OAuth2 access token. The import guide walks through it.
1. Export from Keycloak
Section titled “1. Export from Keycloak”# On the Keycloak host, or inside its containerkc.sh export --dir /tmp/export --realm acme --users realm_file --http-management-port 9001
# Copy the result out, then convert itiamigrate export --source keycloak --in ./realm-export --out ./export/Service account users and users iamigrate can’t translate are skipped and listed in manifest.json. The Keycloak export guide covers running kc.sh export next to a live server.
The export is a snapshot: users created, and passwords changed, after it aren’t in it, so plan a freeze or a final re-export before cutover. Check export/manifest.json for skipped_records, because the command exits with status 0 even when users are skipped, and for the per-algorithm counts.
2. Deal with passwords
Section titled “2. Deal with passwords”Firebase imports bcrypt and scrypt hashes, and Keycloak stores PBKDF2 and Argon2, so no hash can be carried over. A user whose hash can’t be translated isn’t created at all, so drop every password from the export and the users are created without one:
gunzip -c export/users.cmf.jsonl.gz \ | jq -c '.password = null' \ | gzip > export/users.ready.cmf.jsonl.gzThose users then need to set a new password. Send them a password reset email, for example with the Admin SDK’s generatePasswordResetLink.
Read the later steps from export/users.ready.cmf.jsonl.gz.
3. Deal with second factors
Section titled “3. Deal with second factors”| Second factor in the export | On Firebase |
|---|---|
| TOTP (portable) | Not imported. The user is created and listed under requires_reenrollment, and enrolls again after signing in. |
| WebAuthn (flagged non-portable) | Not imported. The user is created and listed in the report for follow-up, and enrolls again after signing in. |
| Recovery codes (flagged non-portable) | Not imported. The user is created and listed in the report for follow-up, and enrolls again after signing in. |
4. Fit the data to Firebase
Section titled “4. Fit the data to Firebase”- An email or a phone number is required. Firebase can’t create a user with neither, and reports
TRANSLATION_ERROR. Keycloak doesn’t require an email, so a realm can hold users that sign in with a username only. - Usernames are dropped. Firebase has no username sign-in, so users who signed in with a username need an email or phone number to sign in at all.
user_metadatais dropped. Firebase stores no free-form profile data. Every other user attribute arrives inuser_metadata. Move what you need intoapp_metadata(it becomes custom claims, limited to 1000 serialized characters and no reserved claim names), or keep it in your own database.- Names and picture.
profile.name(elsegiven_nameandfamily_name) becomesdisplayName, andprofile.picturebecomesphotoURL.
5. Validate against Firebase
Section titled “5. Validate against Firebase”Set the target in the scaffolded mapping, then check the export against what the target can import. validate makes no network calls:
iamigrate map --target firebase --mapping ./export/mapping.yamliamigrate validate --in ./export/users.ready.cmf.jsonl.gz \ --mapping ./export/mapping.yaml --target firebaseFix every reported problem at the source, or in the CMF records, and run it again until it comes back clean. Review mapping.yaml too: custom metadata keys are flagged under manual_steps for you to place, rather than guessed at.
6. Rehearse, then import
Section titled “6. Rehearse, then import”Do a rehearsal first. Follow the Firebase import guide with a fixture that holds the same hash algorithms and second factors as your users, against a disposable target, and sign in as a few of the users (see Generate test fixtures).
For the real run, point iamigrate at Firebase:
export FIREBASE_PROJECT_ID=acme-rehearsalexport GOOGLE_APPLICATION_CREDENTIALS=./service-account.jsonSplit off a small canary, import it, and check the result before you import the rest:
gunzip -c export/users.ready.cmf.jsonl.gz | head -n 100 | gzip > export/canary.cmf.jsonl.gzgunzip -c export/users.ready.cmf.jsonl.gz | tail -n +101 | gzip > export/rest.cmf.jsonl.gz
iamigrate import firebase \ --in ./export/canary.cmf.jsonl.gz \ --mapping ./export/mapping.yaml \ --report ./export/canary-report.jsonSign in as a few canary users, then import the rest:
iamigrate import firebase \ --in ./export/rest.cmf.jsonl.gz \ --mapping ./export/mapping.yaml \ --report ./export/rest-report.jsonThe command exits with status 0 even when users fail. Always read the reports: each failed user is listed under failed with a code, and the follow-up lists (requires_password_reset, requires_reenrollment and so on) say who needs to hear from you. The import guide explains each code.
7. Verify
Section titled “7. Verify”Reconcile the file with the live target. It reports users missing from it and drift in the fields it can read back:
iamigrate diff firebase --in ./export/users.ready.cmf.jsonl.gz --mapping ./export/mapping.yamlThere is no password to prove here, so check the reset path instead: make sure a test user can set a new password on Firebase and sign in.
Firebase keeps the source_id as the user’s uid, which Firebase limits to 128 characters. If your applications reference users by the old ID, keep that mapping.
Cutover
Section titled “Cutover”- Freeze changes in Keycloak, re-export, and import the final file.
- Reconnect what the export doesn’t carry: federated (social) identities, and group and role memberships. Then point every application at Firebase.
- Tell users what to expect. They need to set a new password. A second factor that didn’t move has to be enrolled again.
- Clean up the rehearsal. Delete the rehearsal project, or delete its users from Authentication → Users.