LDAP
-
A protocol for querying a user directory, designed to work over
TCP/IP. -
An
LDAP entryis a collection of attributes. -
Entries are arranged in a tree structure, and are uniquely identified by a
Distinguished Name (DN)that is the path to that object in the tree. -
Hierarchical, from right (root) to left (node)
-
Derived from
X.500(opens in a new tab) standards, with lots of concepts and terms still in use. -
Resources
Concepts
Structure
LDAPdirectory servers present data arranged in tree-like hierarchies in which each entry may have zero or more subordinate entries. This structure is called theDirectory Information Tree, orDIT. Each tree has a single root entry, which is called the naming context (or in some servers, a suffix).- Creating a new
DIT(Directory Information Tree) involves the following steps:- Create a new
partition. - Create
suffix entry. - Create
additional entries.
- Create a new
- All
LDAPservers must expose a special entry, at the top of theLDAPserver directory information tree, called the rootDSE, whoseDNis the zero-length string. DN(Distinguished Name) is aLDAPentry that uniquely identifies and describes an entry in a directory (LDAP) server, a fully qualified path of names that trace the entry back to the root of the tree.RDN(Relative Distinguished Name) is a component of theDN.
Attribute
-
Abbreviation
- User ID :
uid - Common Name :
cn - Surname :
sn - Location :
l - Organizational Unit :
ou - Organization :
o - Domain Component :
dc - State :
st - Country :
c - Street address :
street
- User ID :
Filter
-
Only applies to attributes
-
And
-
Examples
(&(objectClass=person)(objectClass=user))
-
-
Or
-
Examples
(|(objectClass=person)(objectClass=user))
-
-
Not
-
Examples
(&(objectClass=group)(&(ou:dn:=Chicago)(!(ou:dn:=Wrigleyville))))
-
-
Wildcard
-
Wildcards are not supported when used in filters using ! (or NOT) logical operators.
-
Examples
(&(objectClass=user)(cn=*Marketing*))
-
-
Match part of
DN-
Examples
-
(&(objectClass=group)(ou:dn:=Chicago))Find groups with
OUcomponent of theirDNisChicago
-
-
-
Resources
Base
-
The base part of the
DN -
The
base DNis relative to theLDAP URIIf the
URIisldap://localhost:389/dc=example,dc=org, and thebase DNisou=people, the query will be based onldap://localhost:389/ou=people,dc=example,dc=org. So ifbase DNis already included inURI, no need to include it in the query.
LDIF
- Every line in a
LDIFis an attribute. - A plain text
LDAPData Interchange Format file - Can be opened by a
LDAPbrowser such asApache Directory Studio(opens in a new tab) - Directories often have at least one organization entry. Typically the organization entry is the first, or topmost entry in the directory. The organization entry often corresponds to the suffix set for the directory.
Authentication
BIND operation
-
Bind Authenticationis the most common mechanism for authenticating users withLDAP. In bind authentication, the user’s credentials (username and password) are submitted to theLDAPserver, which authenticates them. The advantage to using bind authentication is that the user’s secrets (the password) do not need to be exposed to clients, which helps to protect them from leaking. -
An
LDAP clienttransmits aBINDrequest to aLDAP serverin order to change the authorization state of the client connection. When aLDAP clientfirst connects to anLDAP server, the server sets the authorization state of the connection tounauthenticated. When the server receives aBINDrequest, the server sets the authorization state of the connection tounauthenticatedimmediately. Should theBINDrequest be successful, the server sets the authorization state of the connection to the state associated with theDNin theBINDrequest.LDAPv3allows a connection to change states any number of times, with the caveat that no requests be outstanding when theBINDrequest is received. -
Takeaway
- The
LDAP clientsends the password as part of theBIND request, and theLDAP servervalidates the password instead of the client. TheLDAP serverdoes not send the password back to the client and therefore no leaking of the password.
- The
-
Resources
bind account
openldap-clients
ldapsearch
# search result
search: 2
result: 32 No such object # 32 is result code, refer to result code reference at the bottom
# numResponses: 1 # 1 is the number of pieces of information returned including the meta information.
# numEntries: 84 # is the total number of entries that the search returned.Active Directory
Cheatsheet
Test Simple Authentication
-
ldapsearch -H ldap://<domain>:<port> -D '<bind_account_DN>' -w '<bind_account_password>' -b '<baseDN>' '(filters...)'e.g.
ldapsearch -H ldap://localhost:10389 -D 'cn=admin,dc=example,dc=org' -w 'adminpassword' -b 'ou=people,dc=example,dc=org' '(uid=userID)'
Return all entries in the directory
ldapsearch -h hostname -b "dc=example,dc=com" -s sub "objectclass=*"
Use LDAP_BASEDN environment variable
- Equivalent to
-bargument