Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak fails to import exported realm running in docker

I started my keycloak service using the command:

docker run -d -p 8180:8080 -e KEYCLOAK_USER=admin -e \
KEYCLOAK_PASSWORD=admin -v $(pwd):/tmp --name kc \
jboss/keycloak:8.0.2

I created a new realm on keycloak only giving it a name, nothing else. Exported it running the command:

docker exec -it kc keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.realmName=my_realm \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/my_realm.json

I now have the realm in the my_realm.json file. I then start a new keycloak using docker compose to set up my entire test environment. I build a new docker image with the this DockerFile:

FROM jboss/keycloak:8.0.2

COPY my_realm.json /tmp/my_realm.json

ENV KEYCLOAK_IMPORT /tmp/my_realm.json
ENV KEYCLOAK_MIGRATION_STRATEGY OVERWRITE_EXISTING

Docker compose:

version: '3.4'
volumes:
  postgres_kc_data:
    driver: local
services:
  kc_postgresql:
    image: postgres:11.5
    volumes:
      - postgres_kc_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: kc
      POSTGRES_USER: kc
      POSTGRES_DB: kcdb
    ports:
      - 50009:5432
  keycloak:
    build: "./keycloak/" # ref to folder with above DockerFile
    environment:
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      DB_VENDOR: POSTGRES
      DB_ADDR: kc_postgresql
      DB_DATABASE: kcdb
      DB_SCHEMA: public
      DB_USER: kc
      DB_PASSWORD: kc
    depends_on:
      - kc_postgresql
    ports:
    - 8080:8080

The log output from running docker compose indicates that it is not able to import realm, and suggests something about validating the clients. I added no clients, so these are the default ones.

08:39:46,713 WARN  [org.keycloak.services] (ServerService Thread Pool -- 67) KC-SERVICES0005: Unable to import realm Demo from file /tmp/my_realm.json.: java.lang.NullPointerException
    at [email protected]//org.keycloak.url.DefaultHostnameProvider.resolveUri(DefaultHostnameProvider.java:83)
    at [email protected]//org.keycloak.url.DefaultHostnameProvider.getScheme(DefaultHostnameProvider.java:38)
    at [email protected]//org.keycloak.models.KeycloakUriInfo.<init>(KeycloakUriInfo.java:46)
    at [email protected]//org.keycloak.services.DefaultKeycloakContext.getUri(DefaultKeycloakContext.java:79)
    at [email protected]//org.keycloak.services.util.ResolveRelative.resolveRootUrl(ResolveRelative.java:45)
    at [email protected]//org.keycloak.validation.DefaultClientValidationProvider.validate(DefaultClientValidationProvider.java:44)
    at [email protected]//org.keycloak.validation.DefaultClientValidationProvider.validate(DefaultClientValidationProvider.java:37)
    at [email protected]//org.keycloak.validation.ClientValidationUtil.validate(ClientValidationUtil.java:30)
    at [email protected]//org.keycloak.models.utils.RepresentationToModel.createClients(RepresentationToModel.java:1224)
    at [email protected]//org.keycloak.models.utils.RepresentationToModel.importRealm(RepresentationToModel.java:362)
    at [email protected]//org.keycloak.services.managers.RealmManager.importRealm(RealmManager.java:506)

Any pointers are welcome!

like image 299
Runar Halse Avatar asked Feb 10 '20 09:02

Runar Halse


1 Answers

Upgrading to 9.0.0 fixes it for me.

like image 52
Mathieu D Avatar answered Nov 06 '22 13:11

Mathieu D