Skip to content

Commit 54818cc

Browse files
committed
release
1 parent 73a2bba commit 54818cc

File tree

6 files changed

+188
-0
lines changed

6 files changed

+188
-0
lines changed

Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM osixia/baseimage:0.6.0
2+
MAINTAINER Bertrand Gouny <[email protected]>
3+
4+
# From Nick Stenning's work
5+
# https://github.com/nickstenning/docker-slapd
6+
7+
# Default configuration: can be overridden at the docker command line
8+
ENV LDAP_ADMIN_PWD toor
9+
ENV LDAP_ORGANISATION Example Inc.
10+
ENV LDAP_DOMAIN example.com
11+
12+
# /!\ To store the data outside the container,
13+
# mount /var/lib/ldap and /etc/ldap/slapd.d as a data volume add
14+
# -v /some/host/directory:/var/lib/ldap and -v /some/other/host/directory:/etc/ldap/slapd.d
15+
# to the run command
16+
17+
# Disable SSH
18+
# RUN rm -rf /etc/service/sshd /etc/my_init.d/00_regen_ssh_host_keys.sh
19+
20+
# Enable dnsmasq
21+
RUN /sbin/enable-service dnsmasq
22+
23+
# Use baseimage-docker's init system.
24+
CMD ["/sbin/my_init"]
25+
26+
# Resynchronize the package index files from their sources
27+
RUN apt-get -y update
28+
29+
# Install openldap (slapd) and ldap-utils
30+
RUN LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends slapd ldap-utils openssl
31+
32+
# Expose ldap default port
33+
EXPOSE 389
34+
35+
# Create TLS certificats directory
36+
RUN mkdir /etc/ldap/ssl
37+
38+
# Add config directory
39+
RUN mkdir /etc/ldap/config
40+
ADD service/slapd/config /etc/ldap/config
41+
42+
# Add slapd deamon
43+
RUN mkdir /etc/service/slapd
44+
ADD service/slapd/slapd.sh /etc/service/slapd/run
45+
46+
# Clear out the local repository of retrieved package files
47+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

service/slapd/config/auto/tls.ldif

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
dn: cn=config
2+
changetype: modify
3+
replace: olcTLSCACertificateFile
4+
olcTLSCACertificateFile: /etc/ldap/ssl/ca.crt
5+
-
6+
replace: olcTLSCertificateFile
7+
olcTLSCertificateFile: /etc/ldap/ssl/ldap.crt
8+
-
9+
replace: olcTLSCertificateKeyFile
10+
olcTLSCertificateKeyFile: /etc/ldap/ssl/ldap.key
11+
-
12+
replace: olcTLSDHParamFile
13+
olcTLSDHParamFile: /etc/ldap/ssl/dhparam.pem
14+
-
15+
replace: olcTLSVerifyClient
16+
olcTLSVerifyClient: never
17+

service/slapd/config/logging.ldif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dn: cn=config
2+
changetype: modify
3+
replace: olcLogLevel
4+
olcLogLevel: stats

service/slapd/slapd.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
status () {
6+
echo "---> ${@}" >&2
7+
}
8+
9+
10+
set -x
11+
: LDAP_ADMIN_PWD=${LDAP_ADMIN_PWD}
12+
: LDAP_DOMAIN=${LDAP_DOMAIN}
13+
: LDAP_ORGANISATION=${LDAP_ORGANISATION}
14+
15+
16+
############ Base config ############
17+
if [ ! -e /var/lib/ldap/docker_bootstrapped ]; then
18+
status "configuring slapd database"
19+
20+
cat <<EOF | debconf-set-selections
21+
slapd slapd/internal/generated_adminpw password ${LDAP_ADMIN_PWD}
22+
slapd slapd/internal/adminpw password ${LDAP_ADMIN_PWD}
23+
slapd slapd/password2 password ${LDAP_ADMIN_PWD}
24+
slapd slapd/password1 password ${LDAP_ADMIN_PWD}
25+
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
26+
slapd slapd/domain string ${LDAP_DOMAIN}
27+
slapd shared/organization string ${LDAP_ORGANISATION}
28+
slapd slapd/backend string HDB
29+
slapd slapd/purge_database boolean true
30+
slapd slapd/move_old_database boolean true
31+
slapd slapd/allow_ldap_v2 boolean false
32+
slapd slapd/no_configuration boolean false
33+
slapd slapd/dump_database select when needed
34+
EOF
35+
36+
dpkg-reconfigure -f noninteractive slapd
37+
38+
touch /var/lib/ldap/docker_bootstrapped
39+
40+
else
41+
status "slapd database found"
42+
fi
43+
44+
45+
############ Custom config ############
46+
if [ ! -e /etc/ldap/config/docker_bootstrapped ]; then
47+
status "Custom config"
48+
49+
slapd -h "ldapi:///" -u openldap -g openldap
50+
chown -R openldap:openldap /etc/ldap
51+
52+
# TLS
53+
if [ -e /etc/ldap/ssl/ldap.crt ] && [ -e /etc/ldap/ssl/ldap.key ] && [ -e /etc/ldap/ssl/ca.crt ]; then
54+
status "certificates found"
55+
56+
chmod 600 /etc/ldap/ssl/ldap.key
57+
58+
# create DHParamFile if not found
59+
[ -f /etc/ldap/ssl/dhparam.pem ] || openssl dhparam -out /etc/ldap/ssl/dhparam.pem 2048
60+
61+
ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/ldap/config/auto/tls.ldif -Q
62+
63+
# add fake dnsmasq route to certificate cn
64+
cn=$(openssl x509 -in /etc/ldap/ssl/ldap.crt -subject -noout | sed -n 's/.*CN=\(.*\)\/*\(.*\)/\1/p')
65+
echo "127.0.0.1 " $cn >> /etc/dhosts
66+
67+
fi
68+
69+
# Replication
70+
# todo :)
71+
72+
# Other config files
73+
for f in $(find /etc/ldap/config -maxdepth 1 -name \*.ldif -type f); do
74+
status "Processing file ${f}"
75+
ldapmodify -Y EXTERNAL -H ldapi:/// -f $f -Q
76+
done
77+
78+
kill -INT `cat /run/slapd/slapd.pid`
79+
80+
touch /etc/ldap/config/docker_bootstrapped
81+
82+
else
83+
status "found already-configured slapd"
84+
fi
85+
86+
status "starting slapd on default port 389"
87+
set -x
88+
89+
exec /usr/sbin/slapd -h "ldap:///" -u openldap -g openldap -d -1

test-repository.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# Usage
4+
# sudo ./test.sh
5+
# add -v for verbose mode (or type whatever you like !) :p
6+
7+
. test/config-repository
8+
. test/tools/run.sh
9+
10+
run_test simple.sh "dn: dc=example,dc=com"
11+
run_test tls.sh "dn: dc=example,dc=com"
12+
run_test db.sh "dn: dc=otherdomain,dc=com"
13+
14+
. test/tools/end.sh
15+

test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
# Usage
4+
# sudo ./test.sh
5+
# add -v for verbose mode (or type whatever you like !) :p
6+
7+
. test/config
8+
. test/tools/run.sh
9+
10+
run_test tools/build-container.sh "Successfully built"
11+
run_test simple.sh "dn: dc=example,dc=com"
12+
run_test tls.sh "dn: dc=example,dc=com"
13+
run_test db.sh "dn: dc=otherdomain,dc=com"
14+
15+
. test/tools/end.sh
16+

0 commit comments

Comments
 (0)