Abstract
I need a pre-configured keycloak instance deployed automatically during tests.
Importing users into Keycloak seems to be a challenge
Approach
I created a Docker container with predefined Realm/Users/Clients
Using the export / import feature I can easily rebuild a Realm with clients, but not Users.
To be clear, Users shows up in the JSON file. So the export looks legit.
Desperate Attempts
I have tried multiple approaches including, but not limited to:
ENV KEYCLOAK_IMPORT my-realm.jsonin the docker file => Realm ✔ Clients ✔ Users ✖
Did not create Users but was perfect in term of workflow. It runs during the docker build.
- Import through
docker exec ... action=import=> Realm ✔ Clients ✔ Users ✖
docker exec -it <id> /opt/jboss/keycloak/bin/standalone.sh -Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.realmName=myrealm -Dkeycloak.migration.file=/tmp/my-realm.json
- Set the
Strategy: OVERWRITE_EXISTINGfor users and provider tosingleFile. to have everything in one go. - Manually import through the admin console, Realm ✖ Clients ✔ Users ✔
Clearly not a good fit for automation, but at least my JSON users are importable.
Hence
Is there some cheat code environemt variable like KEYCLOAK_FULL_IMPORT that does everything in one go in the Dockerfile?
