KeycloakRealmImport not visible in console after import

After importing a realm with e.g.

cat <<EOF > /tmp/KeycloakRealmImport.yaml
kind: KeycloakRealmImport
apiVersion: k8s.keycloak.org/v2alpha1
metadata:
  name: saml-basic-auth-import
  labels:
    app: sso
spec:
  keycloakCRName: basic-keycloak
  realm:
    realm: saml-basic-auth
    id: saml-basic-auth
    enabled: true
    users:
      - username: admin
        credentials:
          - type: password
            value: password
        enabled: true
        realmRoles:
          - admin
          - user
      - username: user
        credentials:
          - type: password
            value: user
        enabled: true
        realmRoles:
          - user
      - username: client
        credentials:
          - type: password
            value: creator
        enabled: true
        clientRoles:
          account:
            - "manage-account"
          realm-management:
            - "create-client"
            - "manage-realm"
            - "manage-clients"
EOF

oc apply -f /tmp/KeycloakRealmImport.yaml

I cannot see it in the console (just the master realm is there).

The status tells the import was succesful:

status:
  conditions:
    - message: ''
      status: true
      type: Done
    - message: ''
      status: false
      type: Started
    - message: ''
      status: false
      type: HasErrors

Found the solution myself: you need to use POSGRESQL to persist Keycloak data (or whatever persistence method you wish) in order for the imported data to survive POD restart, which happens every-time after a successful import;

You can find an example here keycloak/operator/src/main/resources at main · keycloak/keycloak · GitHub;

It’s surprising that you have to provision POSGRESQL yourself (the operator won’t do it for you);

1 Like