Skip to content

Commit

Permalink
Adding basic LDAP server based on Apache DS / alpine for integration …
Browse files Browse the repository at this point in the history
…testing blended
  • Loading branch information
atooni committed Jul 11, 2019
1 parent 990c865 commit 7707662
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 2 deletions.
18 changes: 18 additions & 0 deletions apacheds-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM atooni/zulu-8-alpine:1.0
MAINTAINER Blended Team

ENV APACHEDS_VERSION 2.0.0.AM25
ENV APACHEDS_URL http://archive.apache.org/dist/directory/apacheds/dist/${APACHEDS_VERSION}/apacheds-${APACHEDS_VERSION}.tar.gz

RUN apk --no-cache add openldap-clients gettext vim bash

RUN curl ${APACHEDS_URL} | tar -xzC /opt \
&& ln -s $(ls -d /opt/apacheds*) /opt/apacheds

ADD files /opt/apacheds

RUN /bin/bash -l /opt/apacheds/scripts/configure.sh

ENTRYPOINT ["/bin/bash", "-l", "/opt/apacheds/scripts/run.sh" ]
EXPOSE 10389

4 changes: 4 additions & 0 deletions apacheds-alpine/files/ldif/admin_pwd.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dn: uid=admin,ou=system
changetype: modify
replace: userPassword
userPassword:: ${HASHED_PWD}
5 changes: 5 additions & 0 deletions apacheds-alpine/files/ldif/group.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dn: cn=${GROUP_NAME},ou=groups,o=${DOMAIN_NAME}
objectClass: top
objectClass: groupOfNames
cn: ${GROUP_NAME}
member: ${MEMBER}
4 changes: 4 additions & 0 deletions apacheds-alpine/files/ldif/groupAdd.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dn: cn=${GROUP_NAME},ou=groups,o=${DOMAIN_NAME}
changetype: modify
add: member
member: ${MEMBER}
28 changes: 28 additions & 0 deletions apacheds-alpine/files/ldif/partition.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 1

dn: ads-partitionId=${DOMAIN_NAME},ou=partitions,ads-directoryServiceId=default,ou=config
objectclass: ads-jdbmPartition
objectclass: ads-partition
objectclass: ads-base
objectclass: top
ads-partitionid: ${DOMAIN_NAME}
ads-partitionsuffix: o=${DOMAIN_NAME}
ads-enabled: TRUE
ads-jdbmpartitionoptimizerenabled: TRUE
ads-partitioncachesize: 10000
ads-partitionsynconwrite: TRUE

dn: ou=indexes,ads-partitionId=${DOMAIN_NAME},ou=partitions,ads-directoryServiceId=default,ou=config
objectclass: top
objectclass: organizationalUnit
ou: indexes

dn: ads-indexAttributeId=uid,ou=indexes,ads-partitionId=${DOMAIN_NAME},ou=partitions,ads-directoryServiceId=default,ou=config
objectclass: top
objectclass: ads-base
objectclass: ads-jdbmIndex
objectclass: ads-index
ads-indexattributeid: uid
ads-indexhasreverse: FALSE
ads-enabled: TRUE
ads-indexcachesize: 100
4 changes: 4 additions & 0 deletions apacheds-alpine/files/ldif/top_domain.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dn: o=${DOMAIN_NAME}
objectClass: organization
objectClass: top
o: ${DOMAIN_NAME}
9 changes: 9 additions & 0 deletions apacheds-alpine/files/ldif/top_objects.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dn: ou=groups,o=${DOMAIN_NAME}
objectClass: organizationalUnit
objectClass: top
ou: groups

dn: ou=users,o=${DOMAIN_NAME}
objectClass: organizationalUnit
objectClass: top
ou: users
9 changes: 9 additions & 0 deletions apacheds-alpine/files/ldif/user.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dn: uid=${USER},ou=users,o=${DOMAIN_NAME}
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
uid: ${USER}
cn: ${USER_CN}
sn: ${USER_SN}
userPassword:: ${USER_PWD}
111 changes: 111 additions & 0 deletions apacheds-alpine/files/scripts/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash

set -e

export DOMAIN_NAME=blended
export SYSTEM_PWD=blended

if [ "x${START_DELAY}" == "x" ]; then
START_DELAY=10
fi

APACHEDS_CMD=/opt/apacheds/bin/apacheds.sh

function shaPassword() {
pwd=`echo -n $1 | md5sum | awk '{print $1}' | xxd -r -p | base64`
export HASHED_PWD=`echo -n "{MD5}${pwd}" | base64`
}

function stopADS() {
${APACHEDS_CMD} stop
}

function startADS() {

if [[ -n "$1" ]]; then
START_MODE=$1
else
START_MODE=start
fi

${APACHEDS_CMD} $START_MODE

if [[ -n $2 ]]; then
sleep $2
fi
}

function restartADS() {
stopADS
startADS $*
}

function loadLdif() {
envsubst < /opt/apacheds/ldif/$2.ldif > /tmp/$2.ldif
ldapmodify -c -a -f /tmp/$2.ldif -h localhost -p 10389 -D "uid=admin,ou=system" -w $1
}

function addGroup {
export GROUP_NAME=$1
export MEMBER=$2
loadLdif $SYSTEM_PWD group
}

function addToGroup {
export GROUP_NAME=$1
export MEMBER=$2
loadLdif $SYSTEM_PWD groupAdd
}

function addUser {
export USER=$1
shift

export USER_CN=$1
shift

export USER_SN=$1
shift

shaPassword $1
export USER_PWD=$HASHED_PWD
shift

loadLdif $SYSTEM_PWD user
}

# Initially start the LDAP server
startADS start $START_DELAY

# then we change the admin password
#export HASHED_PWD=$SYSTEM_PWD
shaPassword $SYSTEM_PWD
loadLdif secret admin_pwd

# Restart to apply changes
restartADS start $START_DELAY

netstat -anp | grep 10389

# create a new partition
loadLdif $SYSTEM_PWD partition
ldapdelete -r -H ldap://localhost:10389 -D "uid=admin,ou=system" -w $SYSTEM_PWD "ads-partitionId=example,ou=partitions,ads-directoryServiceId=default,ou=config"
ldapdelete -r -H ldap://localhost:10389 -D "uid=admin,ou=system" -r -w $SYSTEM_PWD "dc=example,dc=com"

restartADS start $START_DELAY

# create the top level entries
loadLdif $SYSTEM_PWD top_domain
loadLdif $SYSTEM_PWD top_objects

addUser root "Main Admin" Administrator mysecret
addUser andreas "Andreas Gies" Gies mysecret
addUser tobias "Tobias Roeser" Roeser mysecret

addGroup admins "uid=root,ou=users,o=blended"
addToGroup admins "uid=andreas,ou=users,o=blended"

addGroup blended ""uid=blended,ou=users,o=blended""
addToGroup blended "uid=andreas,ou=users,o=blended"

${APACHEDS_CMD} stop
6 changes: 6 additions & 0 deletions apacheds-alpine/files/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

APACHEDS_CMD=/opt/apacheds/bin/apacheds.sh

${APACHEDS_CMD} start
top
5 changes: 3 additions & 2 deletions base-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# We use alpine 3.9 for now. With 3.10 we do see strange errors when we use
# Selenium and Google Chrome for head less browser testing
FROM alpine:3.9

MAINTAINER WoQ - Way of Quality GmbH - Blended
MAINTAINER WoQ - Way of Quality GmbH - Blended Team

ENV USER=blended
ENV UID=5000
Expand Down Expand Up @@ -28,4 +30,3 @@ RUN addgroup -g "${GID}" "${USER}" \
--uid "$UID" \
"$USER" \
&& chown -R $USER:$GROUP /home/$USER

Binary file removed build-alpine/.Dockerfile.swp
Binary file not shown.
18 changes: 18 additions & 0 deletions zulu-8-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The basic image to run Blended containers
FROM atooni/base-alpine:1.0

MAINTAINER Andreas Gies

ENV JAVA_URL=https://cdn.azul.com/zulu/bin/zulu8.38.0.13-ca-jdk8.0.212-linux_musl_x64.tar.gz
ENV SBT_URL=https://piccolo.link/sbt-1.2.8.tgz

# Installation section
ADD files/profile.d /etc/profile.d

# Download the tar files and explode them in one go to save
# image space
RUN mkdir -p /opt \
&& curl -L ${JAVA_URL} | tar -xzC /opt \
&& ln -s $(ls -d /opt/zulu*) /opt/java

# End of Installation section
File renamed without changes.

0 comments on commit 7707662

Please sign in to comment.