Skip to content

Commit

Permalink
add custom ldif dir
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandGouny committed Jul 19, 2017
1 parent d11265c commit ad82829
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,28 @@ Do not edit slapd.conf it's not used. To modify your server configuration use ld
#### Seed ldap database with ldif

This image can load ldif files at startup with either `ldapadd` or `ldapmodify`.
Mount `.ldif` in `/container/service/slapd/assets/config/bootstrap/ldif/`
directory. Files containing `changeType:` attributes will be loaded with `ldapmodify`.
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.

The startup script provide some substitution in bootstrap ldif files: `{{
LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
Files containing `changeType:` attributes will be loaded with `ldapmodify`.

The startup script provide some substitution in bootstrap ldif files:
`{{LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
substitution are left as is.

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


docker run \
# single file example:
docker run \
--volume ./bootstrap.ldif:/container/service/slapd/assets/config/bootstrap/ldif/50-bootstrap.ldif \
osixia/openldap:1.1.9 --copy-service

#directory example:
docker run \
--volume ./lidf:/container/service/slapd/assets/config/bootstrap/ldif/custom \
osixia/openldap:1.1.9 --copy-service

### Use an existing ldap database

This can be achieved by mounting host directories as volume.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Add your custom ldif files here if you don't want to overwrite image default boostrap ldif.
at run time you can also mount a data volume with your ldif files to /container/service/slapd/assets/config/bootstrap/ldif/custom

The startup script provide some substitution in bootstrap ldif files:
`{{LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported.
Other `{{ * }}` substitution are left as is.

Since startup script modifies `ldif` files,
you **must** add `--copy-service` argument to entrypoint if you don't want to overwrite them.
27 changes: 19 additions & 8 deletions image/service/slapd/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ if [ ! -e "$FIRST_START_DONE" ]; then
fi
}

function ldap_add_or_modify (){
local LDIF_FILE=$1
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $LDIF_FILE
sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $LDIF_FILE
if grep -iq changetype $LDIF_FILE ; then
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
else
ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $LDIF_FILE |& log-helper debug
fi
}

#
# Global variables
#
Expand Down Expand Up @@ -224,16 +235,16 @@ EOF
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/02-security.ldif

# process config files (*.ldif) in bootstrap directory (do no process files in subdirectories)
log-helper info "Add bootstrap ldif..."
log-helper info "Add image bootstrap ldif..."
for f in $(find ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif -mindepth 1 -maxdepth 1 -type f -name \*.ldif | sort); do
log-helper debug "Processing file ${f}"
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $f
sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $f
if grep -iq changetype $f ; then
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
else
ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $f |& log-helper debug
fi
ldap_add_or_modify "$f"
done

log-helper info "Add custom bootstrap ldif..."
for f in $(find ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/custom -type f -name \*.ldif | sort); do
log-helper debug "Processing file ${f}"
ldap_add_or_modify "$f"
done

# read only user
Expand Down

0 comments on commit ad82829

Please sign in to comment.