Difference between revisions of "Installation and configuration of basic openLDAP server"

From Notes_Wiki
(Created page with "=Installation and configuration of basic openLDAP server= ==Install ldap server== To install ldap server use: <pre> yum -y install openldap-servers openldap-clients openldap...")
 
m
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Installation and configuration of basic openLDAP server=
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[LDAP servers]] > [[OpenLDAP]] > [[Installation and configuration of basic openLDAP server|Basic OpenLDAP server configuration]]


==Install ldap server==
=LDAP Basics=
Basic theory of LDAP is mentioned at [[Basic_theory_of_ldap]].  It is important to be familiar with basic terminology before trying simple LDAP server setup.


To install ldap server use:
<pre>
yum -y install openldap-servers openldap-clients openldap
</pre>


Also ensure that folder '<tt>/var/lib/ldap</tt>' exists and is owned by '<tt>ldap:ldap</tt>'
=Setup basic LDAP server with base DN=
# Install required packages:
#:<pre>
#::    yum -y install openldap-servers openldap-clients openldap
#:</pre>
# Create '<tt>/etc/openldap/slapd.conf</tt>' file with following contents:
#:<pre>
#::    include          /etc/openldap/schema/core.schema
#::    include          /etc/openldap/schema/cosine.schema
#::    include          /etc/openldap/schema/inetorgperson.schema
#::    pidfile          /var/run/openldap/slapd.pid
#::    argsfile        /var/run/openldap/slapd.args
#::    defaultsearchbase  "dc=sbarjatiya,dc=com"
#::
#::    database        bdb
#::    suffix          "dc=sbarjatiya,dc=com"
#::    rootdn          "cn=root,dc=sbarjatiya,dc=com"
#::    rootpw          rekall123
#::    directory        /var/lib/ldap
#:</pre>
# Start LDAP using '<tt>slapd -f /etc/openldap/slapd.conf</tt>' command.  Do not use '<tt>service openldap start</tt>' as that would use '<tt>/etc/openldap/slapd.d</tt>' with '<tt>cn=config</tt>' style configuration, which is not being used here. 
# Verify that slapd is running using '<tt>ps aux | grep slapd</tt>'
# Create an organization entry LDIF file named '<tt>sbarjatiya.com.ldif</tt>' with following contents:
#:<pre>
#::    #Main ldap base entry
#::    dn: dc=sbarjatiya,dc=com
#::    objectClass: dcObject
#::    objectClass: organization
#::    #dc is must for dcObject
#::    dc: sbarjatiya
#::    #o is must for organization
#::    o: Barjatiya Softwares
#::    description: This is main domain for sbarjatiya company
#:</pre>
# Add the entry to ldap database using:
#:<pre>
#::    ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f sbarjatiya.com.ldif -W
#:</pre>
#::and enter password '<tt>rekall123</tt>' as mentioned in slapd.conf
# Search for all entries in LDAP server using: '<tt>ldapsearch -x</tt>'.  You should see the organization entry that was added.
# To see all entries in LDIF format use: '<tt>ldapsearch -x -LLL</tt>'.
# Note that the search command requires a base dn to work with.  Since we have specified '<tt>defaultsearchbase</tt>' in '<tt>slapd.conf</tt>' configuration file, that base is being used when we have not specified base explicitly.  To specify search base explicitly while searching use:
#:<pre>
#::    ldapsearch -x -LLL -b 'dc=sbarjatiya,dc=com'
#:</pre>


 
=About LDIF files=
LDIF files have following different types of lines:
# Lines that start with # are treated as comment lines
# Lines that start with space are treated as continuation of previous attribute line
# Lines that start with - are used to terminate changetype:modify directive
# Lines that are completely blank are treated as new lines (no-effect).
# Lines that are not-blank and do not start with space, - or # are treated as attribute lines.


 
All modifications to LDAP database are performed using LDIF files and one among ldapadd, ldapmodify or ldapdelete commands.
==Basic ldap configuration==
 
Very basic ldap configuration is:
<pre>
include          /etc/openldap/schema/core.schema
include          /etc/openldap/schema/cosine.schema
include          /etc/openldap/schema/inetorgperson.schema
pidfile          /var/run/openldap/slapd.pid
argsfile        /var/run/openldap/slapd.args
database       bdb
suffix          "dc=sbarjatiya,dc=com"
rootdn          "cn=owner,dc=sbarjatiya,dc=com"
rootpw          iiit123
directory        /var/lib/ldap
</pre>
The file should have permissions 400 with owner ldap:ldap.
 
One can also edit file '<tt>/etc/sysconfig/ldap</tt>' to change '<tt>SLAPD_LDAPS</tt>' to yes to enable SASL based binding for ldap.




=Creating organisation units, users and groups=
==Creating organisation units (ou)==
#Create LDIF file '<tt>people,groups.sbarjatiya.com.ldif</tt>' with following contents:
#:<pre>
#::      dn: ou=people,dc=sbarjatiya,dc=com
#::      objectClass: organizationalUnit
#::      ou: people
#::      description: All people in organisation
#::
#::      dn: ou=groups,dc=sbarjatiya,dc=com
#::      objectClass: organizationalUnit
#::      ou: groups
#::      description: All groups in organisation
#:</pre>
# Add both groups to database using:
#:<pre>
#::      ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f people,groups.sbarjatiya.com.ldif -W
#:</pre>
# Verify that things got added using '<tt>ldapsearch -x -LLL</tt>'
# To list only organizationUnit entries in search use:
#:<pre>
#::      ldapsearch -x -LLL '(objectClass=organizationalUnit)'
#:</pre>




==Starting ldap==
==Create user==  
# Create LDIF file '<tt>saurabh.people.sbarjatiya.com.ldif</tt>' with following contents:
#:<pre>
#::      dn: cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com
#::      objectClass: inetOrgPerson
#::      #Must due to person
#::      cn: Saurabh Barjatiya
#::      #Must due to person
#::      sn: Barjatiya
#::      uid: saurabhb
#::      mail: saurabhb@sbarjatiya.co.in
#::      mail: barjatiya.saurabh@gmail.com
#::      ou: people
#::      homePhone: 040 6653 1293
#::      displayName: Saurabh Barjatiya
#::      telephoneNumber: 93939 14337
#::      postalAddress: Hyderabad, India
#::      userPassword: rekall123
#:</pre>
# Add user to LDAP using:
#:<pre>
#::      ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f saurabh.people.sbarjatiya.com.ldif -W
#:</pre>
# Verify that entry is added using:
#:<pre>
#::      ldapsearch -x -LLL '(uid=sa*)'
#:</pre>


Start ldap server using:
Note dn for user could also have been
<pre>
<pre>
slapd -f /etc/openldap/slapd.conf
      dn: uid=saurabhb,ou=people,dc=sbarjatiya,dc=com
</pre>
so that conversion from uid to dn or dn to uid can be done with simple string manipulation without requiring any directory search.  In current case to find dn for '<tt>uid=saurabhb</tt>' following search would be required:
<pre>
    ldapsearch -x -LLL '(uid=saurabhb)' dn
</pre>
</pre>
 
'''Also note that this kind of user is not useful for authentication. For authentication posixAccount and shadowAccount objectclasses should be used as explained at [[Configuring authentication with openLDAP server]]'''
'''Do not user 'service slapd start' as for some reason the command is not using the correct configuration file.'''
 
Use command '<tt>ldapsearch -x  "context=*"</tt>' to verify that reported value of base matches with value specified in desired configuration file.
 




==LDIF configuration files==
==Create group==
# Create LDIF file '<tt>admins.groups.sbarjatiya.com.ldif</tt>' with following contents:
#:<pre>
#::      dn:cn=admins,ou=groups,dc=sbarjatiya,dc=com
#::      objectClass: groupOfNames
#::      cn: admins
#::      description: Set of administrators (system, network or desktop) for the organization.
#::      member: cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com
#:</pre>
#::Note that value for member is 'dn' for the member to be added to the group.
# Add the group to LDAP database using:
#:<pre>
#::      ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f admins.groups.sbarjatiya.com.ldif -W
#:</pre>
# Verify that values got added using:
#:<pre>
#::      ldapsearch -x -LLL '(cn=admins)'
#:</pre>
'''Note that same as mentioned for user above, the groups created in this manner are not useful for authentication purposes'''


LDIF files have following different types of lines:
*Lines that start with # are treated as comment lines
*Lines that start with space are treated as continuation of previous attribute line
*Lines that start with - are used to terminate changetype:modify directive
*Lines that are completely blank are treated as new lines (no-effect).
*Lines that are not-blank and do not start with space, - or # are treated as attribute lines.




===Sample ldif files===
Sample ldif configuration files are:


LDIF configuration for sbarjatiya.com domain
=Modifying or deleting entries=
<pre>
==Create some test entries==
#Main ldap base entry
dn: dc=sbarjatiya,dc=com
objectClass: dcObject
objectClass: organization
#dc is must for dcObject
dc: sbarjatiya
#o is must for organization
o: IIIT Hyderabad
description: This is homepage for Saurabh Barjatiya
</pre>


# Create LDIF file with following contents:
#:<pre>
#::      dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
#::      objectClass: inetOrgPerson
#::      #Must due to person
#::      cn: User One
#::      #Must due to person
#::      sn: One
#::      uid: user1
#::     
#::      dn: cn=User Two,ou=people,dc=sbarjatiya,dc=com
#::      objectClass: inetOrgPerson
#::      #Must due to personOpenLDAP server configuratioOpenLDAP server configuration|n|
#::      cn: User Two
#::      #Must due to person
#::      sn: Two
#::      uid: user2
#::     
#::      dn: cn=User Three,ou=people,dc=sbarjatiya,dc=com
#::      objectClass: inetOrgPerson
#::      #Must due to person
#::      cn: User Three
#::      #Must due to person
#::      sn: Three
#::      uid: user3
#:</pre>
# Add entries to the database using:
#:<pre>
#::      ldapadd -x -D "cn=root,dc=sbarjatiya,dc=com" -f <ldif_file> -W
#:</pre>
# Verify entries got added using:
#:<pre>
#::      ldapsearch -x -LLL '(uid=user*)'
#:</pre>


LDIF configuration for creating organizational units with name people and groups in sbarjatiya.com
<pre>
dn: ou=people,dc=sbarjatiya,dc=com
objectClass: organizationalUnit
ou: people
description: All people in organisation


dn: ou=groups,dc=sbarjatiya,dc=com
objectClass: organizationalUnit
ou: groups
description: All groups in organisation
</pre>


==Modify test entries==
===Add attributes===
# To add attributes to an existing entry create LDIF file with following contents:
#:<pre>
#::      dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
#::      changeType: modify
#::      add: mobile
#::      mobile: 93939 14337
#::      mobile: 86865 99552
#:</pre>
# Add attribute entries for user1 to the database using:
#:<pre>
#::      ldapmodify -x -D 'cn=root,dc=sbarjatiya,dc=com' -W -f <ldif-file>
#:</pre>
# Verify that attribute entries were added to user1 using:
#:<pre>
#::      ldapsearch -x -LLL '(uid=user1)'
#:</pre>


LDIF configuration file for creating a person entry as child entry in people ou
<pre>
dn: cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com
objectClass: inetOrgPerson
#Must due to person
cn: Saurabh Barjatiya
#Must due to person
sn: Barjatiya
uid: saurabh.barjatiya
mail: saurabh.barjatiya@iiit.ac.in
mail: barjatiya.saurabh@gmail.com
ou: people
homePhone: 040 6653 1293
displayName: Saurabh Barjatiya
telephoneNumber: 93939 14337
postalAddress: OFQ F2, IIIT Hyderabad
</pre>


LDIF configuration file for creating a group of persons called owners as child entry in group ou
<pre>
dn:cn=owners,ou=groups,dc=sbarjatiya,dc=com
objectClass: groupOfNames
cn: owners
description: Owners of the organization
member: cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com
</pre>


===Replace attributes===
# To replace attributes of an existing entry create LDIF file with following contents:
#:<pre>
#::      dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
#::      changeType: modify
#::      replace: mobile
#::      mobile: 93297 33122
#::      mobile: 93000 33122
#:</pre>
# Replate attribute entries for user1 in the database using:
#:<pre>
#::      ldapmodify -x -D 'cn=root,dc=sbarjatiya,dc=com' -W -f <ldif-file>
#:</pre>
# Verify that attribute entries were modified using:
#:<pre>
#::      ldapsearch -x -LLL '(uid=user1)'
#:</pre>




==Managing DIT==
===Removing attribute values===
# To remove attributes to an existing entry create LDIF file with following contents:
#:<pre>
#::      dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
#::      changeType: modify
#::      delete: mobile
#:</pre>
# Delete attribute entries for user1 in the database using:
#:<pre>
#::      ldapmodify -x -D 'cn=root,dc=sbarjatiya,dc=com' -W -f <ldif-file>
#:</pre>
# Verify that attribute entries were deleted using:
#:<pre>
#::      ldapsearch -x -LLL '(uid=user1)'
#:</pre>


===Adding an LDIF file to DIT===


To add a LDIF file to DIT use:
===Multiple modifications===
It is possible to do multiple modifications to same entry using LDIF file such as:
<pre>
<pre>
ldapadd -x -D "cn=owner,dc=sbarjatiya,dc=com" -f <ldif_file> -W
    dn: cn=User One,ou=People,dc=sbarjatiya,dc=com
    changeType: modify
    add: mobile
    mobile: 93939 14337
    mobile: 86865 99552
    -
    add: mail
    mail: saurabh.barjatiya@yahoo.com
    mail: saurabh.barjatiya@hotmail.com
    -
    replace: userPassword
    userPassword: rekall123
    -
    replace: postalAddress
    postalAddress: Hyderabad, India
</pre>
</pre>
Then enter 'rootpw' as mentioned in slapd.conf to add the entry. One can also use '-w &Lt;password&gt;' to supply password directly on command-line so that there is no separate password prompt.




===Multiple entry modifications===
It is also possible to modify attributes across DNs using LDIF file such as:
<pre>
    dn: cn=User Two,ou=People,dc=sbarjatiya,dc=com
    changeType: modify
    add: mobile
    mobile: 93939 14337
    mobile: 86865 99552
    -
    replace: userPassword
    userPassword: rekall123


===Deleting a ldap entry===
    dn: cn=User Three,ou=People,dc=sbarjatiya,dc=com
 
    changeType: modify
To delete an ldap entry use:
    add: mobile
<pre>
    mobile: 93939 14337
ldapdelete -x -D "cn=owner,dc=sbarjatiya,dc=com" -W <dn_to_be_deleted>
    mobile: 86865 99552
    -
    replace: userPassword
    userPassword: rekall123
</pre>
</pre>




===Syntax of modification LDIF files===
Modification LDIF files use following syntax:
* 'changeType: modify' is used to indicate that entry will be modified
* 'add: <attribute>' is used to indicate that given attributes should be added or appended. Any existing attribute values will remain unaffected.
* 'delete: <attribute>' is used to indicate that all values for given attribute should be deleted
* 'replace: <attribute>' is used to indicate that delete all existing values for given attribute and add the given values in their place.
* Hypen '-' is required to terminate a changeType directive such as add, replace or delete. The last directive is not required to be followed by a hypen.
* If more than one entry is to be modified then two modification entries should be separated by a blank line.


===Modifying existing entries===
To modify entries we can create an ldif file similar to:
<pre>
dn: cn=Saurabh Barjatiya,ou=People,dc=sbarjatiya,dc=com
changeType: modify
add: mobile
mobile: 93939 14337
mobile: 86865 99552
-
delete: telephoneNumber
-
add: mail
mail: saurabh.barjatiya@yahoo.com
mail: saurabh.barjatiya@hotmail.com
-
replace: userPassword
userPassword: iiit123
-
replace: postalAddress
postalAddress: Staff Quarters F2, IIIT Hyderabad
</pre>
Here:
*'<tt>changeType: modify</tt>' is used to indicate that entry will be modified
*'<tt>add: mobile</tt>' is used to indicate that given mobile attributes should be added. Any existing mobile attribute values will remain unaffected.
*'<tt>delete: telephoneNumber</tt>' is used to indicate that all values for attribute telephoneNumber should be deleted
*'<tt>replace: userPassword</tt>' is used to indicate that delete all existing values for attribute userPassword and add the given values in their place.
*Hypen '<tt>-</tt>' is required to terminate a changeType directive such as add, replace or delete. The last directive is not required to be followed by a hypen.
*If more than one entry is to be modified then two modification entries should be separated by a blank line. For example:
<pre>
dn: dc=sbarjatiya,dc=com
changeType: modify
replace: description
description: Test description


dn: ou=People,dc=sbarjatiya,dc=com
changeType: modify
replace: description
description: Test description for people
</pre>


To modify entries using above ldif file use:
==Deleting test entries==
===To delete entries use===
<pre>
<pre>
ldapmodify -x -D "cn=owner,dc=sbarjatiya,dc=com" -W -f <file_name>
    ldapdelete -x -D "cn=root,dc=sbarjatiya,dc=com" -W 'cn=User One,ou=people,dc=sbarjatiya,dc=com'
    ldapdelete -x -D "cn=root,dc=sbarjatiya,dc=com" -W 'cn=User Two,ou=people,dc=sbarjatiya,dc=com'
    ldapdelete -x -D "cn=root,dc=sbarjatiya,dc=com" -W 'cn=User Three,ou=people,dc=sbarjatiya,dc=com'
</pre>
</pre>






==Searching in LDAP database==
=Searching in LDAP database=


Use following to search for all entries in dc=sbarjatiya,dc=com:
Use following to search for all entries in dc=sbarjatiya,dc=com:
Line 227: Line 353:




==Bind mechanisms==
=Bind mechanisms=


===Anonymous binding===
==Anonymous binding==


To bind with ldap server anonymously use '<tt>-x</tt>' option in most ldap command such as:
To bind with ldap server anonymously use '<tt>-x</tt>' option in most ldap command such as:
Line 237: Line 363:




===Simple binding===
==Simple binding==


To bind with ldap server with password use '<tt>-D</tt>' to specify bind dn and '<tt>-W</tt>' or '<tt>-w</tt>' to specify password:
To bind with ldap server with password use '<tt>-D</tt>' to specify bind dn and '<tt>-W</tt>' or '<tt>-w</tt>' to specify password:
Line 246: Line 372:




===Disabling anonymous bind===
==Disabling anonymous bind==


To disable anonymous bind, use following line in '<tt>slapd.conf</tt>' file:
To disable anonymous bind, use following line in '<tt>slapd.conf</tt>' file:
Line 254: Line 380:




===Disabling simple bind===
==Disabling simple bind==


To disable simple bind, use following line in '<tt>slapd.conf</tt>' file:
To disable simple bind, use following line in '<tt>slapd.conf</tt>' file:
Line 267: Line 393:




==Configuring indexing==
=Configuring indexing=


For configuring indexing for database bdb one can use configuration similar to:
For configuring indexing for database bdb one can use configuration similar to:
Line 360: Line 486:
checkpoint 1024 5
checkpoint 1024 5
</pre>
</pre>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[LDAP servers]] > [[OpenLDAP]] > [[Installation and configuration of basic openLDAP server|Basic OpenLDAP server configuration]]

Latest revision as of 15:06, 13 March 2022

Home > CentOS > CentOS 6.x > LDAP servers > OpenLDAP > Basic OpenLDAP server configuration

LDAP Basics

Basic theory of LDAP is mentioned at Basic_theory_of_ldap. It is important to be familiar with basic terminology before trying simple LDAP server setup.


Setup basic LDAP server with base DN

  1. Install required packages:
    yum -y install openldap-servers openldap-clients openldap
  2. Create '/etc/openldap/slapd.conf' file with following contents:
    include /etc/openldap/schema/core.schema
    include /etc/openldap/schema/cosine.schema
    include /etc/openldap/schema/inetorgperson.schema
    pidfile /var/run/openldap/slapd.pid
    argsfile /var/run/openldap/slapd.args
    defaultsearchbase "dc=sbarjatiya,dc=com"
    database bdb
    suffix "dc=sbarjatiya,dc=com"
    rootdn "cn=root,dc=sbarjatiya,dc=com"
    rootpw rekall123
    directory /var/lib/ldap
  3. Start LDAP using 'slapd -f /etc/openldap/slapd.conf' command. Do not use 'service openldap start' as that would use '/etc/openldap/slapd.d' with 'cn=config' style configuration, which is not being used here.
  4. Verify that slapd is running using 'ps aux | grep slapd'
  5. Create an organization entry LDIF file named 'sbarjatiya.com.ldif' with following contents:
    #Main ldap base entry
    dn: dc=sbarjatiya,dc=com
    objectClass: dcObject
    objectClass: organization
    #dc is must for dcObject
    dc: sbarjatiya
    #o is must for organization
    o: Barjatiya Softwares
    description: This is main domain for sbarjatiya company
  6. Add the entry to ldap database using:
    ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f sbarjatiya.com.ldif -W
    and enter password 'rekall123' as mentioned in slapd.conf
  7. Search for all entries in LDAP server using: 'ldapsearch -x'. You should see the organization entry that was added.
  8. To see all entries in LDIF format use: 'ldapsearch -x -LLL'.
  9. Note that the search command requires a base dn to work with. Since we have specified 'defaultsearchbase' in 'slapd.conf' configuration file, that base is being used when we have not specified base explicitly. To specify search base explicitly while searching use:
    ldapsearch -x -LLL -b 'dc=sbarjatiya,dc=com'


About LDIF files

LDIF files have following different types of lines:

  1. Lines that start with # are treated as comment lines
  2. Lines that start with space are treated as continuation of previous attribute line
  3. Lines that start with - are used to terminate changetype:modify directive
  4. Lines that are completely blank are treated as new lines (no-effect).
  5. Lines that are not-blank and do not start with space, - or # are treated as attribute lines.

All modifications to LDAP database are performed using LDIF files and one among ldapadd, ldapmodify or ldapdelete commands.


Creating organisation units, users and groups

Creating organisation units (ou)

  1. Create LDIF file 'people,groups.sbarjatiya.com.ldif' with following contents:
    dn: ou=people,dc=sbarjatiya,dc=com
    objectClass: organizationalUnit
    ou: people
    description: All people in organisation
    dn: ou=groups,dc=sbarjatiya,dc=com
    objectClass: organizationalUnit
    ou: groups
    description: All groups in organisation
  2. Add both groups to database using:
    ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f people,groups.sbarjatiya.com.ldif -W
  3. Verify that things got added using 'ldapsearch -x -LLL'
  4. To list only organizationUnit entries in search use:
    ldapsearch -x -LLL '(objectClass=organizationalUnit)'


Create user

  1. Create LDIF file 'saurabh.people.sbarjatiya.com.ldif' with following contents:
    dn: cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com
    objectClass: inetOrgPerson
    #Must due to person
    cn: Saurabh Barjatiya
    #Must due to person
    sn: Barjatiya
    uid: saurabhb
    mail: saurabhb@sbarjatiya.co.in
    mail: barjatiya.saurabh@gmail.com
    ou: people
    homePhone: 040 6653 1293
    displayName: Saurabh Barjatiya
    telephoneNumber: 93939 14337
    postalAddress: Hyderabad, India
    userPassword: rekall123
  2. Add user to LDAP using:
    ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f saurabh.people.sbarjatiya.com.ldif -W
  3. Verify that entry is added using:
    ldapsearch -x -LLL '(uid=sa*)'

Note dn for user could also have been

      dn: uid=saurabhb,ou=people,dc=sbarjatiya,dc=com

so that conversion from uid to dn or dn to uid can be done with simple string manipulation without requiring any directory search. In current case to find dn for 'uid=saurabhb' following search would be required:

 
     ldapsearch -x -LLL '(uid=saurabhb)' dn

Also note that this kind of user is not useful for authentication. For authentication posixAccount and shadowAccount objectclasses should be used as explained at Configuring authentication with openLDAP server


Create group

  1. Create LDIF file 'admins.groups.sbarjatiya.com.ldif' with following contents:
    dn:cn=admins,ou=groups,dc=sbarjatiya,dc=com
    objectClass: groupOfNames
    cn: admins
    description: Set of administrators (system, network or desktop) for the organization.
    member: cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com
    Note that value for member is 'dn' for the member to be added to the group.
  2. Add the group to LDAP database using:
    ldapadd -x -D 'cn=root,dc=sbarjatiya,dc=com' -f admins.groups.sbarjatiya.com.ldif -W
  3. Verify that values got added using:
    ldapsearch -x -LLL '(cn=admins)'

Note that same as mentioned for user above, the groups created in this manner are not useful for authentication purposes



Modifying or deleting entries

Create some test entries

  1. Create LDIF file with following contents:
    dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
    objectClass: inetOrgPerson
    #Must due to person
    cn: User One
    #Must due to person
    sn: One
    uid: user1
    dn: cn=User Two,ou=people,dc=sbarjatiya,dc=com
    objectClass: inetOrgPerson
    #Must due to personOpenLDAP server configuratioOpenLDAP server configuration|n|
    cn: User Two
    #Must due to person
    sn: Two
    uid: user2
    dn: cn=User Three,ou=people,dc=sbarjatiya,dc=com
    objectClass: inetOrgPerson
    #Must due to person
    cn: User Three
    #Must due to person
    sn: Three
    uid: user3
  2. Add entries to the database using:
    ldapadd -x -D "cn=root,dc=sbarjatiya,dc=com" -f <ldif_file> -W
  3. Verify entries got added using:
    ldapsearch -x -LLL '(uid=user*)'


Modify test entries

Add attributes

  1. To add attributes to an existing entry create LDIF file with following contents:
    dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
    changeType: modify
    add: mobile
    mobile: 93939 14337
    mobile: 86865 99552
  2. Add attribute entries for user1 to the database using:
    ldapmodify -x -D 'cn=root,dc=sbarjatiya,dc=com' -W -f <ldif-file>
  3. Verify that attribute entries were added to user1 using:
    ldapsearch -x -LLL '(uid=user1)'


Replace attributes

  1. To replace attributes of an existing entry create LDIF file with following contents:
    dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
    changeType: modify
    replace: mobile
    mobile: 93297 33122
    mobile: 93000 33122
  2. Replate attribute entries for user1 in the database using:
    ldapmodify -x -D 'cn=root,dc=sbarjatiya,dc=com' -W -f <ldif-file>
  3. Verify that attribute entries were modified using:
    ldapsearch -x -LLL '(uid=user1)'


Removing attribute values

  1. To remove attributes to an existing entry create LDIF file with following contents:
    dn: cn=User One,ou=people,dc=sbarjatiya,dc=com
    changeType: modify
    delete: mobile
  2. Delete attribute entries for user1 in the database using:
    ldapmodify -x -D 'cn=root,dc=sbarjatiya,dc=com' -W -f <ldif-file>
  3. Verify that attribute entries were deleted using:
    ldapsearch -x -LLL '(uid=user1)'


Multiple modifications

It is possible to do multiple modifications to same entry using LDIF file such as:

    dn: cn=User One,ou=People,dc=sbarjatiya,dc=com
    changeType: modify
    add: mobile
    mobile: 93939 14337
    mobile: 86865 99552
    -
    add: mail
    mail: saurabh.barjatiya@yahoo.com
    mail: saurabh.barjatiya@hotmail.com
    -
    replace: userPassword
    userPassword: rekall123
    -
    replace: postalAddress
    postalAddress: Hyderabad, India


Multiple entry modifications

It is also possible to modify attributes across DNs using LDIF file such as:

    dn: cn=User Two,ou=People,dc=sbarjatiya,dc=com
    changeType: modify
    add: mobile
    mobile: 93939 14337
    mobile: 86865 99552
    -
    replace: userPassword
    userPassword: rekall123

    dn: cn=User Three,ou=People,dc=sbarjatiya,dc=com
    changeType: modify
    add: mobile
    mobile: 93939 14337
    mobile: 86865 99552
    -
    replace: userPassword
    userPassword: rekall123


Syntax of modification LDIF files

Modification LDIF files use following syntax:

  • 'changeType: modify' is used to indicate that entry will be modified
  • 'add: <attribute>' is used to indicate that given attributes should be added or appended. Any existing attribute values will remain unaffected.
  • 'delete: <attribute>' is used to indicate that all values for given attribute should be deleted
  • 'replace: <attribute>' is used to indicate that delete all existing values for given attribute and add the given values in their place.
  • Hypen '-' is required to terminate a changeType directive such as add, replace or delete. The last directive is not required to be followed by a hypen.
  • If more than one entry is to be modified then two modification entries should be separated by a blank line.


Deleting test entries

To delete entries use

    ldapdelete -x -D "cn=root,dc=sbarjatiya,dc=com" -W 'cn=User One,ou=people,dc=sbarjatiya,dc=com'
    ldapdelete -x -D "cn=root,dc=sbarjatiya,dc=com" -W 'cn=User Two,ou=people,dc=sbarjatiya,dc=com'
    ldapdelete -x -D "cn=root,dc=sbarjatiya,dc=com" -W 'cn=User Three,ou=people,dc=sbarjatiya,dc=com'


Searching in LDAP database

Use following to search for all entries in dc=sbarjatiya,dc=com:

ldapsearch -x -LLL -b "dc=sbarjatiya,dc=com"


Use following to search for all entries in ou people:

ldapsearch -x -LLL -b "ou=people,dc=sbarjatiya,dc=com"


Use following to search for all entries in ou people and list only dn, cn and sn attributes of the entries:

ldapsearch -x -LLL -b "ou=people,dc=sbarjatiya,dc=com" dn cn sn


Use following to search for all entries where 'cn=Saurabh Barjatiya':

ldapsearch -x -LLL -b "dc=sbarjatiya,dc=com" '(cn=Saurabh Barjatiya)'

Use following to search for all entries where 'cn=Saurabh Barjatiya': and list only sn attribute

ldapsearch -x -LLL -b "dc=sbarjatiya,dc=com" '(cn=Saurabh Barjatiya)' sn

Note: that dn will also get listed automatically.


Overall ldapsearch has following options:

  • '-x' to bind to server for searching. Since we have not specified -D '<dn>' and -W or -w, the binding would be anonymous.
  • '-LLL' to list in the ldif format.
  • '-b' to speceify base from where search should start
  • filter enclosed in () in filter format
  • list of attributes to be displayed for matched entries


Bind mechanisms

Anonymous binding

To bind with ldap server anonymously use '-x' option in most ldap command such as:

ldapwhoami -x


Simple binding

To bind with ldap server with password use '-D' to specify bind dn and '-W' or '-w' to specify password:

ldapwhoami -x -D "cn=owner,dc=sbarjatiya,dc=com" -W


Disabling anonymous bind

To disable anonymous bind, use following line in 'slapd.conf' file:

disallow bind_anon


Disabling simple bind

To disable simple bind, use following line in 'slapd.conf' file:

disallow simple_bind




Configuring indexing

For configuring indexing for database bdb one can use configuration similar to:

index default eq,pres
index uid eq
index cn,gn,mail eq,sub
index sn eq,sub
index ou eq
index telephonenumber eq

These lines should be added to '/etc/openldap/slapd.conf' file after database specification. Here

eq
Index for equality tests without use of wildcard
sub
Index for substrings. There are three sub-categories of this index subinitial, subany and subfinal.
subinitail
Index for string starting with given part such as 'cn=abc*'
subany
Index for strings containing given part such as 'cn=*abc*'
subfinal
index for strings terminating with given part such as 'cn=*abc'
approx
Index for approximate searches for sound-line such as 'cn~=person'
pres
Index for checking whether particular attribute is present or whether entry belongs to a given objectClass or not. such as 'objectClass=person' or 'attribute=mail'

If the configuration is done while creating an ldap server then indexes will be maintained automatically when entries are added or modified. But if a index entry is modified in an existing ldap server, then:

  1. ldap server should be stopped
  2. 'slapindex -f /etc/openldap/slapd.conf' command should be used to generated index based on configuration file
  3. Finally ldap server can be started again



ldap global configuration options

idleTimeout

Specify the number of seconds to wait before forcibly closing an idle client connection. An idletimeout of 0, the default, disables this feature.

Example:

idleTimeout 30


sizeLimit

This directive specifies the maximum number of entries to return from a search operation.

Default:

sizelimit 500

We can change limit for specific DNs using:

limits dn.exact="cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com" size=100000

Note that the limits do not apply to roodn.


timelimit

This directive specifies the maximum number of seconds (in real time) slapd will spend answering a search request. If a request is not finished in this time, a result indicating an exceeded timelimit will be returned.

Default:

timelimit 3600

We can create exception for specific DNs using:

limits dn.exact="cn=Saurabh Barjatiya,ou=people,dc=sbarjatiya,dc=com" time=3600

Note that the limits do not apply to roodn.




ldap database configuration options

checkpoint

This directive specifies how often to checkpoint the BDB transaction log. A checkpoint operation flushes the database buffers to disk and writes a checkpoint record in the log. The checkpoint will occur if either <kbyte> data has been written or <min> minutes have passed since the last checkpoint. Both arguments default to zero, in which case they are ignored. When the <min> argument is non-zero, an internal task will run every <min> minutes to perform the checkpoint.

checkpoint 1024 5


Home > CentOS > CentOS 6.x > LDAP servers > OpenLDAP > Basic OpenLDAP server configuration