From 65a781afa06edbd8a9581e2bc073566e73adab1d Mon Sep 17 00:00:00 2001 From: Mauro Torrez Date: Wed, 25 Sep 2019 19:15:54 -0300 Subject: [PATCH] WIP: add provider capability --- Dockerfile | 26 ++-- entrypoint.sh | 365 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 252 insertions(+), 139 deletions(-) diff --git a/Dockerfile b/Dockerfile index db8139d..5fd9fa7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,31 @@ FROM eumau/debian:buster-slim +# admin CN => dn: cn=%%ADMIN_CN%%,%%DOMAIN_DN%% ENV LDAP_ADMIN_CN="admin" -# admin CN, DN => cn=%%ADMIN_DN%%,%%DOMAIN_DN%% -ENV LDAP_ADMIN_PASSWORD="admin" # password for cn=%%ADMIN_DN%%,%%DOMAIN_DN%% -ENV LDAP_CONFIG_PASSWORD="${LDAP_ADMIN_PASSWORD}" +ENV LDAP_ADMIN_PASSWORD="admin" # password for cn=admin,cn=config +ENV LDAP_CONFIG_PASSWORD="${LDAP_ADMIN_PASSWORD}" +# domain name (example.org) ENV LDAP_DOMAIN="" -# domain O (example.org) -ENV LDAP_DOMAIN_ACCESS="{0}to attrs=userPassword by self write by anonymous auth by * none\n{1}to attrs=shadowLastChange by self write by * read\n{2}to * by * read" # olcDbAccess attribute for domain entry (newline-separated) -ENV LDAP_DOMAIN_DN="" +ENV LDAP_DOMAIN_ACCESS="{0}to attrs=userPassword by self write by anonymous auth by * none\n{1}to attrs=shadowLastChange by self write by * read\n{2}to * by * read" # domain DN (dc=example,dc=org) -ENV LDAP_DOMAIN_INDEX="cn,uid eq\nmember,memberUid eq\nobjectClass eq\nuidNumber,gidNumber eq" +ENV LDAP_DOMAIN_DN="" # olcDbIndex attribute for domain entry (newline-separated) -ENV LDAP_DOMAIN_OUS="People Alias Group" +ENV LDAP_DOMAIN_INDEX="cn,uid eq\nmember,memberUid eq\nobjectClass eq\nuidNumber,gidNumber eq" # domain OUs (space-separated) -ENV LDAP_MEMBEROF="true" +ENV LDAP_DOMAIN_OUS="People Alias Group" # enable memberOf module -ENV LDAP_SCHEMAS="core cosine inetorgperson misc nis" +ENV LDAP_MEMBEROF="true" +# enable replication provider +ENV LDAP_PROVIDER="false" +# replicator CN => dn: cn=%%REPLICATOR_CN%%,%%DOMAIN_DN%% +ENV LDAP_REPLICATOR_CN="replicator" +# replicator password +ENV LDAP_REPLICATOR_PASSWORD="${LDAP_ADMIN_PASSWORD}" # space-separated list of schemas to load +ENV LDAP_SCHEMAS="core cosine inetorgperson misc nis" RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y \ diff --git a/entrypoint.sh b/entrypoint.sh index b6b7d07..e42d7ae 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,34 +6,45 @@ assert(){ [[ $? -eq 0 ]] || { [[ -n ${1} ]] && echo ${@} ; exit 1 ; } } # slapd is absurdly high. See https://github.com/docker/docker/issues/8231 ulimit -n 8192 -echo "I: running slapd for initial setup..." slapd -u openldap -g openldap -h ldapi:/// -assert "E: openldap died unexpectedly!" +assert "FATAL: sldapd died unexpectedly!" PIDFILE=$(ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b "cn=config" -s base \ "" olcPidFile | grep olcPidFile | awk "{print $2}") -echo "I: slapd running with PID ${PIDFILE}" +echo "slapd running. pidfile = ${PIDFILE}" + +[[ -n "${LDAP_DOMAIN}" ]] +assert "FATAL: Please set LDAP_DOMAIN and retry." +DN0="dc=${LDAP_DOMAIN//./,dc=}" +LDAP_DOMAIN_DN=${LDAP_DOMAIN_DN:=${DN0}} + +echo "setting up domain = ${LDAP_DOMAIN}, dn = ${LDAP_DOMAIN_DN}" [[ -n "${LDAP_CONFIG_PASSWORD}" ]] -assert "E: please set non-empty password in LDAP_CONFIG_PASSWORD and retry." +assert "FATAL: Please set LDAP_CONFIG_PASSWORD and retry." +LDAP_CONFIG_PWHASH=$(slappasswd -h "{SSHA}" -s "${LDAP_CONFIG_PASSWORD}") -HASHED_PW=$(slappasswd -h "{SSHA}" -s "${LDAP_CONFIG_PASSWORD}") +[[ -n "${LDAP_ADMIN_PASSWORD}" ]] +assert "FATAL: Please set LDAP_ADMIN_PASSWORD and retry." +LDAP_ADMIN_PWHASH=$(slappasswd -h "{SSHA}" -s "${LDAP_ADMIN_PASSWORD}") -echo "I: Setting administrator password..." +# TODO: verify password before updating ======================================= + +echo "Setting cn=admin,cn=config password" ldapmodify -Y EXTERNAL -H ldapi:/// <