Skip to content

Commit ad82829

Browse files
committed
add custom ldif dir
1 parent d11265c commit ad82829

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,28 @@ Do not edit slapd.conf it's not used. To modify your server configuration use ld
107107
#### Seed ldap database with ldif
108108

109109
This image can load ldif files at startup with either `ldapadd` or `ldapmodify`.
110-
Mount `.ldif` in `/container/service/slapd/assets/config/bootstrap/ldif/`
111-
directory. Files containing `changeType:` attributes will be loaded with `ldapmodify`.
110+
Mount `.ldif` in `/container/service/slapd/assets/config/bootstrap/ldif` directory if you want to overwrite image default boostrap ldif files or in `/container/service/slapd/assets/config/bootstrap/ldif/custom` (recommended) to extend image config.
112111

113-
The startup script provide some substitution in bootstrap ldif files: `{{
114-
LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
112+
Files containing `changeType:` attributes will be loaded with `ldapmodify`.
113+
114+
The startup script provide some substitution in bootstrap ldif files:
115+
`{{LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
115116
substitution are left as is.
116117

117118
Since startup script modifies `ldif` files, you **must** add `--copy-service`
118-
argument to entrypoint.
119+
argument to entrypoint if you don't want to overwrite them.
120+
119121

120-
docker run \
122+
# single file example:
123+
docker run \
121124
--volume ./bootstrap.ldif:/container/service/slapd/assets/config/bootstrap/ldif/50-bootstrap.ldif \
122125
osixia/openldap:1.1.9 --copy-service
123126

127+
#directory example:
128+
docker run \
129+
--volume ./lidf:/container/service/slapd/assets/config/bootstrap/ldif/custom \
130+
osixia/openldap:1.1.9 --copy-service
131+
124132
### Use an existing ldap database
125133

126134
This can be achieved by mounting host directories as volume.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Add your custom ldif files here if you don't want to overwrite image default boostrap ldif.
2+
at run time you can also mount a data volume with your ldif files to /container/service/slapd/assets/config/bootstrap/ldif/custom
3+
4+
The startup script provide some substitution in bootstrap ldif files:
5+
`{{LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported.
6+
Other `{{ * }}` substitution are left as is.
7+
8+
Since startup script modifies `ldif` files,
9+
you **must** add `--copy-service` argument to entrypoint if you don't want to overwrite them.

image/service/slapd/startup.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ if [ ! -e "$FIRST_START_DONE" ]; then
6262
fi
6363
}
6464

65+
function ldap_add_or_modify (){
66+
local LDIF_FILE=$1
67+
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $LDIF_FILE
68+
sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $LDIF_FILE
69+
if grep -iq changetype $LDIF_FILE ; then
70+
ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $LDIF_FILE 2>&1 | log-helper debug || ldapmodify -h localhost -p 389 -D cn=admin,$LDAP_BASE_DN -w $LDAP_ADMIN_PASSWORD -f $LDIF_FILE 2>&1 | log-helper debug
71+
else
72+
ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $LDIF_FILE |& log-helper debug
73+
fi
74+
}
75+
6576
#
6677
# Global variables
6778
#
@@ -224,16 +235,16 @@ EOF
224235
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/02-security.ldif
225236

226237
# process config files (*.ldif) in bootstrap directory (do no process files in subdirectories)
227-
log-helper info "Add bootstrap ldif..."
238+
log-helper info "Add image bootstrap ldif..."
228239
for f in $(find ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif -mindepth 1 -maxdepth 1 -type f -name \*.ldif | sort); do
229240
log-helper debug "Processing file ${f}"
230-
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $f
231-
sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $f
232-
if grep -iq changetype $f ; then
233-
ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $f 2>&1 | log-helper debug || ldapmodify -h localhost -p 389 -D cn=admin,$LDAP_BASE_DN -w $LDAP_ADMIN_PASSWORD -f $f 2>&1 | log-helper debug
234-
else
235-
ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $f |& log-helper debug
236-
fi
241+
ldap_add_or_modify "$f"
242+
done
243+
244+
log-helper info "Add custom bootstrap ldif..."
245+
for f in $(find ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/custom -type f -name \*.ldif | sort); do
246+
log-helper debug "Processing file ${f}"
247+
ldap_add_or_modify "$f"
237248
done
238249

239250
# read only user

0 commit comments

Comments
 (0)