Skip to content

Commit af8016c

Browse files
committed
first commit.
0 parents  commit af8016c

10 files changed

+239
-0
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git
2+
.gitignore
3+
README.md

.gitignore

Whitespace-only changes.

Dockerfile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM debian:7
2+
MAINTAINER Rafael Römhild <[email protected]>
3+
4+
ENV LDAP_DOMAIN planetexpress.com
5+
ENV LDAP_ADMIN_SECRET GoodNewsEveryone
6+
ENV LDAP_ORGANISATION Planet Express, Inc.
7+
ENV DEBIAN_FRONTEND noninteractive
8+
9+
# Install slapd and requirements
10+
RUN apt-get update \
11+
&& apt-get -y --no-install-recommends install \
12+
slapd \
13+
ldap-utils \
14+
openssl \
15+
ca-certificates \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Create TLS certificate and bootstrap directory
19+
RUN mkdir /etc/ldap/ssl /bootstrap
20+
21+
# ADD run script
22+
COPY ./run.sh /run.sh
23+
24+
# ADD bootstrap files
25+
ADD ./bootstrap /bootstrap
26+
27+
# Initialize LDAP with data
28+
RUN /bin/bash /bootstrap/slapd-init.sh
29+
30+
VOLUME ["/etc/ldap/slapd.d", "/etc/ldap/ssl", "/var/lib/ldap", "/run/slapd"]
31+
32+
EXPOSE 389
33+
34+
CMD []
35+
ENTRYPOINT ["/bin/bash", "/run.sh"]
36+

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# OpenLDAP Docker Image for testing
2+
3+
This image provides an OpenLDAP Server for testing LDAP applications, i.e. unit tests. The server is initialized with data from Futurama, Planet Express, Inc. Currently there are only entries for Fry, Lila and Bender. In the future I will add more Crew members and other objects, for more complex tests.
4+
5+
Parts of the image are based on the work from Nick Stenning [docker-slapd][slapd] and Bertrand Gouny [docker-openldap][openldap].
6+
7+
[slapd]: https://github.com/nickstenning/docker-slapd
8+
[openldap]: https://github.com/osixia/docker-openldap
9+
10+
11+
## Features
12+
13+
* Support for TLS
14+
* Initialized with data from Futurama
15+
* ~190MB Images size
16+
17+
18+
## Usage
19+
20+
```
21+
docker pull rroemhild/test-openldap
22+
docker run --privileged -d -p 389:389 rroemhild/test-openldap
23+
```
24+
25+
26+
## LDAP Data
27+
28+
* BASEDN: dc=planetexpress,dc=com
29+
* ADMIN_DN: cn=admin,dc=planetexpress,dc=com
30+
* ADMIN_SECRET: GoodNewsEveryone
31+
32+
33+
## Exposed ports
34+
35+
* 389
36+
37+
38+
## Exposed volumes
39+
40+
* /etc/ldap/slapd.d
41+
* /etc/ldap/ssl
42+
* /var/lib/ldap
43+
* /run/slapd
44+

bootstrap/ldif/00_base.ldif

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dn: ou=people,dc=planetexpress,dc=com
2+
objectClass: top
3+
objectClass: organizationalUnit
4+
description: Springfield citizens
5+
ou: people

bootstrap/ldif/10_people.ldif

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
dn: cn=Philip Fry,ou=people,dc=planetexpress,dc=com
2+
objectClass: top
3+
objectClass: person
4+
objectClass: organizationalPerson
5+
objectClass: inetOrgPerson
6+
cn: Philip Fry
7+
displayName: Philip J. Fry
8+
sn: Philip
9+
givenName: Fry
10+
11+
uid: fry
12+
13+
dn: cn=Turanga Leela,ou=people,dc=planetexpress,dc=com
14+
objectClass: top
15+
objectClass: person
16+
objectClass: organizationalPerson
17+
objectClass: inetOrgPerson
18+
cn: Turanga Leela
19+
sn: Turanga
20+
givenName: Leela
21+
22+
uid: leela
23+
24+
dn: cn=Bender Rodríguez,ou=people,dc=planetexpress,dc=com
25+
objectClass: top
26+
objectClass: person
27+
objectClass: organizationalPerson
28+
objectClass: inetOrgPerson
29+
cn: Bender Rodríguez
30+
displayName: Bender Bending Rodríguez
31+
sn: Rodríguez
32+
givenName: Bender
33+
34+
uid: bender

bootstrap/ldif/logging.ldif

+4
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

bootstrap/ldif/tls.ldif

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dn: cn=config
2+
changetype: modify
3+
replace: olcTLSCertificateFile
4+
olcTLSCertificateFile: /etc/ldap/ssl/ldap.crt
5+
-
6+
replace: olcTLSCertificateKeyFile
7+
olcTLSCertificateKeyFile: /etc/ldap/ssl/ldap.key
8+
-
9+
replace: olcTLSVerifyClient
10+
olcTLSVerifyClient: never
11+

bootstrap/slapd-init.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
5+
readonly LDAP_BINDDN="cn=admin,dc=planetexpress,dc=com"
6+
7+
8+
file_exist() {
9+
local file=$1
10+
11+
[[ -e $file ]]
12+
}
13+
14+
15+
reconfigure_slapd() {
16+
echo "Reconfigure slapd..."
17+
cat <<EOL | debconf-set-selections
18+
slapd slapd/internal/generated_adminpw password ${LDAP_ADMIN_SECRET}
19+
slapd slapd/internal/adminpw password ${LDAP_ADMIN_SECRET}
20+
slapd slapd/password2 password ${LDAP_ADMIN_SECRET}
21+
slapd slapd/password1 password ${LDAP_ADMIN_SECRET}
22+
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
23+
slapd slapd/domain string ${LDAP_DOMAIN}
24+
slapd shared/organization string ${LDAP_ORGANISATION}
25+
slapd slapd/backend string HDB
26+
slapd slapd/purge_database boolean true
27+
slapd slapd/move_old_database boolean true
28+
slapd slapd/allow_ldap_v2 boolean false
29+
slapd slapd/no_configuration boolean false
30+
slapd slapd/dump_database select when needed
31+
EOL
32+
33+
dpkg-reconfigure -f noninteractive slapd
34+
}
35+
36+
37+
configure_tls() {
38+
echo "Configure TLS..."
39+
ldapmodify -Y EXTERNAL -H ldapi:/// -f /bootstrap/ldif/tls.ldif -Q
40+
}
41+
42+
43+
configure_logging() {
44+
echo "Configure logging..."
45+
ldapmodify -Y EXTERNAL -H ldapi:/// -f /bootstrap/ldif/logging.ldif -Q
46+
}
47+
48+
49+
load_initial_data() {
50+
echo "Load data..."
51+
data=$(find /bootstrap/ldif -maxdepth 1 -name \*_\*.ldif -type f | sort)
52+
for ldif in ${data}; do
53+
echo "Processing file ${ldif}..."
54+
ldapadd -x -D ${LDAP_BINDDN} -w ${LDAP_ADMIN_SECRET} -H ldapi:/// -f ${ldif}
55+
done
56+
}
57+
58+
59+
## Init
60+
61+
reconfigure_slapd
62+
63+
chown -R openldap:openldap /etc/ldap
64+
slapd -h "ldapi:///" -u openldap -g openldap
65+
66+
configure_tls
67+
configure_logging
68+
load_initial_data
69+
70+
kill -INT `cat /run/slapd/slapd.pid`
71+
72+
exit 0
73+

run.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
set -x
3+
4+
readonly LDAP_SSL_KEY="/etc/ldap/ssl/ldap.key"
5+
readonly LDAP_SSL_CERT="/etc/ldap/ssl/ldap.crt"
6+
7+
8+
make_snakeoil_certificate() {
9+
echo "Make snakeoil certificate for ${LDAP_DOMAIN}..."
10+
openssl req -subj "/CN=${LDAP_DOMAIN}" \
11+
-new \
12+
-newkey rsa:2048 \
13+
-days 365 \
14+
-nodes \
15+
-x509 \
16+
-keyout ${LDAP_SSL_KEY} \
17+
-out ${LDAP_SSL_CERT}
18+
19+
chmod 600 /etc/ldap/ssl/ldap.key
20+
}
21+
22+
23+
file_exist ${LDAP_SSL_CERT} \
24+
|| make_snakeoil_certificate
25+
26+
echo "starting slapd on default port 389..."
27+
chown -R openldap:openldap /etc/ldap
28+
exec /usr/sbin/slapd -h "ldap:/// ldapi:///" -u openldap -g openldap -d -1
29+

0 commit comments

Comments
 (0)