Skip to content

Commit f9e5ef6

Browse files
authored
Merge pull request #32 from AnalogJ/master
STARTTLS, custom/valid certificate support, runtime configuration & other enhancements
2 parents 5448206 + 612b622 commit f9e5ef6

28 files changed

+293
-135
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
schedule:
10+
- cron: '36 12 * * *'
11+
push:
12+
branches: [ master ]
13+
# Publish semver tags as releases.
14+
tags: [ 'v*.*.*' ]
15+
pull_request:
16+
branches: [ master ]
17+
18+
env:
19+
# Use docker.io for Docker Hub if empty
20+
REGISTRY: ghcr.io
21+
# github.repository as <account>/<repo>
22+
IMAGE_NAME: ${{ github.repository }}
23+
24+
25+
jobs:
26+
build:
27+
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
packages: write
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v2
36+
37+
# Login against a Docker registry except on PR
38+
# https://github.com/docker/login-action
39+
- name: Log into registry ${{ env.REGISTRY }}
40+
if: github.event_name != 'pull_request'
41+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
42+
with:
43+
registry: ${{ env.REGISTRY }}
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
# Extract metadata (tags, labels) for Docker
48+
# https://github.com/docker/metadata-action
49+
- name: Extract Docker metadata
50+
id: meta
51+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
52+
with:
53+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54+
55+
# Build and push Docker image with Buildx (don't push on PR)
56+
# https://github.com/docker/build-push-action
57+
- name: Build and push Docker image
58+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
59+
with:
60+
context: .
61+
push: ${{ github.event_name != 'pull_request' }}
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
certs

Dockerfile

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
FROM debian:buster-slim
2-
MAINTAINER Rafael Römhild <[email protected]>
2+
3+
# Configuration Env Variables with defaults
4+
ENV DATA_DIR="/opt/openldap/bootstrap/data"
5+
ENV CONFIG_DIR="/opt/openldap/bootstrap/config"
6+
ENV LDAP_DOMAIN=planetexpress.com
7+
ENV LDAP_ORGANISATION="Planet Express, Inc."
8+
ENV LDAP_BINDDN="cn=admin,dc=planetexpress,dc=com"
9+
ENV LDAP_SECRET=GoodNewsEveryone
10+
ENV LDAP_CA_CERT="/etc/ldap/ssl/fullchain.crt"
11+
ENV LDAP_SSL_KEY="/etc/ldap/ssl/ldap.key"
12+
ENV LDAP_SSL_CERT="/etc/ldap/ssl/ldap.crt"
13+
ENV LDAP_FORCE_STARTTLS="false"
314

415
# Install slapd and requirements
516
RUN apt-get update \
@@ -10,23 +21,20 @@ RUN apt-get update \
1021
ldap-utils \
1122
openssl \
1223
ca-certificates \
13-
tini \
1424
&& rm -rf /var/lib/apt/lists/* \
1525
&& mkdir /etc/ldap/ssl /bootstrap
1626

17-
# ADD bootstrap files
18-
ADD ./bootstrap /bootstrap
27+
# Add s6-overlay
28+
ADD https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.1/s6-overlay-amd64-installer /tmp/
29+
RUN chmod +x /tmp/s6-overlay-amd64-installer && /tmp/s6-overlay-amd64-installer /
1930

20-
# Initialize LDAP with data
21-
RUN /bin/bash /bootstrap/slapd-init.sh
31+
# ADD rootfs files
32+
ADD ./rootfs /
2233

2334
VOLUME ["/etc/ldap/slapd.d", "/etc/ldap/ssl", "/var/lib/ldap", "/run/slapd"]
2435

25-
EXPOSE 389 636
26-
27-
USER openldap
36+
EXPOSE 10389 10636
2837

29-
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/sbin/slapd"]
30-
CMD ["-h", "ldapi:/// ldap://0.0.0.0:10389 ldaps://0.0.0.0:10636", "-d", "256"]
38+
CMD ["/init"]
3139

32-
HEALTHCHECK CMD ldapsearch -H ldap://127.0.0.1:10389 -D cn=admin,dc=planetexpress,dc=com -w GoodNewsEveryone -b cn=admin,dc=planetexpress,dc=com
40+
HEALTHCHECK CMD ["ldapsearch", "-H", "ldap://127.0.0.1:10389", "-D", "${LDAP_BINDDN}", "-w", "${LDAP_SECRET}", "-b", "${LDAP_BINDDN}"]

LETSENCRYPT_CERTS.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# LetsEncrypt Certificates for OpenLDAP
2+
- Use https://github.com/matrix-org/docker-dehydrated#behaviour
3+
```
4+
mkdir data
5+
echo "ldap.customdomain.com" > data/domains.txt
6+
7+
# create a docker-compose.yml file
8+
version: '2'
9+
services:
10+
dehydrated:
11+
image: docker.io/matrixdotorg/dehydrated
12+
restart: unless-stopped
13+
volumes:
14+
- ./data:/data
15+
environment:
16+
- DEHYDRATED_GENERATE_CONFIG=yes
17+
- DEHYDRATED_CA="https://acme-v02.api.letsencrypt.org/directory"
18+
# - DEHYDRATED_CA="https://acme-staging-v02.api.letsencrypt.org/directory"
19+
- DEHYDRATED_CHALLENGE="dns-01"
20+
- DEHYDRATED_KEYSIZE="4096"
21+
- DEHYDRATED_HOOK="/usr/local/bin/lexicon-hook"
22+
- DEHYDRATED_RENEW_DAYS="30"
23+
- DEHYDRATED_KEY_RENEW="yes"
24+
- DEHYDRATED_EMAIL="[email protected]"
25+
- DEHYDRATED_ACCEPT_TERMS=yes
26+
- PROVIDER=cloudflare
27+
- LEXICON_CLOUDFLARE_USERNAME
28+
- LEXICON_CLOUDFLARE_TOKEN
29+
30+
31+
#run docker compose
32+
docker-compose up
33+
```
34+
35+
# Copy Certificates to correct directory
36+
```
37+
cp fullchain-*.pem ldap/fullchain.crt
38+
cp cert-*.pem ldap/ldap.crt
39+
cp privkey-1623520297.pem ldap/ldap.key
40+
```

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ The Flask extension [flask-ldapconn][flaskldapconn] use this image for unit test
1717
## Features
1818

1919
* Initialized with data from Futurama
20-
* Support for TLS (snake oil cert on build)
20+
* Support for LDAP over TLS (STARTTLS) using a self-signed cert, or valid certificates (LetsEncrypt, etc)
2121
* memberOf overlay support
2222
* MS-AD style groups support
23+
* Supports Forced STARTTLS
24+
* Supports custom domain and custom directory structure
2325

2426

2527
## Usage
@@ -29,6 +31,22 @@ docker pull rroemhild/test-openldap
2931
docker run --rm -p 10389:10389 -p 10636:10636 rroemhild/test-openldap
3032
```
3133

34+
## Testing
35+
36+
```
37+
# List all Users
38+
ldapsearch -H ldap://localhost:10389 -x -b "ou=people,dc=planetexpress,dc=com" -D "cn=admin,dc=planetexpress,dc=com" -w GoodNewsEveryone "(objectClass=inetOrgPerson)"
39+
40+
# Request StartTLS
41+
ldapsearch -H ldap://localhost:10389 -Z -x -b "ou=people,dc=planetexpress,dc=com" -D "cn=admin,dc=planetexpress,dc=com" -w GoodNewsEveryone "(objectClass=inetOrgPerson)"
42+
43+
# Enforce StartTLS
44+
ldapsearch -H ldap://localhost:10389 -ZZ -x -b "ou=people,dc=planetexpress,dc=com" -D "cn=admin,dc=planetexpress,dc=com" -w GoodNewsEveryone "(objectClass=inetOrgPerson)"
45+
46+
# Enforce StartTLS with self-signed cert
47+
LDAPTLS_REQCERT=never ldapsearch -H ldap://localhost:10389 -ZZ -x -b "ou=people,dc=planetexpress,dc=com" -D "cn=admin,dc=planetexpress,dc=com" -w GoodNewsEveryone "(objectClass=inetOrgPerson)"
48+
```
49+
3250
## Exposed ports
3351

3452
* 10389 (ldap)

bootstrap/slapd-init.sh

Lines changed: 0 additions & 112 deletions
This file was deleted.

docker-compose.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ services:
55
container_name: ldap
66
# use the image tag to pull directly from the repo
77
# image: rroemhild/test-openldap
8-
8+
environment:
9+
LDAP_FORCE_STARTTLS: "true"
10+
LDAP_DOMAIN: "customdomain.com"
11+
LDAP_BASEDN: "dc=customdomain,dc=com"
12+
LDAP_ORGANISATION: "Custom Domain, Inc."
13+
LDAP_BINDDN: "cn=admin,dc=customdomain,dc=com"
914
# use build tag to use the local repo
1015
build:
1116
context: ./
1217
dockerfile: ./Dockerfile
1318
ports:
1419
- '10389:10389'
1520
- '10636:10636'
16-
volumes:
17-
- data_volume:/var/lib/ldap/
18-
19-
volumes:
20-
data_volume:
21+
# volumes:
22+
# - data_volume:/var/lib/ldap/
23+
#
24+
#volumes:
25+
# data_volume:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/with-contenv bash
2+
set -eux
3+
4+
echo "Reconfigure slapd..."
5+
cat <<EOL | debconf-set-selections
6+
slapd slapd/internal/generated_adminpw password ${LDAP_SECRET}
7+
slapd slapd/internal/adminpw password ${LDAP_SECRET}
8+
slapd slapd/password2 password ${LDAP_SECRET}
9+
slapd slapd/password1 password ${LDAP_SECRET}
10+
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
11+
slapd slapd/domain string ${LDAP_DOMAIN}
12+
slapd shared/organization string ${LDAP_ORGANISATION}
13+
slapd slapd/backend string HDB
14+
slapd slapd/purge_database boolean true
15+
slapd slapd/move_old_database boolean true
16+
slapd slapd/allow_ldap_v2 boolean false
17+
slapd slapd/no_configuration boolean false
18+
slapd slapd/dump_database select when needed
19+
EOL
20+
21+
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure slapd
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/with-contenv bash
2+
set -eux
3+
4+
if [[ -f "$LDAP_SSL_KEY" ]] && [[ -f "$LDAP_SSL_CERT" ]]; then
5+
echo "TLS Certificates already present. Using provided certificates"
6+
7+
# TODO: validate the provided certs match domain
8+
9+
else
10+
echo "Make self-signed certificate for ${LDAP_DOMAIN}..."
11+
openssl req -subj "/CN=${LDAP_DOMAIN}" \
12+
-new \
13+
-newkey rsa:2048 \
14+
-days 365 \
15+
-nodes \
16+
-x509 \
17+
-keyout ${LDAP_SSL_KEY} \
18+
-out ${LDAP_SSL_CERT}
19+
20+
chmod 600 ${LDAP_SSL_KEY}
21+
fi
22+
23+
24+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/with-contenv bash
2+
set -eux
3+
4+
chown -R openldap:openldap /etc/ldap

0 commit comments

Comments
 (0)