Skip to content

Commit

Permalink
Merge branch 'release-0.10.0' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandGouny committed Mar 3, 2015
2 parents 9964ef4 + ce67e92 commit 469a9bf
Show file tree
Hide file tree
Showing 52 changed files with 1,018 additions and 216 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 0.10.0 (release date: 2015-03-03)
- New version initial release
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
NAME = osixia/openldap
VERSION = 0.9.2
VERSION = 0.10.0

.PHONY: all build test tag_latest release

all: build

build:
docker.io build -t $(NAME):$(VERSION) --rm .
docker build -t $(NAME):$(VERSION) --rm image

test:
env NAME=$(NAME) VERSION=$(VERSION) ./test.sh debug
env NAME=$(NAME) VERSION=$(VERSION) bats test/test.bats

tag_latest:
docker.io tag $(NAME):$(VERSION) $(NAME):latest
docker tag -f $(NAME):$(VERSION) $(NAME):latest

release: build test tag_latest
@if ! docker.io images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi
docker.io push $(NAME)
@echo "*** Don't forget to run 'twgit release finish' :)"
@if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi
@if ! head -n 1 CHANGELOG.md | grep -q 'release date'; then echo 'Please note the release date in Changelog.md.' && false; fi
docker push $(NAME)
@echo "*** Don't forget to run 'twgit release/hotfix finish' :)"

27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,4 @@ https://github.com/nickstenning/docker-slapd

Add support of tls.

### How to use tls

Add `-v some/host/dir:/etc/ldap/ssl` and `--dns=127.0.0.1` to the run command.

`some/host/dir` must contain a least 3 files :
- `ca.crt` certificate authority certificate
- `ldap.crt` ldap server certificate
- `ldap.key` ldap server certificate private key

and optionaly `dhparam.pem` this file is genereted automaticaly if not present.

`--dns=127.0.0.1` allow to use the certificate cn correctly.


### Example

docker run --dns=127.0.0.1 \
-v /data/ldap/db:/var/lib/ldap \
-v /data/ldap/config:/etc/ldap/slapd.d \
-v /data/ldap/ssl/:/etc/ldap/ssl \
-v /data/ldap/log/:/var/log \
-e LDAP_DOMAIN=example.com \
-e LDAP_ORGANISATION="Example Corp." \
-e LDAP_ROOTPASS=toor \
-p 389:389 -d osixia/openldap

Use docker 1.5.0
34 changes: 34 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM osixia/baseimage:0.10.3
MAINTAINER Bertrand Gouny <[email protected]>

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]

# Add openldap user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r openldap && useradd -r -g openldap openldap

# Install OpenLDAP and ldap-utils (and ssl-kit from baseimage), remove default ldap db
RUN apt-get -y update && /sbin/enable-service ssl-kit \
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes --no-install-recommends slapd ldap-utils \
&& rm -rf /var/lib/ldap

# Add install script and OpenLDAP assets
ADD service/install.sh /tmp/install.sh
ADD service/slapd/assets /osixia/slapd

# Run install script and clean all
RUN ./tmp/install.sh \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Add default env variables
ADD env.yml /etc/env.yml

# Add OpenLDAP container start config & daemon
ADD service/slapd/container-start.sh /etc/my_init.d/slapd
ADD service/slapd/daemon.sh /etc/service/slapd/run

# Set OpenLDAP data and config directories in a data volume
VOLUME ["/var/lib/ldap", "/etc/ldap/slapd.d"]

# Expose ldap default port
EXPOSE 389
10 changes: 10 additions & 0 deletions image/env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LDAP_ORGANISATION: Example Inc.
LDAP_DOMAIN: example.org
LDAP_ADMIN_PASSWORD: admin

SERVER_NAME: ldap.example.org

USE_TLS: true
SSL_CRT_FILENAME: ldap.crt
SSL_KEY_FILENAME: ldap.key
SSL_CA_CRT_FILENAME: ca.crt
6 changes: 6 additions & 0 deletions image/service/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e
# this script is run during the image build

# Enable access only from docker default network and localhost
echo "slapd: 172.17.0.0/255.255.0.0 127.0.0.1 : ALLOW" >> /etc/hosts.allow
echo "slapd: ALL : DENY" >> /etc/hosts.allow
1 change: 1 addition & 0 deletions image/service/slapd/assets/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add your ldif config file here
4 changes: 4 additions & 0 deletions image/service/slapd/assets/config/logging.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: stats
2 changes: 2 additions & 0 deletions image/service/slapd/assets/ssl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add your ssl crt, key and ca crt here
or during docker run mount a data volume with thoses files to /osixia/slapd/ssl
19 changes: 19 additions & 0 deletions image/service/slapd/assets/tls.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
dn: cn=config
changetype: modify
add: olcTLSCipherSuite
olcTLSCipherSuite: SECURE256:-VERS-SSL3.0
-
replace: olcTLSCACertificateFile
olcTLSCACertificateFile: /osixia/slapd/ssl/ca.crt
-
replace: olcTLSCertificateFile
olcTLSCertificateFile: /osixia/slapd/ssl/ldap.crt
-
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /osixia/slapd/ssl/ldap.key
-
replace: olcTLSDHParamFile
olcTLSDHParamFile: /osixia/slapd/ssl/dhparam.pem
-
replace: olcTLSVerifyClient
olcTLSVerifyClient: never
78 changes: 78 additions & 0 deletions image/service/slapd/container-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash -e

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

# database is uninitialized
if [ -z "$(ls -A /var/lib/ldap)" ]; then

cat <<EOF | debconf-set-selections
slapd slapd/internal/generated_adminpw password ${LDAP_ADMIN_PASSWORD}
slapd slapd/internal/adminpw password ${LDAP_ADMIN_PASSWORD}
slapd slapd/password2 password ${LDAP_ADMIN_PASSWORD}
slapd slapd/password1 password ${LDAP_ADMIN_PASSWORD}
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
slapd slapd/domain string ${LDAP_DOMAIN}
slapd shared/organization string ${LDAP_ORGANISATION}
slapd slapd/backend string HDB
slapd slapd/purge_database boolean true
slapd slapd/move_old_database boolean true
slapd slapd/allow_ldap_v2 boolean false
slapd slapd/no_configuration boolean false
slapd slapd/dump_database select when needed
EOF

dpkg-reconfigure -f noninteractive slapd
fi


# start OpenLDAP
slapd -h "ldapi:///" -u openldap -g openldap

# TLS config
if [ "${USE_TLS,,}" == "true" ]; then

# check certificat and key or create it
/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

# 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 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

# 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

# OpenLDAP config
for f in $(find /osixia/slapd/config -name \*.ldif -type f); do
status "Processing file ${f}"
ldapmodify -r -Y EXTERNAL -H ldapi:/// -f $f -Q
done

# stop OpenLDAP
kill -INT `cat /run/slapd/slapd.pid`

touch $FIRST_START_DONE
fi

# fix file permissions
chown openldap:openldap -R /osixia/slapd

exit 0
2 changes: 2 additions & 0 deletions image/service/slapd/daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash -e
exec /usr/sbin/slapd -h "ldap:///" -u openldap -g openldap -d -1
8 changes: 0 additions & 8 deletions test/config

This file was deleted.

7 changes: 0 additions & 7 deletions test/config-repository

This file was deleted.

16 changes: 16 additions & 0 deletions test/config/cn=config.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 e072c71d
dn: cn=config
objectClass: olcGlobal
cn: config
olcArgsFile: /var/run/slapd/slapd.args
olcPidFile: /var/run/slapd/slapd.pid
olcToolThreads: 1
structuralObjectClass: olcGlobal
entryUUID: db089696-51e1-1034-95ec-9d03bc6be361
creatorsName: cn=config
createTimestamp: 20150226090154Z
olcLogLevel: stats
entryCSN: 20150303142212.168245Z#000000#000#000000
modifiersName: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
modifyTimestamp: 20150303142212Z
14 changes: 14 additions & 0 deletions test/config/cn=config/cn=module{0}.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 d5bd456a
dn: cn=module{0}
objectClass: olcModuleList
cn: module{0}
olcModulePath: /usr/lib/ldap
olcModuleLoad: {0}back_hdb
structuralObjectClass: olcModuleList
entryUUID: db093e98-51e1-1034-95f4-9d03bc6be361
creatorsName: cn=config
createTimestamp: 20150226090154Z
entryCSN: 20150226090154.826169Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20150226090154Z
12 changes: 12 additions & 0 deletions test/config/cn=config/cn=schema.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 deed6c98
dn: cn=schema
objectClass: olcSchemaConfig
cn: schema
structuralObjectClass: olcSchemaConfig
entryUUID: db08b2b6-51e1-1034-95ef-9d03bc6be361
creatorsName: cn=config
createTimestamp: 20150226090154Z
entryCSN: 20150226090154.822586Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20150226090154Z
Loading

0 comments on commit 469a9bf

Please sign in to comment.