commit 143a94f2f4760843aa497622658ab42208084746 Author: Reza Behzadan Date: Mon Jan 29 16:52:14 2024 +0330 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a093b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +build/ +stash/ +.archive/ +.vagrant/ +.env +.keys +*_[0-9] +*_[0-9][0-9] +*_????-??-?? +*.zip diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d4a557d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:22.04 + +LABEL version="1.0.0" + +MAINTAINER "Reza Behzadan " + +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"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..398e7b5 --- /dev/null +++ b/Makefile @@ -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 diff --git a/basic.ldif b/basic.ldif new file mode 100644 index 0000000..b819d46 --- /dev/null +++ b/basic.ldif @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..26bb777 --- /dev/null +++ b/entrypoint.sh @@ -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 <