Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keycloak_ldap_user_federation with master realm is not working #694

Closed
spidersouleater opened this issue Jun 1, 2022 · 10 comments · Fixed by #707
Closed

keycloak_ldap_user_federation with master realm is not working #694

spidersouleater opened this issue Jun 1, 2022 · 10 comments · Fixed by #707

Comments

@spidersouleater
Copy link

It's not possible to create a LDAP user federation provider within the Realm "master", anymore.

The problem occurs with the Image "quay.io/keycloak/keycloak:18.0.0-legacy". I'm using the Version 3.8.1 of the terraform-provider-keycloak.

Minimal example to reproduce the Problem:

data "keycloak_realm" "master" {
    realm = "master"
}

resource "keycloak_ldap_user_federation" "ldap_user_federation" {
  name     = "openldap"
  realm_id = data.keycloak_realm.master.id
  enabled  = true

  username_ldap_attribute = "cn"
  rdn_ldap_attribute      = "cn"
  uuid_ldap_attribute     = "entryDN"
  user_object_classes     = [
    "simpleSecurityObject",
    "organizationalRole"
  ]
  connection_url          = "ldap://openldap"
  users_dn                = "dc=example,dc=org"
  bind_dn                 = "cn=admin,dc=example,dc=org"
  bind_credential         = "admin"

  connection_timeout = "5s"
  read_timeout       = "10s"

  kerberos {
    kerberos_realm   = "FOO.LOCAL"
    server_principal = "HTTP/host.foo.com@FOO.LOCAL"
    key_tab          = "/etc/host.keytab"
  }
}
@wann-ap
Copy link

wann-ap commented Jun 1, 2022

+1

@mrparkers
Copy link
Contributor

Hi @spidersouleater, sorry that you're having this issue. I tried the example configuration you provided, and I wasn't able to reproduce the problem. Could you give me some more information so I could investigate this further? Specifically, if you could provide an error message, or provide the output logs after running terraform with the TF_LOG=DEBUG environment variable, that would be very helpful. If you post these logs, make sure to redact them, as they can sometimes contain sensitive information.

@EvgeniyBlinov
Copy link

+1
@spidersouleater Did you found any workaround solution?

@spidersouleater
Copy link
Author

spidersouleater commented Jul 4, 2022

Hi mrparkers, thanks for your help.

When executing the example configuration no error message seems to appear and everything has been configured correctly. But when you take look in the Keycloak Admin Console you can see that "LDAP user federation provide" has not been created.

keycloak-18.0.2-legacy

  • terraform-provider-keycloak 3.9.0

The problem still exists in the recent versions. You can see in the Keycloak Admin Console the missing provider after the Terrafrom execution.

gui-18 0 2-legacy

Here are the logs:

keycloak-17.0.1-legacy

  • terraform-provider-keycloak 3.9.0

This seems to be the last Version where everything is fine. You can see in the Keycloak Admin Console the created Provider after Terraform install.

gui-17 0 1-legacy

Here are the logs:

I could find out that Keycloak-18-legacy use a UUID for the Master-Realm and not anymore the String representation "master". That could maybe cause the problems we have.

@kelimutu
Copy link

kelimutu commented Jul 6, 2022

+1

@spidersouleater
Copy link
Author

spidersouleater commented Jul 7, 2022

I spent little time with the logs and the Keycloak Api. I could find out that the "parentId" of the following request body to the Endpoint "Component - POST - /{realm}/components" cause our problems.

{
    "name": "openldap",
    "providerId": "ldap",
    "providerType": "org.keycloak.storage.UserStorageProvider",
    "parentId": "master",
    "config": {
        "allowKerberosAuthentication": [
            "true"
        ],
        "authType": [
            "simple"
        ],
        "batchSizeForSync": [
            "1000"
        ],
        "bindCredential": [
            "admin"
        ],
        "bindDn": [
            "cn=admin,dc=example,dc=org"
        ],
        "cachePolicy": [
            ""
        ],
        "changedSyncPeriod": [
            "-1"
        ],
        "connectionTimeout": [
            "5000"
        ],
        "connectionUrl": [
            "ldap://openldap"
        ],
        "editMode": [
            "READ_ONLY"
        ],
        "enabled": [
            "true"
        ],
        "evictionDay": [],
        "evictionHour": [],
        "evictionMinute": [],
        "fullSyncPeriod": [
            "-1"
        ],
        "importEnabled": [
            "true"
        ],
        "kerberosRealm": [
            "FOO.LOCAL"
        ],
        "keyTab": [
            "/etc/host.keytab"
        ],
        "maxLifespan": [],
        "pagination": [
            "true"
        ],
        "priority": [
            "0"
        ],
        "rdnLDAPAttribute": [
            "cn"
        ],
        "readTimeout": [
            "10000"
        ],
        "searchScope": [
            "1"
        ],
        "serverPrincipal": [
            "HTTP/host.foo.com@FOO.LOCAL"
        ],
        "startTls": [
            "false"
        ],
        "syncRegistrations": [
            "false"
        ],
        "trustEmail": [
            "false"
        ],
        "useKerberosForPasswordAuthentication": [
            "false"
        ],
        "usePasswordModifyExtendedOp": [
            "false"
        ],
        "useTruststoreSpi": [
            "ldapsOnly"
        ],
        "userObjectClasses": [
            "simpleSecurityObject, organizationalRole"
        ],
        "usernameLDAPAttribute": [
            "cn"
        ],
        "usersDn": [
            "dc=example,dc=org"
        ],
        "uuidLDAPAttribute": [
            "entryDN"
        ],
        "validatePasswordPolicy": [
            "false"
        ],
        "vendor": [
            "other"
        ]
    }

If we set the UUID for the Master Realm or remove the optional field "parentId" than the Keycloak Api creates the "User Federation" again. I hope the information can help to solve the problem faster.

@mrparkers
Copy link
Contributor

Sorry for taking so long on this. The root problem here is that Keycloak 18 changed the internal ID of the default master realm - it used to be master, but now it's a random GUID. So the provider was making assumptions about the internal ID of this realm, which was causing this issue.

I've opened #707 to fix this.

@mrparkers
Copy link
Contributor

This is fixed in v3.9.1

@spidersouleater
Copy link
Author

Hi mrparkes,

i have tested the bugfix version and everything seems fine, now.

Thank you for your help.

@mrparkers
Copy link
Contributor

Of course, thank you for your help with the debugging effort! It saved me a lot of time since I didn't have to do much research to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants