Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 2b0cd76

Browse files
committed
Update to debian jessie
* Move most envvars into scripts * Generate snake oil certificate on container build
1 parent 9279b87 commit 2b0cd76

File tree

5 files changed

+41
-56
lines changed

5 files changed

+41
-56
lines changed

Dockerfile

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
FROM debian:7
1+
FROM debian:jessie
22
MAINTAINER Rafael Römhild <[email protected]>
33

4-
ENV DEBUG_LEVEL 256
5-
ENV LDAP_DOMAIN planetexpress.com
6-
ENV LDAP_ADMIN_SECRET GoodNewsEveryone
7-
ENV LDAP_ORGANISATION Planet Express, Inc.
8-
ENV DEBIAN_FRONTEND noninteractive
9-
104
# Install slapd and requirements
115
RUN apt-get update \
12-
&& apt-get -y --no-install-recommends install \
13-
slapd \
14-
ldap-utils \
15-
openssl \
16-
ca-certificates \
6+
&& DEBIAN_FRONTEND=noninteractive apt-get \
7+
install -y --no-install-recommends \
8+
slapd \
9+
ldap-utils \
10+
openssl \
11+
ca-certificates \
1712
&& rm -rf /var/lib/apt/lists/*
1813

14+
ENV LDAP_DEBUG_LEVEL=256
15+
1916
# Create TLS certificate and bootstrap directory
2017
RUN mkdir /etc/ldap/ssl /bootstrap
2118

@@ -33,5 +30,5 @@ VOLUME ["/etc/ldap/slapd.d", "/etc/ldap/ssl", "/var/lib/ldap", "/run/slapd"]
3330
EXPOSE 389
3431
EXPOSE 636
3532

36-
CMD []
37-
ENTRYPOINT ["/bin/bash", "/run.sh"]
33+
CMD ["/bin/bash", "/run.sh"]
34+
ENTRYPOINT []

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ The Flask extension [flask-ldapconn][flaskldapconn] use this image for unit test
1414

1515
## Features
1616

17-
* Support for TLS
18-
* Autogenerated snake oil cert
17+
* Support for TLS (snake oil cert on build)
1918
* Initialized with data from Futurama
2019
* ~180MB Images size
2120

@@ -30,7 +29,7 @@ docker run --privileged -d -p 389:389 rroemhild/test-openldap
3029
## Exposed ports
3130

3231
* 389
33-
32+
* 636
3433

3534
## Exposed volumes
3635

@@ -155,4 +154,3 @@ docker run --privileged -d -p 389:389 rroemhild/test-openldap
155154
| ou | Delivering Crew |
156155
| uid | bender |
157156
| userPassword | bender |
158-

bootstrap/config/tls.ldif

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ olcTLSCertificateKeyFile: /etc/ldap/ssl/ldap.key
88
-
99
replace: olcTLSVerifyClient
1010
olcTLSVerifyClient: never
11-

bootstrap/slapd-init.sh

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@ set -eu
44
readonly DATA_DIR="/bootstrap/data"
55
readonly CONFIG_DIR="/bootstrap/config"
66

7+
readonly LDAP_DOMAIN=planetexpress.com
8+
readonly LDAP_ORGANISATION="Planet Express, Inc."
79
readonly LDAP_BINDDN="cn=admin,dc=planetexpress,dc=com"
10+
readonly LDAP_SECRET=GoodNewsEveryone
811

9-
10-
file_exist() {
11-
local file=$1
12-
13-
[[ -e $file ]]
14-
}
12+
readonly LDAP_SSL_KEY="/etc/ldap/ssl/ldap.key"
13+
readonly LDAP_SSL_CERT="/etc/ldap/ssl/ldap.crt"
1514

1615

1716
reconfigure_slapd() {
1817
echo "Reconfigure slapd..."
1918
cat <<EOL | debconf-set-selections
20-
slapd slapd/internal/generated_adminpw password ${LDAP_ADMIN_SECRET}
21-
slapd slapd/internal/adminpw password ${LDAP_ADMIN_SECRET}
22-
slapd slapd/password2 password ${LDAP_ADMIN_SECRET}
23-
slapd slapd/password1 password ${LDAP_ADMIN_SECRET}
19+
slapd slapd/internal/generated_adminpw password ${LDAP_SECRET}
20+
slapd slapd/internal/adminpw password ${LDAP_SECRET}
21+
slapd slapd/password2 password ${LDAP_SECRET}
22+
slapd slapd/password1 password ${LDAP_SECRET}
2423
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
2524
slapd slapd/domain string ${LDAP_DOMAIN}
2625
slapd shared/organization string ${LDAP_ORGANISATION}
@@ -32,7 +31,22 @@ slapd slapd/no_configuration boolean false
3231
slapd slapd/dump_database select when needed
3332
EOL
3433

35-
dpkg-reconfigure slapd
34+
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure slapd
35+
}
36+
37+
38+
make_snakeoil_certificate() {
39+
echo "Make snakeoil certificate for ${LDAP_DOMAIN}..."
40+
openssl req -subj "/CN=${LDAP_DOMAIN}" \
41+
-new \
42+
-newkey rsa:2048 \
43+
-days 365 \
44+
-nodes \
45+
-x509 \
46+
-keyout ${LDAP_SSL_KEY} \
47+
-out ${LDAP_SSL_CERT}
48+
49+
chmod 600 ${LDAP_SSL_KEY}
3650
}
3751

3852

@@ -55,7 +69,7 @@ load_initial_data() {
5569
echo "Processing file ${ldif}..."
5670
ldapadd -x -H ldapi:/// \
5771
-D ${LDAP_BINDDN} \
58-
-w ${LDAP_ADMIN_SECRET} \
72+
-w ${LDAP_SECRET} \
5973
-f ${ldif}
6074
done
6175
}
@@ -64,7 +78,7 @@ load_initial_data() {
6478
## Init
6579

6680
reconfigure_slapd
67-
81+
make_snakeoil_certificate
6882
chown -R openldap:openldap /etc/ldap
6983
slapd -h "ldapi:///" -u openldap -g openldap
7084

@@ -75,4 +89,3 @@ load_initial_data
7589
kill -INT `cat /run/slapd/slapd.pid`
7690

7791
exit 0
78-

run.sh

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
#!/bin/sh
22
set -e
33

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 ${LDAP_SSL_KEY}
20-
}
21-
22-
23-
file_exist ${LDAP_SSL_CERT} \
24-
|| make_snakeoil_certificate
25-
264
echo "starting slapd on port 389 and 636..."
275
chown -R openldap:openldap /etc/ldap
286
exec /usr/sbin/slapd -h "ldap:/// ldapi:/// ldaps:///" \
297
-u openldap \
308
-g openldap \
31-
-d ${DEBUG_LEVEL}
9+
-d ${LDAP_DEBUG_LEVEL}

0 commit comments

Comments
 (0)