Import/export realm functionality sucks

Exporting/importing a realm is really difficult for no reason. Especially if you are using Docker.

This means that making a simple backup, or doing a server migration becomes a time consuming process for what should otherwise be a basic, well supported feature of any software product.

Some issues I encountered:

  • Due to migration to Quarkus 70% of the docs/discussion you’ll find is obsolete
  • The official docker image runs as non-root, so if you mount a volume, and then inside Docker try to write a backup to it, it wont have sufficient write permissions
  • kc.sh export tries to start a HTTP server (???) which fails because Keycloak is probably already running. This means that you need to pass QUARKUS_HTTP_HOST_ENABLED=false (undocumented, of course).
  • Trying to import a realm depends on some special path where a .json needs to be placed --import-realm in combination with /opt/keycloak/data/import - silly
  • Importing the master realm will yield in the error Not importing realm master from file /opt/keycloak/bin/../data/import/master-realm.json. It already exists. with no help/hints how to force overwrite any existing configuration.

Please devs, try to keep it simple. I know Java is enterprise but this doesn’t mean you need to waste everyone’s time.

For example, in the web-interface you could have an option “export database”. And then you have an option “import database”… I know, totally out of this world. But you should try it, it will make the process easier.

4 Likes

I ended up writing a Python script that manually copies various entities (via the admin API) from the old instance to the new one. If you are a programmer, this is most likely the fastest way shakes head

I struggled some with this… I found that to import users, I had to use the combined file that has the realm AND the users… I also saw the buttons to manually do this disappeared…

Hello,

I confirm that the keycloak import/export process is very poorly designed, especially in a containerized environment (a k8s cluster in my case).

In my case I want to migrate from an old wildfly version which is no longer maintained to the latest version on quarkus but after reading an astronomical amount of documentation (all contradictory), I still can not achieve this task yet simple at first sight …

@g34h34h can you explain what does your script ?