What Is Realm Export/Import in Keycloak?
The complete, in-depth guide to capturing an entire Realm's configuration as a portable file, and bringing it back to life elsewhere.
Imagine a restaurant that’s spent years perfecting a single dish — the exact ratios, the exact plating, the exact cooking times — and now wants to open a second location. Nobody wants the new kitchen to rediscover the recipe by trial and error; they want the entire written recipe card, every ingredient and every step, handed over intact so the second location can reproduce the dish exactly. A Keycloak Realm, built up over months through careful configuration of Clients, Roles, Authentication Flows, Identity Providers, and every other concept covered elsewhere in this series, is exactly this kind of hard-won recipe. Realm Export/Import is Keycloak’s own built-in mechanism for writing that entire recipe down to a portable file, and reading it back in wherever it’s needed next.
This guide is a comprehensive, ground-up exploration of Realm Export and Import: what actually gets captured, the difference between a full and a partial export, the file format underneath it, the several distinct ways an administrator can trigger an export or import, what deliberately does not travel along with the file, and the real-world patterns organizations use to treat their Realm configuration as reproducible, version-controlled infrastructure rather than a fragile, hand-clicked one-off. No prior background with backups or configuration management is assumed — every term is explained in full the moment it first appears.
1Core Concepts
What Is a Realm Export?
Export is the operation of writing out a Realm’s entire configuration — its Clients, Roles, Authentication Flows, Identity Providers, Groups, and (optionally) its Users — into a structured file, most commonly formatted as JSON, a widely used, human-readable text format for representing structured data. That file becomes a complete, self-contained snapshot of the Realm as it existed at the moment of export.
What Is a Realm Import?
Import is the reverse operation: reading a previously exported file back into a Keycloak server, recreating either a brand-new Realm from scratch, or updating pieces of an existing one, using the file’s contents as the source of truth for how that Realm should be configured.
It’s tempting to think of a Realm export as equivalent to backing up Keycloak’s underlying database, but the two are meaningfully different. A database backup captures everything, including internal implementation details specific to that exact database engine and version. A Realm export captures a portable, Keycloak-native representation of the configuration itself, deliberately designed to be readable and reusable across different Keycloak instances, database backends, and even certain version differences — a purpose-built configuration snapshot, not a raw data dump.
Why This Capability Exists
Manually recreating a Realm’s dozens of Clients, Roles, and carefully tuned Authentication Flows by clicking through the Admin Console every time a new environment is needed is slow, error-prone, and produces subtly different results each time a human repeats it by hand. Export/Import exists to make a Realm’s configuration something that can be captured once, reviewed, stored, and reliably reproduced — turning identity configuration into something closer to ordinary software, rather than a one-off manual artifact living only in one administrator’s memory of what they clicked.
2Architecture & Components
graph TD
DB["Keycloak's Underlying Database"]
DB -->|"Export reads from"| Realm["Realm Configuration
(Clients, Roles, Flows, IdPs, Groups, Users)"]
Realm -->|"Written to"| File["Portable JSON Export File"]
File -->|"Import reads from"| Target["Target Keycloak Server
(same server, another environment, or a fresh install)"]
Target -->|"Recreates or updates"| NewRealm["Realm Configuration on Target"]
Live Realm Configuration
The actual, currently running configuration inside a Keycloak server, built up through the Admin Console, the REST Admin API, or a prior import.
Export File
The portable JSON representation this guide focuses on, capturing everything needed to recreate the Realm elsewhere.
Full vs. Partial Export
Two distinct export modes, covered fully in Chapter 5, controlling exactly how much of the Realm’s data actually gets included.
Export/Import Method
Several different ways to actually invoke export or import, covered fully in Chapters 6 through 8 — the Admin Console, the standalone command-line tool, and startup-time import.
3What Actually Gets Captured
| Category | Included in Export? |
|---|---|
| Realm-level settings (session timeouts, security defenses, tokens) | Yes, always |
| Clients and their configuration | Yes, always |
| Realm Roles and Client Roles | Yes, always |
| Authentication Flows, including any Conditional Flows | Yes, always |
| Identity Providers and their Mappers | Yes, always |
| Groups and their Role assignments | Yes, always |
| Users | Only with a full export, or a partial export with users explicitly included — covered in Chapter 5 |
| Client secrets and Identity Provider credentials | Included, but deserve special handling — covered in Chapter 4 |
An export file reflects the Realm exactly as it existed the moment the export ran. Any configuration change made afterward, in either the source or a previously imported target, isn’t automatically reflected anywhere else — keeping multiple environments aligned over time requires a deliberate, repeated export/import process, covered further in Chapter 11.
4Secrets, Credentials, and What Deserves Special Handling
Client Secrets Are Included in Plain Text
A Confidential Client’s secret, covered elsewhere in this series’ guide to Client Authentication Methods, is written directly into the export file as plain, readable text. This means an export file is, functionally, a sensitive credential store in its own right, and needs to be handled with exactly the same care as any other file containing production secrets.
User Passwords Are Hashed, Not Reversible
When Users are included in an export, their passwords are exported in their already-hashed form — the same one-way, non-reversible representation Keycloak stores internally — rather than as plain text. This means an export doesn’t expose actual user passwords, though it’s still sensitive personal data deserving careful handling in its own right.
Because of the plain-text Client secrets described above, an export file should never be committed to a public or loosely access-controlled source-control repository, emailed casually, or stored somewhere without the same access restrictions applied to any other production credential material.
A Common Real-World Pattern: Export, Redact, Then Store
Many organizations address this by exporting, then deliberately stripping or replacing sensitive fields like Client secrets with placeholder values before the file is committed anywhere for version-controlled reuse, re-injecting real secrets separately at import time through an external secrets-management process rather than storing them inside the file itself.
Identity Provider Credentials Deserve the Same Treatment
Client secrets aren’t the only sensitive material an export can carry. Identity Brokering configuration, covered elsewhere in this series, often includes a client secret issued by the external Identity Provider itself, alongside whatever signing or encryption keys a SAML-based broker configuration might reference. Each of these deserves the exact same redaction discipline as a Client secret — a thorough security review of an export file checks every credential-shaped field, not only the most obvious one.
Production Example: A Templating Step in a CI/CD Pipeline
A mature deployment pipeline commonly runs an intermediate templating step between export and import, replacing every sensitive value with a placeholder token during export, and substituting genuine values back in — pulled from a dedicated secrets manager — immediately before the file is actually imported into its target environment. This keeps the file itself, at every point it might be stored or reviewed, entirely free of real credential material.
5Full Export vs. Partial Export
Full Export
- Captures the entire Realm, including every User account and their credentials
- Produces a much larger file, scaling with the number of registered Users
- Appropriate for genuine disaster-recovery backups, or migrating an entire Realm including its user base to a new server
- Typically performed through the standalone command-line export tool, covered in Chapter 7, rather than the Admin Console
Partial Export
- Captures the Realm’s configuration — Clients, Roles, Flows, Identity Providers, Groups — while excluding Users by default
- Produces a much smaller, more manageable file focused on configuration rather than data
- Appropriate for promoting configuration between environments, or checking configuration into version control
- Available directly from the Admin Console’s own export screen, with checkboxes to optionally include Users and Groups
Production Example: Choosing Partial Export for Environment Promotion
A team promoting a Realm’s tested configuration from a staging environment into production typically uses a partial export, since production’s own user base is entirely separate from staging’s test accounts, and including staging’s test users in the file would risk polluting production with accounts that were never meant to exist there.
6Deep Dive: Exporting and Importing From the Admin Console
Exporting a Realm From the Admin Console
Inside a Realm’s own settings, an Export action produces a downloadable JSON file representing a partial export of that Realm’s current configuration, with optional checkboxes to include Groups and Users if a fuller snapshot is needed for this particular export.
Importing a Realm From the Admin Console
From the Realm selection screen, an administrator can choose to create a new Realm by directly uploading a previously exported JSON file, rather than configuring every setting by hand — Keycloak reads the file and recreates the entire Realm’s configuration from it in one operation.
Production Example: Quickly Cloning a Realm for Testing
A developer wanting to experiment with a risky Authentication Flow change without touching the actual working Realm can export it, import that same file back in under a new Realm name, and freely experiment on the clone — a fast, low-risk way to create a genuinely isolated sandbox that starts from an exact, known-good configuration.
Importing through the Admin Console’s Realm-creation screen always produces a new Realm from the file’s contents. Updating an already-existing Realm’s configuration from a file is a different operation, more commonly performed through the command-line tool or startup-time import, covered in the following chapters.
7Deep Dive: The Standalone Export/Import Tool
Why a Separate Tool Exists
A full export of a Realm with a very large number of Users can be a substantial operation, and running it through the same live server handling ordinary authentication traffic risks impacting performance for real users during the export. Keycloak’s standalone export/import tooling is designed to run this kind of full, potentially large-scale operation directly against the underlying data, independent of the ordinary running server process.
Scripting Repeatable Operations
Because this tooling is invoked from the command line rather than clicked through manually, it fits naturally into automated scripts and scheduled jobs — a nightly full-export job feeding into an organization’s broader backup process, for instance, running unattended without requiring an administrator to remember to click through the Admin Console every time.
Production Example: Scheduled Full Backups for Disaster Recovery
An organization with strict recovery-point requirements might schedule a full export to run automatically every night, storing each resulting file in a securely access-controlled backup location, ensuring that even a catastrophic failure of the live Keycloak deployment leaves no more than a single day’s worth of configuration and user changes actually at risk of being lost.
8Deep Dive: Startup-Time Import
How It Works
Keycloak can be configured to automatically import one or more Realm files the moment the server itself starts up, rather than requiring any manual action after the server is already running. This is especially valuable in containerized deployments, where a fresh Keycloak container can come up already fully configured with its intended Realms, Clients, and Roles, entirely from files bundled alongside the deployment itself.
Startup-time import is like a new appliance that comes pre-loaded with its factory settings the moment it’s plugged in, rather than requiring someone to manually configure every option after unboxing it. The “settings file” — the exported Realm JSON — travels with the appliance itself, so every unit built from the same file starts in an identical, known state.
Production Example: Reproducible Local Development Environments
A development team can bundle a partial export of their application’s expected Realm configuration directly alongside their project’s own source code, letting any new developer spin up a fully configured local Keycloak instance — matching the team’s actual Clients and Roles — with a single command, rather than manually reconstructing that configuration by hand from a wiki page or a colleague’s memory.
9Internal Working: What Happens During an Import
File Is Read and Parsed
Keycloak reads the provided JSON file and parses its structure, validating that it represents a well-formed Realm configuration before attempting anything further.
Target Realm Identified
Keycloak determines whether the import should create a brand-new Realm, or update an already-existing one with a matching name, depending on the specific import method and its own configured behavior.
Configuration Objects Recreated
Clients, Roles, Authentication Flows, Identity Providers, and Groups described in the file are created (or updated) inside the target Realm, in a dependency-aware order that respects, for instance, a Role referenced by a Group actually existing before that Group is created.
Users Recreated, if Included
If the file includes Users, their accounts, hashed credentials, and Role or Group assignments are recreated as well, completing the full picture of the target Realm.
Realm Becomes Active
Once import completes successfully, the resulting Realm is immediately available for use, exactly as if every setting inside it had been configured by hand through the Admin Console.
10Behavior When Importing Into an Already-Existing Realm
Merge Behavior, Not a Clean Overwrite
Importing into an already-existing Realm generally merges the file’s contents into what’s already there, rather than deleting everything first and starting fresh. Existing objects matching something described in the file are typically updated to match, while objects entirely unmentioned in the file are generally left untouched, though the precise behavior can vary depending on the specific import method and configuration used.
Because unmentioned objects are typically left alone rather than removed, importing a file into an existing Realm is not a dependable way to force that Realm back to exactly and only what the file describes — anything added to the Realm since the file was captured will generally still be there afterward. A genuine, clean reset to match a file exactly usually requires deleting the existing Realm first and importing into a fresh one.
Why This Matters for Ongoing Environment Synchronization
Teams relying on repeated imports to keep an environment’s configuration aligned with a version-controlled source file need to understand this merge behavior clearly — configuration drift introduced through manual Admin Console changes made directly against a target environment won’t automatically be corrected by a subsequent import, unless that drift happens to be explicitly overwritten by something the file itself also describes.
What Genuinely Gets Removed on Import
It’s worth being precise about the boundary here rather than treating merge behavior as an all-or-nothing rule. A field that exists in the file and already exists on the target is generally updated to match the file’s value exactly. An object entirely described by the file but that already exists on the target under the same identifier is generally replaced with the file’s version of it. What generally survives untouched is an object that exists on the target but has no corresponding entry in the file at all — a Client an administrator created directly against the target environment after the file was last captured, for instance, is a common example of something an import typically leaves alone rather than removing.
Because the precise merge semantics can vary somewhat between Keycloak versions and between the different import methods covered in this guide, a team building a process that depends on this behavior should verify the actual, current result directly against their own deployed version, rather than assuming it matches exactly what an older guide or a different team’s experience described.
11Data Flow & Lifecycle
Initial Configuration. A Realm is built up through the Admin Console, the REST Admin API, or an earlier import, reaching a state worth capturing and reusing.
Export. The Realm is exported, choosing full or partial scope depending on the intended purpose, as covered in Chapter 5.
Secret Handling. Sensitive fields are reviewed and, commonly, redacted or externalized before the file is stored anywhere long-lived, as covered in Chapter 4.
Storage. The resulting file is stored — in version control for configuration promoted between environments, or in a secured backup location for disaster-recovery purposes.
Import. The file is imported into its target — a fresh environment, a new Realm clone, or a startup-time provisioning process — recreating the captured configuration there.
Drift Management. Over time, the target environment may accumulate its own changes; a deliberate process for re-exporting and re-synchronizing keeps environments meaningfully aligned rather than silently diverging.
graph LR
A["Realm Configured"] --> B["Exported
(Full or Partial)"]
B --> C["Secrets Reviewed
& Redacted"]
C --> D["Stored
(Version Control / Backup)"]
D --> E["Imported Into Target"]
E --> F["Ongoing Drift
Managed & Re-synced"]
F --> B
12Advantages, Disadvantages & Trade-offs
Advantages
- Turns Realm configuration into something reproducible and reviewable, rather than a fragile artifact living only in one administrator’s manual clicks
- Enables reliable environment promotion — moving tested configuration from staging into production consistently
- Supports genuine disaster-recovery backups through full exports capturing Users alongside configuration
- Fits naturally into automated provisioning, including startup-time import for containerized deployments
Disadvantages & Trade-offs
- Export files contain genuinely sensitive material — Client secrets in plain text — requiring the same careful handling as any other production credential
- Import into an existing Realm merges rather than cleanly resets, which can be surprising if a true, exact reset was actually intended
- A large full export, including every User, can be a substantial operation better suited to the standalone tooling than casual Admin Console use
- An export file is a point-in-time snapshot; keeping it meaningfully synchronized with an evolving live Realm requires deliberate, ongoing process rather than a one-time effort
13Security
Problem
A team wanting to version-control their Realm configuration exports it directly from the Admin Console and commits the resulting JSON file, unmodified, into a shared source-control repository readable by the entire engineering organization.
Why It Fails
As covered in Chapter 4, this file contains every Confidential Client’s secret in plain, readable text. Committing it unmodified exposes every one of those secrets to anyone with read access to the repository, and — because source-control history is typically permanent — simply deleting the file afterward doesn’t remove the exposure from the repository’s history.
Correct Approach
Redact or externalize sensitive fields before committing, following the pattern described in Chapter 4, and treat any export file that did contain real secrets as itself compromised, rotating those secrets, exactly as would be done for any other leaked credential.
Import as a Privileged Operation
Because an import can create Clients, assign Roles, and configure Identity Providers, the ability to perform an import is itself a highly privileged capability, deserving the same restriction and audit trail as any other administrative action covered elsewhere in this series’ discussion of Realm administration.
Validate Untrusted Import Files Before Use
An import file received from outside a fully trusted source — a vendor-provided template, for instance — deserves careful review before being imported, since a maliciously crafted file could introduce an unexpected Identity Provider, an unexpected administrative Role assignment, or other configuration a team wouldn’t have knowingly approved.
Production Example: A Malicious or Compromised Template File
Consider a scenario where a third-party vendor supplies a “starter Realm” template meant to speed up onboarding, but that file has been tampered with — perhaps quietly including an additional administrative Role assignment for an account the vendor controls, or an Identity Provider configured to trust an unexpected external authority. Because import applies the file’s contents largely as-is, a team that imports it without careful review could unknowingly grant standing administrative access to an outside party, discovered only much later during an unrelated security audit.
Least-Privilege Access to Export Files Themselves
Beyond who is allowed to perform an import, it’s worth separately restricting who can even read an already-produced export file, given the plain-text secrets it may contain, as covered in Chapter 4. Storage locations for these files — whether a version-control repository, a backup archive, or a shared drive — deserve access controls scoped as narrowly as the sensitivity of their contents actually warrants, rather than being left as broadly readable as an organization’s more routine, non-sensitive documentation.
14Monitoring, Logging & Metrics
Import Event Logging
Recording exactly when an import ran, who triggered it, and which Realm it targeted supports later review of how a given configuration state actually came to exist.
Post-Import Configuration Diffing
Comparing the target Realm’s resulting configuration against the source file after an import helps catch any unexpected merge-related surprise, as discussed in Chapter 10.
Scheduled Export Success Tracking
For a nightly backup process built on full exports, monitoring that each scheduled export actually completed successfully is essential — a silently failing backup job provides no real protection at all.
Environment Comparison Over Time
Periodically re-exporting a live environment and comparing it against the version-controlled source file that originally provisioned it reveals how much manual drift has accumulated since the last synchronized import.
15Design Patterns & Anti-patterns
Good Patterns
- Use partial exports for configuration promotion between environments, and full exports specifically for genuine disaster-recovery backups
- Redact or externalize secrets before storing any export file long-term or in version control
- Use startup-time import for reproducible environment provisioning, particularly in containerized deployments
- Understand merge behavior explicitly before relying on import to synchronize an already-existing environment, verifying the actual resulting state rather than assuming a clean reset occurred
Anti-patterns to Avoid
Common Mistakes
- Committing an unredacted export file containing plain-text Client secrets to a shared repository, as covered in Chapter 13
- Assuming an import into an existing Realm cleanly resets it to exactly match the file, when it actually merges
- Running a large full export against a live, production-traffic-handling server rather than using the standalone tooling designed for it
- Never re-exporting after manual changes, leaving the version-controlled source file silently out of date with reality
16Real-World & Industry Examples
Continuous Integration Pipelines
A software team’s automated pipeline commonly spins up a fresh Keycloak container using startup-time import of a version-controlled partial export, giving every automated test run an identical, known-good identity configuration without any manual setup step.
Multi-Environment Promotion
An organization maintaining separate development, staging, and production Realms typically exports configuration from a lower environment once it’s been tested and approved, then imports that same file into the next environment up, ensuring consistent configuration travels deliberately through each stage rather than being manually re-created at every step.
Disaster Recovery Planning
A regulated organization with strict recovery-time requirements typically maintains a scheduled full-export backup process, storing each resulting file in a securely access-controlled, geographically separate location, ensuring a catastrophic failure of the live deployment can be recovered from a recent, complete snapshot.
Vendor and Partner Onboarding Templates
A platform onboarding many similar partner organizations might maintain a partial export representing a standard “starter” Realm configuration, importing a fresh copy for each new partner rather than manually reconfiguring the same set of Clients and Roles by hand every time.
Migrating Between Self-Hosted and Managed Deployments
An organization moving from a self-managed Keycloak cluster to a managed hosting offering, or between two entirely different infrastructure providers, commonly leans on a full export as the actual migration vehicle — capturing the complete Realm, including its Users, from the old environment and importing it directly into the new one, avoiding a slow, error-prone manual reconstruction of years of accumulated configuration.
17Frequently Asked Questions
18Summary and Key Takeaways
Key Takeaways
- Export writes a Realm’s entire configuration to a portable JSON file; Import reads that file back in, recreating or updating a Realm from it.
- A full export includes Users and is suited to disaster-recovery backups; a partial export focuses on configuration and is better suited to environment promotion and version control.
- Export files can be triggered three main ways: the Admin Console for occasional manual use, the standalone command-line tool for large-scale or scripted operations, and startup-time import for automated, reproducible provisioning.
- Export files contain Client secrets in plain text — treat them exactly like any other production credential, redacting or externalizing sensitive fields before long-term storage.
- Importing into an already-existing Realm merges rather than cleanly resetting it — objects not described in the file are typically left untouched.
- Treating Realm configuration as a version-controlled, exportable/importable artifact turns identity infrastructure into something reproducible and reviewable, rather than a fragile, manually clicked one-off.
- Restrict both who can perform an import and who can even read a stored export file, given the plain-text credentials it may carry, and validate any file received from outside a fully trusted source before importing it.