Why compare realm exports
Keycloak keeps its configuration in a database and changes it through the admin console, the admin API and imports. That makes it easy to change and hard to review. Two realms that should match, such as staging and production, drift apart one click at a time, and nobody can say exactly when or how.
A realm export captures the whole configuration as JSON. Comparing two exports answers the questions a plain look at the console cannot: what changed since last month, which client settings differ between environments, and whether an import did what you expected.
Why a plain text diff is not enough
You can run diff on two export files, but the result is mostly noise.
- Every object has an internal id, and ids differ on every server. Two identical clients on staging and production show as completely different.
- Lists come out in whatever order the database returns them, so a moved role or redirect URI looks like a removal and an addition.
- Nested objects, such as client attributes and flow executions, spread one change over many lines.
This tool compares the exports the way a person would: it matches each object by a stable name, ignores ids when asked, treats lists of plain values as sets, and reports each change as one line with the old and new value.
How objects are matched
| Section | Matched by |
|---|---|
| Realm settings | Field name, for every top-level setting |
| Clients | clientId |
| Realm roles | Role name |
| Client roles | Client id and role name |
| Groups | Full path, such as /staff/support |
| Client scopes | Scope name |
| Authentication flows | Flow alias |
| Identity providers | Alias |
| Required actions | Alias |
| Components | Component type and name |
| Users | Username |
Within a matched pair, the tool compares field by field and reports the path of each difference, such as web-app › implicitFlowEnabled. Objects that exist on one side only are reported as added or removed.
What this tool does and does not do
It reads two exports in your browser, compares them and lists the differences by section, with a text report you can copy into a review or a change ticket. Nothing is uploaded.
It does not tell you whether a change is right, and it does not produce an import file that applies the changes. Lists of objects inside an object, such as protocol mappers or flow executions, are compared as a whole: a change shows the full old and new value rather than each mapper. Large differences are shown in full in the text report, and the first 200 per section on the page.
How to use it
- Export the realm from both places, for example with
kc.sh exporton each server, or the admin console’s partial export. - Put the older or reference export in A and the newer one in B. Two made-up sample realms are filled in to show the output.
- Keep Ignore internal ids on when the exports come from different servers. Turn it off only to compare two exports of the same database.
- Read the differences section by section. Added items are on B only, removed items on A only.
- Copy the text report into the review, ticket or commit message.
## Realm settings
~ bruteForceProtected: false → true
~ passwordPolicy: "length(8)" → "length(12) and notUsername(undefined)"
## Clients
+ mobile-app
- legacy-portal
~ web-app › implicitFlowEnabled: true → false
~ web-app › redirectUris: + https://staging.example.com/*Getting comparable exports
A clean comparison starts with two exports made the same way. Use the same command on both sides, export one realm per file, and decide up front whether users belong in the comparison. Most configuration reviews do not need them, and leaving them out keeps the report short and free of personal data.
# on each server, against its own database
bin/kc.sh export --realm acme --file /tmp/acme-$(hostname).json --users skipThe admin console’s partial export also works, as long as both sides use the same choices for groups, roles and clients. Do not mix a partial export with a full one: the masked secrets and missing users would show up as differences that are not real.
Where it helps
Staging and production drift
Export the same realm from both environments and compare. Expected differences, such as redirect URIs with other host names, are easy to spot and skip. Unexpected ones, such as a flow edited only in production, are the reason to look.
Reviewing a change
Export before and after a change in the admin console. The diff shows exactly what the change touched, which is often more than the person who made it remembers. Keep the report with the change record.
Checking an import or a migration
After you import a realm into a new server or a new Keycloak version, export it again and compare with the file you imported. Differences show what the import changed or dropped. Some differences are normal across versions, because newer releases add settings or defaults. Read those as information, not errors. If you are moving to managed hosting, the same check fits the dry run described on our migration page.
Configuration in version control
Teams that keep sanitized exports in a repository can compare any two commits here when a line-based diff is too noisy, and attach the report to the pull request.
Reading the results
- Added means the object or field exists in B only. For clients and roles, that is something new in the later export.
- Removed means it exists in A only. Check whether the removal was intended before you copy configuration between environments.
- Changed shows the old value, an arrow, and the new value. For lists of values, it shows the items taken out with a minus and the items added with a plus.
A change in a secret field shows up as a change only if both files hold the value. If one export is masked or sanitized and the other is not, secrets appear as changed. Compare files cleaned the same way.
Common causes of noise
| Difference | Usual cause | What to do |
|---|---|---|
| Every client changed | Ids compared across servers | Turn on Ignore internal ids. |
| Many new settings | Exports from different Keycloak versions | Expect it; review only the settings you use. |
| Secrets changed | One file masked, one not | Sanitize both the same way. |
| Users added or removed | One export has users, the other does not | Export both with the same --users option. |
| Host names in URIs | Environment-specific redirect URIs | Expected; check the rest of the client. |
Security notes
Exports can hold secrets and personal data. Both files are read in your browser and nothing leaves the page, but the text report repeats the old and new values of what changed. If a secret or a user’s detail changed, it appears in the report. Run the files through the realm export sanitizer first when the report will be shared.
Best practices
- Export both sides the same way: same command, same
--usersoption, same sanitizing. - Compare one realm at a time.
- Keep a known-good export of each production realm and compare against it after every change window.
- Make configuration changes in staging first, then use the diff to confirm production received exactly the same change.
- When a difference is expected forever, such as host names, note it in the review so the next person does not chase it.