Skip to content

Commit 5dc0cf2

Browse files
committed
Configure Keycloak with OpenLDAP
1 parent 8c70a96 commit 5dc0cf2

File tree

4 files changed

+280
-28
lines changed

4 files changed

+280
-28
lines changed

keycloak/docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@ services:
1717
ports:
1818
- "5432:5432"
1919

20+
openldap:
21+
image: "bitnami/openldap:2.6"
22+
container_name: openldap
23+
environment:
24+
LDAP_ADMIN_USERNAME: admin
25+
LDAP_ADMIN_PASSWORD: admin
26+
LDAP_ADMIN_DN: cn=admin,dc=example,dc=org
27+
LDAP_ROOT: dc=example,dc=org
28+
healthcheck:
29+
test: [ "CMD-SHELL", "ldapsearch -H ldapi:/// -b dc=example,dc=org cn > /dev/null" ]
30+
interval: 15s
31+
retries: 5
32+
timeout: 5s
33+
ports:
34+
- "1389:1389"
35+
- "1636:1636"
36+
volumes:
37+
- openldap:/bitnami/openldap
38+
- ./openldap:/ldifs
39+
40+
openldap-admin:
41+
image: "osixia/phpldapadmin:0.9.0"
42+
container_name: openldap-admin
43+
ports:
44+
- "8000:80"
45+
healthcheck:
46+
test: "curl --fail http://localhost || exit 1"
47+
interval: 5s
48+
timeout: 3s
49+
retries: 5
50+
volumes:
51+
- ./openldap-admin/.env.yaml:/container/environment/01-custom/env.yaml
52+
depends_on:
53+
openldap:
54+
condition: service_started
55+
2056
keycloak:
2157
image: "bitnami/keycloak:26"
2258
container_name: keycloak
@@ -45,7 +81,10 @@ services:
4581
depends_on:
4682
postgres:
4783
condition: service_healthy
84+
openldap:
85+
condition: service_healthy
4886

4987
volumes:
5088
keycloak:
89+
openldap:
5190
postgres:

keycloak/keycloak/realm.json

Lines changed: 186 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
"composite" : true,
240240
"composites" : {
241241
"client" : {
242-
"realm-management" : [ "query-users", "query-realms", "manage-realm", "manage-users", "manage-identity-providers", "manage-authorization", "view-users", "view-clients", "manage-clients", "query-groups", "view-events", "create-client", "view-identity-providers", "view-authorization", "manage-events", "impersonation", "query-clients", "view-realm" ]
242+
"realm-management" : [ "query-users", "query-realms", "manage-realm", "manage-users", "manage-identity-providers", "manage-authorization", "view-users", "view-clients", "manage-clients", "query-groups", "view-events", "create-client", "manage-events", "view-authorization", "view-identity-providers", "impersonation", "query-clients", "view-realm" ]
243243
}
244244
},
245245
"clientRole" : true,
@@ -378,23 +378,44 @@
378378
"webAuthnPolicyPasswordlessAcceptableAaguids" : [ ],
379379
"webAuthnPolicyPasswordlessExtraOrigins" : [ ],
380380
"users" : [ {
381-
"id" : "08bf372c-4033-4a45-809e-4fcffce47b36",
381+
"id" : "b916f557-09c1-448f-8a9a-8b5a04768817",
382382
"username" : "program",
383-
"firstName" : "Alexey",
383+
"firstName" : "Alex",
384384
"lastName" : "Romanov",
385385
"email" : "program@mail.ru",
386-
"emailVerified" : true,
387-
"createdTimestamp" : 1733751128274,
386+
"emailVerified" : false,
387+
"attributes" : {
388+
"LDAP_ENTRY_DN" : [ "cn=program,ou=users,dc=example,dc=org" ],
389+
"LDAP_ID" : [ "1001" ]
390+
},
391+
"origin" : "1WfrqTJuR9uIQ0vyjwRzKA",
392+
"createdTimestamp" : 1733922080126,
388393
"enabled" : true,
389394
"totp" : false,
390-
"credentials" : [ {
391-
"id" : "2f06e698-eaa7-47a8-a059-d5c2c9810dba",
392-
"type" : "password",
393-
"userLabel" : "My password",
394-
"createdDate" : 1733751138860,
395-
"secretData" : "{\"value\":\"Cfjv7pFPB/L45GjjuFxGhdNKh9ArDq1JCQAl7a+d+Fc=\",\"salt\":\"L+M8zZuovvrpfz4arIZzPA==\",\"additionalParameters\":{}}",
396-
"credentialData" : "{\"hashIterations\":5,\"algorithm\":\"argon2\",\"additionalParameters\":{\"hashLength\":[\"32\"],\"memory\":[\"7168\"],\"type\":[\"id\"],\"version\":[\"1.3\"],\"parallelism\":[\"1\"]}}"
397-
} ],
395+
"federationLink" : "1WfrqTJuR9uIQ0vyjwRzKA",
396+
"credentials" : [ ],
397+
"disableableCredentialTypes" : [ ],
398+
"requiredActions" : [ ],
399+
"realmRoles" : [ "default-roles-todo-list" ],
400+
"notBefore" : 0,
401+
"groups" : [ ]
402+
}, {
403+
"id" : "474d4970-109b-43d3-b732-d19b9327ce78",
404+
"username" : "ronin",
405+
"firstName" : "Alex",
406+
"lastName" : "Romanov",
407+
"email" : "ronin@mail.ru",
408+
"emailVerified" : false,
409+
"attributes" : {
410+
"LDAP_ENTRY_DN" : [ "cn=ronin,ou=users,dc=example,dc=org" ],
411+
"LDAP_ID" : [ "1000" ]
412+
},
413+
"origin" : "1WfrqTJuR9uIQ0vyjwRzKA",
414+
"createdTimestamp" : 1733922080099,
415+
"enabled" : true,
416+
"totp" : false,
417+
"federationLink" : "1WfrqTJuR9uIQ0vyjwRzKA",
418+
"credentials" : [ ],
398419
"disableableCredentialTypes" : [ ],
399420
"requiredActions" : [ ],
400421
"realmRoles" : [ "default-roles-todo-list" ],
@@ -504,7 +525,8 @@
504525
"protocol" : "openid-connect",
505526
"attributes" : {
506527
"realm_client" : "false",
507-
"client.use.lightweight.access.token.enabled" : "true"
528+
"client.use.lightweight.access.token.enabled" : "true",
529+
"post.logout.redirect.uris" : "+"
508530
},
509531
"authenticationFlowBindingOverrides" : { },
510532
"fullScopeAllowed" : true,
@@ -541,6 +563,7 @@
541563
"oidc.ciba.grant.enabled" : "false",
542564
"client.secret.creation.time" : "1733752117",
543565
"backchannel.logout.session.required" : "true",
566+
"post.logout.redirect.uris" : "+",
544567
"display.on.consent.screen" : "false",
545568
"oauth2.device.authorization.grant.enabled" : "false",
546569
"backchannel.logout.revoke.offline.tokens" : "false"
@@ -571,7 +594,8 @@
571594
"frontchannelLogout" : false,
572595
"protocol" : "openid-connect",
573596
"attributes" : {
574-
"realm_client" : "true"
597+
"realm_client" : "true",
598+
"post.logout.redirect.uris" : "+"
575599
},
576600
"authenticationFlowBindingOverrides" : { },
577601
"fullScopeAllowed" : false,
@@ -599,7 +623,8 @@
599623
"frontchannelLogout" : false,
600624
"protocol" : "openid-connect",
601625
"attributes" : {
602-
"realm_client" : "true"
626+
"realm_client" : "true",
627+
"post.logout.redirect.uris" : "+"
603628
},
604629
"authenticationFlowBindingOverrides" : { },
605630
"fullScopeAllowed" : false,
@@ -752,6 +777,7 @@
752777
"config" : {
753778
"introspection.token.claim" : "true",
754779
"multivalued" : "true",
780+
"userinfo.token.claim" : "true",
755781
"user.attribute" : "foo",
756782
"id.token.claim" : "true",
757783
"access.token.claim" : "true",
@@ -801,8 +827,9 @@
801827
"consentRequired" : false,
802828
"config" : {
803829
"user.session.note" : "AUTH_TIME",
804-
"id.token.claim" : "true",
805830
"introspection.token.claim" : "true",
831+
"userinfo.token.claim" : "true",
832+
"id.token.claim" : "true",
806833
"access.token.claim" : "true",
807834
"claim.name" : "auth_time",
808835
"jsonType.label" : "long"
@@ -1074,7 +1101,8 @@
10741101
"config" : {
10751102
"id.token.claim" : "true",
10761103
"introspection.token.claim" : "true",
1077-
"access.token.claim" : "true"
1104+
"access.token.claim" : "true",
1105+
"userinfo.token.claim" : "true"
10781106
}
10791107
} ]
10801108
}, {
@@ -1192,12 +1220,13 @@
11921220
"protocolMapper" : "oidc-organization-membership-mapper",
11931221
"consentRequired" : false,
11941222
"config" : {
1195-
"id.token.claim" : "true",
11961223
"introspection.token.claim" : "true",
1224+
"multivalued" : "true",
1225+
"userinfo.token.claim" : "true",
1226+
"id.token.claim" : "true",
11971227
"access.token.claim" : "true",
11981228
"claim.name" : "organization",
1199-
"jsonType.label" : "String",
1200-
"multivalued" : "true"
1229+
"jsonType.label" : "String"
12011230
}
12021231
} ]
12031232
}, {
@@ -1250,7 +1279,7 @@
12501279
"subType" : "authenticated",
12511280
"subComponents" : { },
12521281
"config" : {
1253-
"allowed-protocol-mapper-types" : [ "saml-user-property-mapper", "oidc-full-name-mapper", "oidc-usermodel-attribute-mapper", "oidc-usermodel-property-mapper", "oidc-sha256-pairwise-sub-mapper", "saml-user-attribute-mapper", "saml-role-list-mapper", "oidc-address-mapper" ]
1282+
"allowed-protocol-mapper-types" : [ "oidc-full-name-mapper", "oidc-usermodel-attribute-mapper", "oidc-address-mapper", "saml-user-attribute-mapper", "saml-role-list-mapper", "saml-user-property-mapper", "oidc-sha256-pairwise-sub-mapper", "oidc-usermodel-property-mapper" ]
12541283
}
12551284
}, {
12561285
"id" : "610a7dee-4d8d-4df0-bd4b-17285d790ef0",
@@ -1294,7 +1323,7 @@
12941323
"subType" : "anonymous",
12951324
"subComponents" : { },
12961325
"config" : {
1297-
"allowed-protocol-mapper-types" : [ "oidc-full-name-mapper", "saml-user-attribute-mapper", "oidc-sha256-pairwise-sub-mapper", "oidc-usermodel-property-mapper", "saml-role-list-mapper", "oidc-address-mapper", "saml-user-property-mapper", "oidc-usermodel-attribute-mapper" ]
1326+
"allowed-protocol-mapper-types" : [ "oidc-usermodel-property-mapper", "oidc-full-name-mapper", "oidc-sha256-pairwise-sub-mapper", "oidc-address-mapper", "saml-role-list-mapper", "saml-user-attribute-mapper", "saml-user-property-mapper", "oidc-usermodel-attribute-mapper" ]
12981327
}
12991328
}, {
13001329
"id" : "e8b90a10-667e-45d4-8e06-488a3dbd7d97",
@@ -1313,6 +1342,130 @@
13131342
"subComponents" : { },
13141343
"config" : { }
13151344
} ],
1345+
"org.keycloak.storage.UserStorageProvider" : [ {
1346+
"id" : "1WfrqTJuR9uIQ0vyjwRzKA",
1347+
"name" : "ldap",
1348+
"providerId" : "ldap",
1349+
"subComponents" : {
1350+
"org.keycloak.storage.ldap.mappers.LDAPStorageMapper" : [ {
1351+
"id" : "e1e84320-fe45-4b80-ad31-b7c599697626",
1352+
"name" : "email",
1353+
"providerId" : "user-attribute-ldap-mapper",
1354+
"subComponents" : { },
1355+
"config" : {
1356+
"ldap.attribute" : [ "mail" ],
1357+
"is.mandatory.in.ldap" : [ "false" ],
1358+
"read.only" : [ "true" ],
1359+
"always.read.value.from.ldap" : [ "false" ],
1360+
"user.model.attribute" : [ "email" ]
1361+
}
1362+
}, {
1363+
"id" : "251c4670-010c-4cf3-9129-0820d8e23712",
1364+
"name" : "first name",
1365+
"providerId" : "user-attribute-ldap-mapper",
1366+
"subComponents" : { },
1367+
"config" : {
1368+
"ldap.attribute" : [ "givenName" ],
1369+
"is.mandatory.in.ldap" : [ "true" ],
1370+
"always.read.value.from.ldap" : [ "true" ],
1371+
"read.only" : [ "true" ],
1372+
"user.model.attribute" : [ "firstName" ]
1373+
}
1374+
}, {
1375+
"id" : "2c9261be-5fe8-4aa5-a42d-1d19287cbfb4",
1376+
"name" : "creation date",
1377+
"providerId" : "user-attribute-ldap-mapper",
1378+
"subComponents" : { },
1379+
"config" : {
1380+
"ldap.attribute" : [ "whenCreated" ],
1381+
"is.mandatory.in.ldap" : [ "false" ],
1382+
"always.read.value.from.ldap" : [ "true" ],
1383+
"read.only" : [ "true" ],
1384+
"user.model.attribute" : [ "createTimestamp" ]
1385+
}
1386+
}, {
1387+
"id" : "29bb279e-33b7-4d4a-969a-b52ed8de55f7",
1388+
"name" : "username",
1389+
"providerId" : "user-attribute-ldap-mapper",
1390+
"subComponents" : { },
1391+
"config" : {
1392+
"ldap.attribute" : [ "cn" ],
1393+
"is.mandatory.in.ldap" : [ "true" ],
1394+
"always.read.value.from.ldap" : [ "false" ],
1395+
"read.only" : [ "true" ],
1396+
"user.model.attribute" : [ "username" ]
1397+
}
1398+
}, {
1399+
"id" : "64028dbf-8137-4cfe-abda-38b751863c91",
1400+
"name" : "Kerberos principal attribute mapper",
1401+
"providerId" : "kerberos-principal-attribute-mapper",
1402+
"subComponents" : { },
1403+
"config" : { }
1404+
}, {
1405+
"id" : "19a68ab4-8215-4d66-a384-c7d7618ac07f",
1406+
"name" : "last name",
1407+
"providerId" : "user-attribute-ldap-mapper",
1408+
"subComponents" : { },
1409+
"config" : {
1410+
"ldap.attribute" : [ "sn" ],
1411+
"is.mandatory.in.ldap" : [ "true" ],
1412+
"read.only" : [ "true" ],
1413+
"always.read.value.from.ldap" : [ "true" ],
1414+
"user.model.attribute" : [ "lastName" ]
1415+
}
1416+
}, {
1417+
"id" : "a17fce5c-1ed5-43e5-8006-52bf47f5eeba",
1418+
"name" : "modify date",
1419+
"providerId" : "user-attribute-ldap-mapper",
1420+
"subComponents" : { },
1421+
"config" : {
1422+
"ldap.attribute" : [ "whenChanged" ],
1423+
"is.mandatory.in.ldap" : [ "false" ],
1424+
"read.only" : [ "true" ],
1425+
"always.read.value.from.ldap" : [ "true" ],
1426+
"user.model.attribute" : [ "modifyTimestamp" ]
1427+
}
1428+
}, {
1429+
"id" : "33d6e815-5892-4daa-a34b-8284f9e37722",
1430+
"name" : "MSAD account controls",
1431+
"providerId" : "msad-user-account-control-mapper",
1432+
"subComponents" : { },
1433+
"config" : {
1434+
"always.read.enabled.value.from.ldap" : [ "true" ]
1435+
}
1436+
} ]
1437+
},
1438+
"config" : {
1439+
"fullSyncPeriod" : [ "-1" ],
1440+
"pagination" : [ "false" ],
1441+
"startTls" : [ "false" ],
1442+
"usersDn" : [ "ou=users,dc=example,dc=org" ],
1443+
"connectionPooling" : [ "false" ],
1444+
"cachePolicy" : [ "DEFAULT" ],
1445+
"useKerberosForPasswordAuthentication" : [ "false" ],
1446+
"importEnabled" : [ "true" ],
1447+
"enabled" : [ "true" ],
1448+
"changedSyncPeriod" : [ "-1" ],
1449+
"bindCredential" : [ "admin" ],
1450+
"bindDn" : [ "cn=admin,dc=example,dc=org" ],
1451+
"usernameLDAPAttribute" : [ "cn" ],
1452+
"vendor" : [ "ad" ],
1453+
"uuidLDAPAttribute" : [ "uidNumber" ],
1454+
"allowKerberosAuthentication" : [ "false" ],
1455+
"connectionUrl" : [ "ldap://openldap:1389" ],
1456+
"syncRegistrations" : [ "true" ],
1457+
"authType" : [ "simple" ],
1458+
"krbPrincipalAttribute" : [ "userPrincipalName" ],
1459+
"searchScope" : [ "1" ],
1460+
"useTruststoreSpi" : [ "always" ],
1461+
"usePasswordModifyExtendedOp" : [ "false" ],
1462+
"trustEmail" : [ "false" ],
1463+
"userObjectClasses" : [ "inetOrgPerson" ],
1464+
"rdnLDAPAttribute" : [ "cn" ],
1465+
"editMode" : [ "READ_ONLY" ],
1466+
"validatePasswordPolicy" : [ "false" ]
1467+
}
1468+
} ],
13161469
"org.keycloak.keys.KeyProvider" : [ {
13171470
"id" : "14afaef2-1bcf-46cc-8836-18dfb4f83f40",
13181471
"name" : "rsa-generated",
@@ -1986,13 +2139,18 @@
19862139
"firstBrokerLoginFlow" : "first broker login",
19872140
"attributes" : {
19882141
"cibaBackchannelTokenDeliveryMode" : "poll",
1989-
"cibaExpiresIn" : "120",
19902142
"cibaAuthRequestedUserHint" : "login_hint",
1991-
"oauth2DeviceCodeLifespan" : "600",
2143+
"clientOfflineSessionMaxLifespan" : "0",
19922144
"oauth2DevicePollingInterval" : "5",
1993-
"parRequestUriLifespan" : "60",
2145+
"clientSessionIdleTimeout" : "0",
2146+
"clientOfflineSessionIdleTimeout" : "0",
19942147
"cibaInterval" : "5",
1995-
"realmReusableOtpCode" : "false"
2148+
"realmReusableOtpCode" : "false",
2149+
"cibaExpiresIn" : "120",
2150+
"oauth2DeviceCodeLifespan" : "600",
2151+
"parRequestUriLifespan" : "60",
2152+
"clientSessionMaxLifespan" : "0",
2153+
"organizationsEnabled" : "false"
19962154
},
19972155
"keycloakVersion" : "26.0.7",
19982156
"userManagedAccessAllowed" : false,
@@ -2003,4 +2161,4 @@
20032161
"clientPolicies" : {
20042162
"policies" : [ ]
20052163
}
2006-
}
2164+
}

keycloak/openldap-admin/.env.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PHPLDAPADMIN_LDAP_HOSTS:
2+
- openldap:
3+
- server:
4+
- port: 1389
5+
- tls: false
6+
- login:
7+
- bind_id: cn=admin,dc=example,dc=org
8+
9+
PHPLDAPADMIN_HTTPS: false
10+
PHPLDAPADMIN_LDAP_CLIENT_TLS: false

0 commit comments

Comments
 (0)