Skip to content

Lesson 2 of 9 · 26m

Searches, Filters, Indexes, and Operational Attributes

Use ldapsearch deliberately, read real filter semantics, distinguish user data from server metadata, and diagnose slow searches.

Most directory incidents start as a search problem wearing a login problem's clothes. The account exists, the password is correct, and the bind succeeds, but the application searches the wrong base or uses a filter nobody indexed. A senior operator can read the filter before touching the server.

ldapsearch is the scalpel

A useful search names the connection, base, scope, filter, and attributes explicitly:

ldapsearch -x -H ldaps://ldap.sudosecurity.org   -D 'uid=readonly,ou=services,dc=sudosecurity,dc=org'   -W   -b 'ou=people,dc=sudosecurity,dc=org'   -s sub   '(uid=amorales)'   dn uid cn mail memberOf

Never settle for implicit defaults while debugging. If the application uses subtree scope and your manual test uses one-level scope, you are testing a different product.

Filters compose by prefix logic

LDAP filters are prefix expressions:

(&(objectClass=posixAccount)(uid=amorales))
(|(uid=amorales)(mail=amorales@*))
(&(objectClass=groupOfNames)(member=uid=amorales,ou=people,dc=sudosecurity,dc=org))
(!(loginDisabled=TRUE))

& means all clauses must match, | means any clause may match, and ! negates one clause. Wildcards are expensive when leading (mail=*@sudosecurity.org) because indexes cannot use them efficiently. Escaping matters too: *, (, ), \, and NUL have special meaning in assertion values.

Operational attributes are hidden until requested

A normal search returns user attributes, not every piece of server metadata. Ask for operational attributes explicitly:

ldapsearch ... '(uid=amorales)' '+' '*'

Useful operational attributes include entryUUID, createTimestamp, modifyTimestamp, creatorsName, modifiersName, pwdChangedTime, and replication state. On OpenLDAP, + means operational attributes and * means user attributes; request both when auditing.

Referrals and chasing explain strange emptiness

A search can return referrals instead of entries when the base or partition routes elsewhere. Many command-line clients do not chase referrals by default or chase them differently from application libraries. If a result is empty but the object exists, verify:

correct server? correct base? correct scope? ACL visibility? referral? filter match?

ACLs are particularly deceptive. LDAP usually does not say "unauthorized object exists"; it simply omits entries or attributes from results.

Indexing determines whether scale survives

An unindexed equality search over hundreds of thousands of entries becomes a full scan. In OpenLDAP, indexes live in database configuration:

olcDbIndex: objectClass eq
olcDbIndex: uid eq,pres
olcDbIndex: mail eq,sub
olcDbIndex: member eq

After changing indexes on an existing backend, run the appropriate index rebuild (slapindex for offline OpenLDAP maintenance or the server-specific procedure). In 389ds, inspect index configuration under cn=index entries and use the server tooling rather than hand-editing files.

Field notes

  • A search returning zero entries can mean no match, no permission, wrong base, wrong scope, or schema mismatch.
  • Test application filters exactly, including whitespace and objectClass clauses copied from configuration.
  • memberOf is often generated or overlay-managed; do not assume it is independently writable.
  • Latency distributed across many small searches is still directory load; connection pooling matters.

Was this lesson helpful?

Sign in to rate