# ldapdock *_a configurable secure openLDAP based container_* Step by step approach on how to setup and run an openLDAP server on a systemd-less docker image container ## _1- Creating the ldapdock image container_ build ldapdock from the dockerfile and run into it, creating the proper volumes to save databases data, config data, and certs data ``` > docker build -t ldapdock /path/to/dockerfile ``` ``` > docker run -i -t -p 389:389 -p 636:636 -h example.com -v ldap_data:/var/lib/ldap -v ldap_config:/etc/ldap/slapd.d -v ldap_certs:/etc/ldap/certs ldapdock ``` ## _2- Run the openLDAP server and populate a directory_ Use the following command to start openLDAP ``` root@example:/# slapd -h "ldap:/// ldapi:/// ldaps:///" -g openldap -u openldap ``` Create some groups and users to populate a directory ``` root@example:/# cat > add_content.ldif << EOF dn: ou=People,dc=example,dc=com objectClass: organizationalUnit ou: People dn: ou=Groups,dc=example,dc=com objectClass: organizationalUnit ou: Groups dn: cn=mages,ou=Groups,dc=example,dc=com objectClass: posixGroup cn: mages gidNumber: 5000 memberUid: marisa dn: uid=marisa,ou=People,dc=example,dc=com objectClass: inetOrgPerson objectClass: posixAccount objectClass: shadowAccount uid: marisa sn: Kirisame givenName: Marisa cn: Marisa Kirisame displayName: Marisa Kirisame uidNumber: 10000 gidNumber: 5000 userPassword: {CRYPT}x gecos: Marisa Kirisame loginShell: /bin/bash homeDirectory: /home/marisa EOF ``` When creating the groups and users, we will be asked the openLDAP root password (default: admin) ``` root@example:/# ldapadd -x -D cn=admin,dc=example,dc=com -W -f add_content.ldif ``` Notice the userPassword is invalid, let's set a proper one ``` root@example:/# ldappasswd -x -D cn=admin,dc=example,dc=com -W -S uid=marisa,ou=people,dc=example,dc=com ``` When setting up the password, we will be asked:\ 1-the password for the user marisa (qwerty), 2-reenter the password for marisa, 3-the openLDAP root password (admin) ## _3- Add schemas_ Let's add one of the policy schemas that comes with openLDAP, these files can be found in /etc/ldap/schema/. The pre-installed schemas exists in both converted .ldif files that can be loaded directly, as well native .schema formats which can be converted to .ldif files with the package schema2ldif (not loaded by default in this container) if neccesary. ``` root@example:/# ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/corba.ldif adding new entry "cn=corba,cn=schema,cn=config" ``` The following schemas will be loaded by default: ``` root@example:/# ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn dn: cn=schema,cn=config dn: cn={0}core,cn=schema,cn=config dn: cn={1}cosine,cn=schema,cn=config dn: cn={2}nis,cn=schema,cn=config dn: cn={3}inetorgperson,cn=schema,cn=config dn: cn={4}corba,cn=schema,cn=config ``` ## _4- Configure TLS/SSL certificates_ Create cert directories and generate certificates ``` root@example:/# mkdir -p /etc/ldap/certs root@example:/# cd /etc/ldap/certs ``` CA key ``` root@example:/etc/ldap/certs# certtool --generate-privkey --bits 4096 --outfile ca-key.pem ``` CA template ``` root@example:/etc/ldap/certs# cat > ca.info < ldap01.info < ldap01_slapd_cert_full.pem chown root:openldap ldap01_slapd_cert_full.pem chmod 640 ldap01_slapd_cert_full.pem ```