LDAP (Lightweight Directory Access Protocol) is a protocol used to store, organize, and access directory information in a structured way. It is commonly used for user authentication, access control, and identity management in networks, allowing multiple applications and systems to share a centralized directory of users and resources.
OpenLDAP is an open-source implementation of the LDAP. OpenLDAP is widely used in enterprise environments to manage identities and enforce security policies efficiently.
We will setup a ldap server using OpenLDAP and send some requests to the server.
$ apt install slapd ldap-utils
Create file /etc/ldap/slapd.conf.
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
pidfile /var/run/slapd/slapd.pid
argsfile /var/run/slapd/slapd.args
loglevel none
modulepath /usr/lib/ldap
moduleload back_mdb
database mdb
suffix "dc=example,dc=com"
rootdn "cn=Manager,dc=example,dc=com"
rootpw fakepass
directory /var/lib/ldap
access to attrs=userPassword
by anonymous auth
by self write
by * none
access to *
by self write
by * none
Validate configuration.
$ slaptest -v -f /etc/ldap/slapd.conf
Start slapd server.
$ slapd -f /etc/ldap/slapd.conf -h ldap://127.0.0.1:12345
Create file data.ldif
=example,dc=com
dn: dc
dc: example
o: example.com
objectClass: top
objectClass: dcObject
objectClass: organization
=users,dc=example,dc=com
dn: ou
ou: users
objectClass: organizationalUnit
=alice,ou=users,dc=example,dc=com
dn: uid
ou: users
uid: alice
sn: jane
cn: alex jane
objectClass: person
objectClass: organizationalPerson
objectClass: inetorgperson
Validate data.
$ slapadd -v -u -c -f /etc/ldap/slapd.conf -l data.ldif
Send ldapadd request.
$ ldapadd -x -H ldap://127.0.0.1:12345 -w fakepass -D 'cn=Manager,dc=example,dc=com' -f data.ldif
$ ldapsearch -x -H ldap://127.0.0.1:12345 -w fakepass -D 'cn=Manager,dc=example,dc=com' -b 'dc=example,dc=com'
$ ldapsearch -x -H ldap://127.0.0.1:12345 -w fakepass -D 'cn=Manager,dc=example,dc=com' -b 'ou=users,dc=example,dc=com'
$ ldapsearch -x -H ldap://127.0.0.1:12345 -w fakepass -D 'cn=Manager,dc=example,dc=com' -b 'uid=alice,ou=users,dc=example,dc=com'
$ ldapdelete -x -H ldap://127.0.0.1:12345 -w fakepass -D 'cn=Manager,dc=example,dc=com' 'uid=alice,ou=users,dc=example,dc=com'
$ slapcat
$ slapd -d 1 -f /etc/ldap/slapd.conf -h ldap://127.0.0.1:389
Problem: The below error message is shown when start slapd server.
Could not open config file “slapd.conf”: Permission denied.
Reason: AppArmor prevents slapd to open file from unconfigured folders.
$ dmesg
audit: type=1400 apparmor="DENIED" operation="open" class="file" profile="/usr/sbin/slapd"
name="/root/ldap/slapd.conf" pid=30197 comm="slapd" requested_mask="r" denied_mask="r"
Solution: Put slapd.conf in folder /etc/ldap.