I need a pre-configured keycloak instance deployed automatically during tests.
Importing users into Keycloak seems to be a challenge
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.
I have tried multiple approaches including, but not limited to:
ENV KEYCLOAK_IMPORT my-realm.json
in the docker file => Realm ✔ Clients ✔ Users ✖
Did not create Users but was perfect in term of workflow. It runs during the docker build.
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
Strategy: OVERWRITE_EXISTING
for users and provider to singleFile
. to have everything in one go.Clearly not a good fit for automation, but at least my JSON users are importable.
Is there some cheat code environemt variable like KEYCLOAK_FULL_IMPORT
that does everything in one go in the Dockerfile?
I confess with limited pride this was a stupid typo in my Dockerfile
For short I was copying from the wrong file. The proper configuration looked like this
FROM jboss/keycloak:latest
COPY my-realm.json /tmp/my-realm.json
ENV KEYCLOAK_USER admin
ENV KEYCLOAK_PASSWORD admin
ENV DB_VENDOR h2
ENV KEYCLOAK_IMPORT /tmp/my-realm.json
The typo was COPY some-realm.json /tmp/my-realm.json
where some-realm.json
did actually not include users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With