Skip to content

Commit 1fe0ba0

Browse files
committed
fix: using LDAP_INIT_ORG_DN without o attribute prevents initialization
1 parent 92b4ac8 commit 1fe0ba0

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ are only evaluated on the **first** container launch. Changing their values late
3939
To customize the **initial** configuration you can set the following environment variables:
4040

4141
```sh
42-
LDAP_INIT_ORG_DN='dc=example,dc=com'
42+
LDAP_INIT_ORG_DN='DC=example,DC=com'
4343
LDAP_INIT_ORG_NAME='Example Corporation'
44+
LDAP_INIT_ORG_ATTR_O='' # optional, if not defined will be derived from LDAP_INIT_ORG_DN, e.g. DC=example,DC=com -> example.com
4445
LDAP_INIT_ADMIN_GROUP_DN='cn=ldap-admins,ou=Groups,${LDAP_INIT_ORG_DN}'
4546
LDAP_INIT_PASSWORD_RESET_GROUP_DN='cn=ldap-password-reset,ou=Groups,${LDAP_INIT_ORG_DN}' # users in this group can set password/sshPublicKey attribute of other users
4647
LDAP_INIT_ROOT_USER_DN='uid=admin,${LDAP_INIT_ORG_DN}'
@@ -55,9 +56,9 @@ Environment variables can for example be set in one of the following ways:
5556

5657
```sh
5758
docker run -itd \
58-
-e LDAP_INIT_ORG_DN='o=yourorg' \
59+
-e LDAP_INIT_ORG_DN='DC=example,DC=com' \
5960
-e LDAP_INIT_ROOT_USER_PW='newpassword' \
60-
-e LDAP_INIT_ORG_NAME='Company Inc' \
61+
-e LDAP_INIT_ORG_NAME='Example Corporation' \
6162
-e LDAP_INIT_PPOLICY_PW_MIN_LENGTH='12' \
6263
-v /my_data/ldap/var/:/var/lib/ldap/ \
6364
-v /my_data/ldap/etc/:/etc/ldap/slapd.d/ \
@@ -76,9 +77,9 @@ Environment variables can for example be set in one of the following ways:
7677

7778
```sh
7879
# /path/on/docker/host/my_init.sh
79-
LDAP_INIT_ORG_DN='o=yourorg'
80+
LDAP_INIT_ORG_DN='DC=example,DC=com'
8081
LDAP_INIT_ROOT_USER_PW='newpassword'
81-
LDAP_INIT_ORG_NAME='Company Inc'
82+
LDAP_INIT_ORG_NAME='Example Corporation'
8283
LDAP_INIT_PPOLICY_PW_MIN_LENGTH='12'
8384
```
8485

example/docker-compose/docker-compose.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
# https://github.com/vegardit/docker-openldap
1313
image: vegardit/openldap:latest # https://hub.docker.com/r/vegardit/openldap
1414
environment:
15-
LDAP_INIT_ORG_DN: o=example.com
15+
LDAP_INIT_ORG_DN: DC=example,DC=com
1616
LDAP_INIT_ORG_NAME: Example Inc.
1717
LDAP_INIT_ROOT_USER_PW: CHANGE@it
1818
LDAP_BACKUP_TIME: # disable backup by setting to empty string
@@ -32,7 +32,7 @@ services:
3232
###############################
3333
# PHP LDAP Admin (Port 8080)
3434
###############################
35-
PHPLDAPADMIN_LDAP_BASE: o=example.com
35+
PHPLDAPADMIN_LDAP_BASE: DC=example,DC=com
3636
PHPLDAPADMIN_LDAP_CLIENT_TLS: 'false'
3737
PHPLDAPADMIN_LDAP_HOSTS: ldap_service
3838
###############################
@@ -41,8 +41,8 @@ services:
4141
DEBUG_MODE: 'false'
4242
#LDAP connection https://ltb-project.org/documentation/self-service-password/1.3/config_ldap
4343
LDAP_URL: ldap://ldap_service
44-
LDAP_BASE_DN: ou=Users,o=example.com
45-
LDAP_USER_DN: uid=self-service-password,ou=TechnicalAccounts,ou=Users,o=example.com
44+
LDAP_BASE_DN: ou=Users,DC=example,DC=com
45+
LDAP_USER_DN: uid=self-service-password,ou=TechnicalAccounts,ou=Users,DC=example,DC=com
4646
LDAP_USER_PASSWORD: CHANGE@it
4747
LDAP_FILTER: '(\&(objectClass=inetOrgPerson)(uid={login}))' # backslash is mandatory!
4848
LDAP_LOGIN_ATTRIBUTE: 'uid'

example/docker-compose/ldifs/init_org_tree.ldif

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dn: ${LDAP_INIT_ORG_DN}
77
description: ${LDAP_INIT_ORG_NAME}
88
objectClass: top
99
objectClass: organization
10-
${LDAP_INIT_ORG_DN_ATTR}
10+
o: ${LDAP_INIT_ORG_ATTR_O}
1111

1212
dn: ou=Groups,${LDAP_INIT_ORG_DN}
1313
ou: Groups

example/docker/example.env

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
#INIT_SH_FILE=
44

5-
LDAP_INIT_ORG_DN=o=yourorg
5+
LDAP_INIT_ORG_DN=DC=example,DC=com
66
LDAP_INIT_ORG_NAME=Example Inc
7-
#LDAP_INIT_ADMIN_GROUP_DN=cn=ldap-admins,ou=Groups,o=yourorg
8-
#LDAP_INIT_ROOT_USER_DN=uid=admin,o=yourorg
7+
#LDAP_INIT_ADMIN_GROUP_DN=cn=ldap-admins,ou=Groups,DC=example,DC=com
8+
#LDAP_INIT_ROOT_USER_DN=uid=admin,DC=example,DC=com
99
LDAP_INIT_ROOT_USER_PW=password
1010

11-
#LDAP_INIT_PPOLICY_DEFAULT_DN=cn=DefaultPasswordPolicy,ou=Policies,o=yourorg
11+
#LDAP_INIT_PPOLICY_DEFAULT_DN=cn=DefaultPasswordPolicy,ou=Policies,DC=example,DC=com
1212
LDAP_INIT_PPOLICY_PW_MIN_LENGTH=8
1313
#LDAP_INIT_PPOLICY_MAX_FAILURES=3
1414
#LDAP_INIT_PPOLICY_LOCKOUT_DURATION=300

image/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ LABEL \
101101
ENV \
102102
INIT_SH_FILE='' \
103103
#
104-
LDAP_INIT_ORG_DN='o=example.com' \
104+
LDAP_INIT_ORG_DN='DC=example,DC=com' \
105105
LDAP_INIT_ORG_NAME='Example Corporation' \
106+
LDAP_INIT_ORG_ATTR_O='' \
106107
LDAP_INIT_ADMIN_GROUP_DN='cn=ldap-admins,ou=Groups,${LDAP_INIT_ORG_DN}' \
107108
LDAP_INIT_PASSWORD_RESET_GROUP_DN='cn=ldap-password-reset,ou=Groups,${LDAP_INIT_ORG_DN}' \
108109
LDAP_INIT_ROOT_USER_DN='uid=admin,${LDAP_INIT_ORG_DN}' \

image/run.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,21 @@ if [ ! -e /etc/ldap/slapd.d/initialized ]; then
160160
ldif modify -Y EXTERNAL /opt/ldifs/init_config_admin_access.ldif
161161
fi
162162

163-
LDAP_INIT_ORG_DN_ATTR=$(substr_before $LDAP_INIT_ORG_DN "," | str_replace "=" ": ") # referenced by init_org_tree.ldif
163+
if [[ -z ${LDAP_INIT_ORG_ATTR_O:-} ]]; then
164+
# derive LDAP_INIT_ORG_ATTR_O (referenced by init_org_tree.ldif) from LDAP_INIT_ORG_DN
165+
if [[ "$LDAP_INIT_ORG_DN" =~ [oO]=([^,]*) ]]; then # check if "o=..." attribute is present in DN
166+
# e.g. LDAP_INIT_ORG_DN="O=example.com" -> LDAP_INIT_ORG_ATTR_O="example.com"
167+
# e.g. LDAP_INIT_ORG_DN="O=Example,DC=example,DC=com" -> LDAP_INIT_ORG_ATTR_O="Example"
168+
LDAP_INIT_ORG_DN_ATTR=${BASH_REMATCH[1]}
169+
elif [[ "${LDAP_INIT_ORG_DN}" =~ [dD][cC]= ]]; then
170+
# e.g. LDAP_INIT_ORG_DN="DC=example,DC=com" -> LDAP_INIT_ORG_ATTR_O="example.com"
171+
LDAP_INIT_ORG_DN_ATTR=$(echo $LDAP_INIT_ORG_DN | grep -ioP 'DC=\K[^,]+' | paste -sd '.')
172+
else
173+
log ERROR "Unable to derive required 'o' attribute of objectClass 'organization' from LDAP_INIT_ORG_DN='$LDAP_INIT_ORG_DN'"
174+
exit 1
175+
fi
176+
fi
177+
164178
ldif add -x -D "$LDAP_INIT_ROOT_USER_DN" -w "$LDAP_INIT_ROOT_USER_PW" /opt/ldifs/init_org_tree.ldif
165179
ldif add -x -D "$LDAP_INIT_ROOT_USER_DN" -w "$LDAP_INIT_ROOT_USER_PW" /opt/ldifs/init_org_ppolicy.ldif
166180
ldif add -x -D "$LDAP_INIT_ROOT_USER_DN" -w "$LDAP_INIT_ROOT_USER_PW" /opt/ldifs/init_org_entries.ldif

0 commit comments

Comments
 (0)