Why realm exports need cleaning
A realm export is the easiest way to show someone how a Keycloak realm is set up. Support engineers ask for it, consultants review it, and teams keep it next to their code. The trouble is that a full export from kc.sh export holds more than configuration. It holds the secrets that protect the realm.
Anyone with those secrets can act as your applications, sign tokens your apps will trust, or read the password hashes of every user. A file like that should never reach a ticket, a chat thread or a public repository as it is.
What secrets a Keycloak export contains
| Where | Field | What it unlocks |
|---|---|---|
| Confidential clients | secret | Getting tokens as that client, for example with the client credentials grant. |
| Identity providers | config.clientSecret | Acting as your realm toward Google, Microsoft or another provider. |
| Key providers | privateKey, secret | Signing tokens, or HMAC and AES keys, that your apps trust. |
| LDAP federation | bindCredential | Reading, and maybe writing, your directory. |
| SMTP settings | smtpServer.password | Sending mail as your realm. |
| Users | credentials | Password hashes and OTP secrets, open to offline guessing. |
Users also carry personal data: usernames, email addresses, names and attributes. Even without credentials, that data is often covered by privacy rules.
What this tool does
The sanitizer walks the whole JSON tree of the export in your browser and treats secrets in three ways.
Known secret fields
Fields Keycloak uses for secrets are handled wherever they appear: secret, clientSecret, password, bindCredential, privateKey, keystorePassword, keyPassword, registrationAccessToken and secretData. Each one is named in the report with its path, such as clients[billing-service].secret.
Fields that look like secrets
With the extra option on, any other field whose name contains secret, password or private key, and which holds a real value, is masked too. Names that only describe a setting, such as passwordPolicy or a URL, are left alone. Values written as ${...} placeholders are kept, since they point to a vault or environment variable rather than holding the secret.
Users
By default the whole users list is removed, with its personal data. If you keep users, their credentials are still removed, so no password hash or OTP secret stays in the file.
Mask or remove
You choose what happens to each secret.
- Mask replaces the value with
**********, the same text Keycloak’s own partial export uses. The structure stays, so a reviewer can see that a client has a secret without seeing it. - Remove deletes the field. The file is smaller and cannot be mistaken for a working export.
Neither choice can be undone from the file. If you import a sanitized export, Keycloak gets a masked value or no value at all, so you set those secrets again afterwards: new client secrets, the identity provider secrets, the LDAP bind password and the SMTP password. Key providers without their private keys need new keys, and tokens signed with the old keys stop verifying.
What it cannot find
The tool knows Keycloak’s field names. It cannot know your own. A secret stored under another name passes through untouched, for example:
- a token kept in a custom user or client attribute;
- an API key in the config of a protocol mapper or a custom provider;
- a webhook URL with a key in its query string;
- a value in a theme property or a script.
That is why the report always ends with a reminder to read the file yourself before you send it. Search it for words such as key, token, secret and password, and look at any long random-looking strings.
How to use it
- Export the realm with
kc.sh exportor the admin console. - Open the file with Open a file, or paste it. A made-up sample realm with fake secrets is filled in to show how it works.
- Choose mask or remove, and whether to drop users.
- Read the list of what was taken out. Each line has the reason and the path.
- Search the result for anything the tool could not know about.
- Copy the JSON or save it with Save file, under a new name.
client secret clients[billing-service].secret
identity provider client secret identityProviders[google].config.clientSecret
realm private key components.org.keycloak.keys.KeyProvider[rsa-generated].config.privateKey
LDAP bind password components.org.keycloak.storage.UserStorageProvider[corporate-ldap].config.bindCredentialWhen to use it
Asking for help
A support engineer or a community forum can often spot a problem from the realm configuration alone. Send a sanitized export without users; it shows the settings and flows without handing over access.
Keeping configuration in Git
Teams that track realm changes in a repository should commit sanitized exports only. Pair it with the realm export diff to review what changed between commits.
Moving to another environment or provider
When a realm moves from one setup to another, the people planning the move need its configuration long before they need its secrets. Share a sanitized copy for planning, and move the secrets separately, through a channel meant for secrets. For a move to managed hosting, see how migration works.
Audit and review
Reviewers need to see that secrets exist and where, not their values. Masking keeps that information in place.
If an export has already leaked
Treat every secret in it as known to others and rotate them. In practice that means:
- Regenerate the secret of each confidential client and update the apps that use it.
- Add new keys under Realm settings, Keys, make them active, and retire the old ones once tokens signed with them have expired.
- Create new client secrets at each identity provider and update them in Keycloak.
- Change the LDAP bind password and the SMTP password.
- If users and credentials were in the file, consider requiring a password change for them.
Common mistakes
- Sharing the users file. With
kc.sh export --dir, users sit in their own files next to the realm file. Clean those too, or leave them out. - Trusting the mask alone. A partial export hides secrets, but it can still name internal hosts, LDAP base DNs and admin usernames you may not want to share.
- Cleaning a copy and sending the original. Save the result under a new name, such as
acme-sanitized.json, and attach that file. - Forgetting old copies. Exports left in downloads folders, build logs or old tickets keep their secrets. Search for them and delete them.
- Importing a masked file into production. Keycloak cannot recover masked secrets, so apps that use those clients stop working until you set real secrets.
Privacy of this page
The file is read with the browser’s FileReader. Parsing, cleaning and saving all happen on your computer; Save file writes a new file without any upload. Nothing you paste is sent to us. Close the tab when you are done, so the original stays only where you keep it.
Best practices
- Prefer the admin console’s partial export when users are not needed. It masks secrets already, and the sanitizer then catches the rest.
- Store secrets in a vault and reference them with
${vault.name}style placeholders, so exports do not hold them at all. - Never commit an unsanitized export, even to a private repository.
- Sanitize before you analyze or compare, if other people will see the results.
- Keep the original export encrypted, or delete it once you no longer need it.