|
@@ -2,6 +2,10 @@
|
|
|
|
|
|
FIRST_START_DONE="/etc/docker-openldap-first-start-done"
|
|
|
|
|
|
+#fix file permissions
|
|
|
+chown -R openldap:openldap /var/lib/ldap
|
|
|
+chown -R openldap:openldap /etc/ldap
|
|
|
+
|
|
|
# container first start
|
|
|
if [ ! -e "$FIRST_START_DONE" ]; then
|
|
|
|
|
@@ -27,9 +31,6 @@ EOF
|
|
|
dpkg-reconfigure -f noninteractive slapd
|
|
|
fi
|
|
|
|
|
|
- #fix file permissions
|
|
|
- chown -R openldap:openldap /var/lib/ldap
|
|
|
- chown -R openldap:openldap /etc/ldap
|
|
|
|
|
|
# start OpenLDAP
|
|
|
slapd -h "ldapi:///" -u openldap -g openldap
|
|
@@ -38,130 +39,40 @@ EOF
|
|
|
if [ "${USE_TLS,,}" == "true" ]; then
|
|
|
|
|
|
# check certificat and key or create it
|
|
|
- /sbin/ssl-kit "/osixia/slapd/$SSL_CRT_FILENAME" "/osixia/slapd/$SSL_KEY_FILENAME" --ca-crt=/osixia/slapd/$SSL_CA_CRT_FILENAME --gnutls
|
|
|
- chown openldap:openldap -R /osixia/slapd
|
|
|
-
|
|
|
-
|
|
|
- fi
|
|
|
-
|
|
|
- # stop OpenLDAP
|
|
|
- kill -INT `cat /run/slapd/slapd.pid`
|
|
|
-
|
|
|
- touch $FIRST_START_DONE
|
|
|
-fi
|
|
|
-
|
|
|
-exit 0
|
|
|
-
|
|
|
-
|
|
|
+ /sbin/ssl-kit "/osixia/slapd/ssl/$SSL_CRT_FILENAME" "/osixia/slapd/ssl/$SSL_KEY_FILENAME" --ca-crt=/osixia/slapd/ssl/$SSL_CA_CRT_FILENAME --gnutls
|
|
|
|
|
|
+ # create DHParamFile if not found
|
|
|
+ [ -f /osixia/slapd/ssl/dhparam.pem ] || openssl dhparam -out /osixia/slapd/ssl/dhparam.pem 2048
|
|
|
|
|
|
-#!/bin/sh
|
|
|
+ # adapt tls ldif
|
|
|
+ sed -i "s,/osixia/slapd/ssl/ca.crt,/osixia/slapd/ssl/${SSL_CA_CRT_FILENAME},g" /osixia/slapd/tls.ldif
|
|
|
+ sed -i "s,/osixia/slapd/ssl/ldap.crt,/osixia/slapd/ssl/${SSL_CRT_FILENAME},g" /osixia/slapd/tls.ldif
|
|
|
+ sed -i "s,/osixia/slapd/ssl/ldap.key,/osixia/slapd/ssl/${SSL_KEY_FILENAME},g" /osixia/slapd/tls.ldif
|
|
|
|
|
|
-set -eu
|
|
|
-
|
|
|
-status () {
|
|
|
- echo "---> ${@}" >&2
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-set -x
|
|
|
-: LDAP_ADMIN_PWD=${LDAP_ADMIN_PWD}
|
|
|
-: LDAP_DOMAIN=${LDAP_DOMAIN}
|
|
|
-: LDAP_ORGANISATION=${LDAP_ORGANISATION}
|
|
|
-: DOMAIN_NAME=${DOMAIN_NAME}
|
|
|
-
|
|
|
-
|
|
|
-############ Base config ############
|
|
|
-if [ ! -e /var/lib/ldap/docker_bootstrapped ]; then
|
|
|
- status "configuring slapd database"
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- touch /var/lib/ldap/docker_bootstrapped
|
|
|
-
|
|
|
-else
|
|
|
- status "slapd database found"
|
|
|
-fi
|
|
|
+ # set tls config
|
|
|
+ ldapmodify -Y EXTERNAL -H ldapi:/// -f /osixia/slapd/tls.ldif -Q
|
|
|
|
|
|
+ # add localhost route to certificate cn (need docker 1.5.0)
|
|
|
+ cn=$(openssl x509 -in /osixia/slapd/ssl/$SSL_CRT_FILENAME -subject -noout | sed -n 's/.*CN=\(.*\)\/*\(.*\)/\1/p')
|
|
|
+ echo "127.0.0.1 $cn" >> /etc/hosts
|
|
|
|
|
|
-############ Custom config ############
|
|
|
-if [ ! -e /etc/ldap/slapd.d/docker_bootstrapped ]; then
|
|
|
- status "Custom config"
|
|
|
-
|
|
|
- slapd -h "ldapi:///" -u openldap -g openldap
|
|
|
- chown -R openldap:openldap /etc/ldap
|
|
|
-
|
|
|
- if [ "$WITH_MMC_AGENT" = true ]; then
|
|
|
-
|
|
|
- # Convert needed mmc ldap schema to ldif
|
|
|
- mkdir -p /etc/ldap/schema/converted
|
|
|
- slaptest -f /etc/mmc/agent/assets/convert_to_ldif -F /etc/ldap/schema/converted
|
|
|
-
|
|
|
- sed -i -e 's/^dn:.*$/dn: cn=mmc,cn=schema,cn=config/; s/^cn:.*$/cn: mmc/; /^structuralObjectClass:.*$/d; /^entryUUID:.*$/d; /^creatorsName:.*$/d; /^createTimestamp:.*$/d; /^entryCSN:.*$/d; /^modifiersName:.*$/d; /^modifyTimestamp:.*$/d' /etc/ldap/schema/converted/cn\=config/cn\=schema/cn=\{4\}mmc.ldif
|
|
|
-
|
|
|
- sed -i -e 's/^dn:.*$/dn: cn=mail,cn=schema,cn=config/; s/^cn:.*$/cn: mail/; /^structuralObjectClass:.*$/d; /^entryUUID:.*$/d; /^creatorsName:.*$/d; /^createTimestamp:.*$/d; /^entryCSN:.*$/d; /^modifiersName:.*$/d; /^modifyTimestamp:.*$/d' /etc/ldap/schema/converted/cn\=config/cn\=schema/cn=\{5\}mail.ldif
|
|
|
-
|
|
|
- ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/converted/cn\=config/cn\=schema/cn=\{4\}mmc.ldif -Q
|
|
|
- ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/converted/cn\=config/cn\=schema/cn=\{5\}mail.ldif -Q
|
|
|
-
|
|
|
- fi
|
|
|
-
|
|
|
- # TLS
|
|
|
- if [ -e /etc/ldap/ssl/ldap.crt ] && [ -e /etc/ldap/ssl/ldap.key ] && [ -e /etc/ldap/ssl/ca.crt ]; then
|
|
|
- status "certificates found"
|
|
|
-
|
|
|
- else
|
|
|
-
|
|
|
- # generate default tls certificate
|
|
|
- export SSL_SLAPD_COMMON_NAME="$DOMAIN_NAME"
|
|
|
- export SSL_SLAPD_ORGANIZATION="${LDAP_ORGANISATION}"
|
|
|
-
|
|
|
- /sbin/ssl-gnutls-create-signed-cert slapd /etc/ldap/ssl/ldap.crt /etc/ldap/ssl/ldap.key
|
|
|
- ln -s /etc/ssl/certs/docker_baseimage_gnutls_cacert.pem /etc/ldap/ssl/ca.crt
|
|
|
-
|
|
|
+ # local ldap tls client config
|
|
|
+ sed -i "s,TLS_CACERT.*,TLS_CACERT /osixia/slapd/ssl/${SSL_CA_CRT_FILENAME},g" /etc/ldap/ldap.conf
|
|
|
fi
|
|
|
|
|
|
- # Fix permission on certificates
|
|
|
- chown openldap:openldap -R /etc/ldap/ssl
|
|
|
- chmod 600 /etc/ldap/ssl/ldap.key
|
|
|
-
|
|
|
- # ldap client config
|
|
|
- sed -i 's,TLS_CACERT.*,TLS_CACERT /etc/ldap/ssl/ca.crt,g' /etc/ldap/ldap.conf
|
|
|
-
|
|
|
- # create DHParamFile if not found
|
|
|
- [ -f /etc/ldap/ssl/dhparam.pem ] || openssl dhparam -out /etc/ldap/ssl/dhparam.pem 2048
|
|
|
-
|
|
|
- ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/ldap/config/modify/auto/tls.ldif -Q
|
|
|
-
|
|
|
- # add fake dnsmasq route to certificate cn
|
|
|
- cn=$(openssl x509 -in /etc/ldap/ssl/ldap.crt -subject -noout | sed -n 's/.*CN=\(.*\)\/*\(.*\)/\1/p')
|
|
|
- /sbin/dns-add-host 127.0.0.1 $cn
|
|
|
-
|
|
|
- # Replication
|
|
|
- # todo :)
|
|
|
-
|
|
|
- # Add config
|
|
|
- for f in $(find /etc/ldap/config/add -maxdepth 1 -name \*.ldif -type f); do
|
|
|
+ # OpenLDAP config
|
|
|
+ for f in $(find /osixia/slapd/config -name \*.ldif -type f); do
|
|
|
status "Processing file ${f}"
|
|
|
- ldapadd -Y EXTERNAL -H ldapi:/// -f $f -Q
|
|
|
- done
|
|
|
-
|
|
|
- # Modify config
|
|
|
- for f in $(find /etc/ldap/config/modify -maxdepth 1 -name \*.ldif -type f); do
|
|
|
- status "Processing file ${f}"
|
|
|
- ldapmodify -Y EXTERNAL -H ldapi:/// -f $f -Q
|
|
|
+ ldapmodify -r -Y EXTERNAL -H ldapi:/// -f $f -Q
|
|
|
done
|
|
|
|
|
|
+ # stop OpenLDAP
|
|
|
kill -INT `cat /run/slapd/slapd.pid`
|
|
|
|
|
|
- touch /etc/ldap/slapd.d/docker_bootstrapped
|
|
|
-
|
|
|
-else
|
|
|
- status "found already-configured slapd"
|
|
|
+ touch $FIRST_START_DONE
|
|
|
fi
|
|
|
|
|
|
-status "starting slapd on default port 389"
|
|
|
-set -x
|
|
|
+# fix file permissions
|
|
|
+chown openldap:openldap -R /osixia/slapd
|
|
|
|
|
|
+exit 0
|