Initial commit

This commit is contained in:
Reza Behzadan 2024-01-29 16:52:14 +03:30
commit 143a94f2f4
5 changed files with 129 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
build/
stash/
.archive/
.vagrant/
.env
.keys
*_[0-9]
*_[0-9][0-9]
*_????-??-??
*.zip

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM ubuntu:22.04
LABEL version="1.0.0"
MAINTAINER "Reza Behzadan <reza@behzadan.ir>"
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -yq --no-install-recommends debconf-utils && \
echo "slapd slapd/internal/adminpw password 123" | debconf-set-selections && \
echo "slapd slapd/internal/generated_adminpw password 123" | debconf-set-selections && \
echo "slapd slapd/password2 password 123" | debconf-set-selections && \
echo "slapd slapd/password1 password 123" | debconf-set-selections && \
echo "slapd slapd/domain string example.com" | debconf-set-selections && \
echo "slapd shared/organization string example" | debconf-set-selections && \
apt-get install -yq --no-install-recommends slapd ldap-utils && \
apt-get autoremove -yq && apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 389
CMD ["/entrypoint.sh"]

23
Makefile Normal file
View File

@ -0,0 +1,23 @@
.PHONY: prepare_mounts
prepare_mounts: clean
mkdir ldap-data
sudo chown -R 101:101 ldap-data
.PHONY: clean
clean:
sudo rm -rf ldap-data
.PHONY: build
build: clean
docker build -t rbehzadan/openldap:1.0.1 .
.PHONY: run
run: prepare_mounts
docker run --rm -p 389:389 --name openldap \
-e LDAP_ROOTPASS="Sinic1234" \
-e LDAP_ORGANISATION="sinic" \
-e LDAP_DOMAIN="sinic.ir" \
-v /etc/timezone:/etc/timezone:ro \
-v /etc/localtime:/etc/localtime:ro \
-v "`pwd`/ldap-data:/var/lib/ldap" \
rbehzadan/openldap:1.0.1

18
basic.ldif Normal file
View File

@ -0,0 +1,18 @@
dn: ou=users,dc=sinic,dc=ir
objectClass: organizationalUnit
ou: users
dn: ou=groups,dc=sinic,dc=ir
objectClass: organizationalUnit
ou: groups
dn: uid=rbehzadan,ou=users,dc=sinic,dc=ir
objectClass: top
objectClass: person
objectClass: inetOrgPerson
uid: rbehzadan
cn: Reza Behzadan
sn: Behzadan
givenName: Reza
mail: rbehzadan@gmail.com
userPassword: Reza1234

51
entrypoint.sh Normal file
View File

@ -0,0 +1,51 @@
#!/bin/bash
# Set default values for environment variables if they are not provided
LDAP_ROOTPASS=${LDAP_ROOTPASS:-123}
LDAP_ORGANISATION=${LDAP_ORGANISATION:-example}
LDAP_DOMAIN=${LDAP_DOMAIN:-exmaple.com}
# Function to handle SIGTERM
terminate() {
echo "Termination signal received, shutting down slapd..."
slapd_stop
exit 0
}
# Function to start slapd in the background
slapd_start() {
ulimit -n 1024
slapd -h "ldap:/// ldapi:///" -u openldap -g openldap -d 1 &
SLAPD_PID=$!
}
# Function to stop slapd
slapd_stop() {
kill -TERM "$SLAPD_PID"
wait "$SLAPD_PID"
}
# Set trap for SIGTERM
trap 'terminate' SIGTERM SIGINT
cat <<EOF | debconf-set-selections
slapd slapd/internal/generated_adminpw password ${LDAP_ROOTPASS}
slapd slapd/internal/adminpw password ${LDAP_ROOTPASS}
slapd slapd/password2 password ${LDAP_ROOTPASS}
slapd slapd/password1 password ${LDAP_ROOTPASS}
slapd slapd/domain string ${LDAP_DOMAIN}
slapd shared/organization string ${LDAP_ORGANISATION}
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
# Start slapd in the background
slapd_start
# Keep the script running and wait for the slapd process
wait "$SLAPD_PID"