Skip to content

LDAP search (ldap) ​

Connects to a directory server, binds anonymously or with an account, runs one search, and reports how long the whole exchange took and how many entries it found. It can also require that the entries have a given value in an attribute. Over StartTLS or LDAPS it reads the server's certificate from the same connection and reports how long it remains valid, so one sensor watches the directory and its certificate.

Use it to know that a directory answers searches, not only that its port is open: a server that accepts connections but cannot read its database fails the search, and a server whose replication broke shows up as an entry that is missing or has the old value.

What it looks like ​

The page of an ldap sensor in the light theme

The sensor's page after a few polls, searching the people below a directory's base over StartTLS and checking that one account is among them. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.

Channels ​

KeyNameUnitDefault limits
response_msResponse timemswarning above 1000, error above 5000
entry_countEntries foundnoneerror below 1
value_foundExpected value foundnoneerror below 1 (0 is Missing, 1 is Found); only with attribute and expected_value
cert_days_remainingDays until the certificate expiresdayswarning below 21, error below 7; only over StartTLS and LDAPS
chain_days_remainingDays until the earliest expiry in the chaindayswarning below 21, error below 7; only over StartTLS and LDAPS

response_ms covers everything from the first connection byte to the answer: connecting, the TLS handshake, the bind and the search. A search that finds nothing is not a failed poll: entry_count is 0 and the default limit turns the sensor Down. Clear that limit on a sensor that is meant to find nothing.

Parameters ​

ParameterDefaultMeaning
baserequiredWhere the search starts, as a distinguished name such as dc=example,dc=org. It may be empty only with scope base, which reads the server's root entry.
scopesubbase (the entry itself), one (the entries directly below it) or sub (it and everything below).
filter(objectClass=*)The search filter, as RFC 4515 writes it. Checked for balanced brackets when the sensor is saved.
securitynonenone (clear text), starttls (port 389, upgraded before anything is bound) or ldaps (TLS from the first byte).
port389, or 636 with ldapsTCP port.
size_limit1000The most entries the server is asked to return, 1 to 1000. When the server stops there, the message says "at least" and entry_count is the limit.
attribute, expected_valuenoneBoth or neither. At least one entry found must have expected_value among the values of attribute; the comparison ignores case.
server_namethe device's host name, else its addressThe name the certificate has to be valid for, and the name sent for SNI. Used with starttls and ldaps.
verify_tlstrueVerify the certificate against the probe host's trust store.
tls_fingerprintnoneTrust exactly the certificate with this SHA-256 fingerprint; then verify_tls is not needed.
check_certificatetrueReport the two certificate channels over TLS.

Suggested interval: 60 seconds. Credential: optional secret.

The bind login. Without a credential the search is anonymous. To bind, set a secret credential holding bind name:password, for example uid=monitor,ou=people,dc=example,dc=org:the password. The name is cut at the first colon, so a password may contain colons and the name may not. It is assigned like every secret credential, as the secret credential of the sensor, its device or a group above it; see credentials. It never appears in parameters, messages or logs. Use an account that can only read. A sensor that finds a secret meant for something else (a token with no colon) fails with kind config and says what form it needs.

Use TLS when you bind. With security none the password crosses the network as it is. Choose starttls or ldaps. A sensor that binds without TLS works, because some directories on a closed network offer nothing else, but anyone who can read that network can read the password.

Certificates ​

The same rules as the web sensors, described in pinning a certificate. By default the server's certificate has to chain to an authority the probe host trusts and has to be valid for server_name (or the device's host name, or its address). For a directory with a certificate from your own authority you can install that authority on the probe host, set tls_fingerprint to the one certificate, or, least well, turn verify_tls off. With a pin the chain, the dates and the name are not looked at, but the dates are still reported: an expired certificate is accepted for the connection and makes the sensor Down.

When a certificate is refused for not being trusted or not matching the name, the message carries the SHA-256 fingerprint the server presented, so you can compare it with the server's own and pin exactly that one. A pin that does not match is a failure of kind protocol that shows both fingerprints.

On the target ​

An LDAP server reachable from the probe on the port. For a bound search, an account that may read the base and the attributes you ask for. Nothing is installed, and nothing is changed: the sensor only searches.

Failures ​

MessageMeaning
the server refused the bind: invalid credentials ... (LDAP result 49) (kind auth_failed)The name or the password in the secret is wrong.
the account is not allowed to ... (insufficient access, LDAP result 50) (kind auth_failed)The account may not read the base.
the server will not ... like this (LDAP result 53, 7, 8 or 13) (kind protocol)The server wants TLS before a bind, or a different kind of bind.
TLS error: ... (kind protocol)The certificate was refused, or the port does not speak TLS. The text says which and how to fix it.
the secret must be in the form <bind name>:<password> (kind config)The secret credential does not hold a login.
a timeout (kind timeout), connection refused (kind unreachable)The server did not answer, or nothing listens on the port.
the search base ... does not exist on the serverA successful poll that is Down: the base was removed or mistyped.
no entry has <attribute> = "..." (values seen: ...)A successful poll that is Down. At most three of the values found are shown.

Verification ​

Run against OpenLDAP in a container on a test network: an anonymous search, a bound search over StartTLS and over LDAPS, a wrong password, a base that does not exist, the value check, the certificate checked against the authority that issued it (and refused for a wrong name), and a pin taken from the server and a wrong one. The refusal of an untrusted or pinned certificate and the failures against servers that hang up or speak something else are also tested against listeners the tests start themselves, which needs no lab. The sensor's rules (count, value check, limits, certificate channels, messages) are tested against scripted answers.

The live tests read their target from the environment and say so and return when it is not set:

VariableMeaning
PROBEWARD_TEST_LDAP_HOSTThe server's address.
PROBEWARD_TEST_LDAP_BASEA search base the server holds entries below.
PROBEWARD_TEST_LDAP_USER, PROBEWARD_TEST_LDAP_PASSWORDThe bind name (starting uid=) and its password.
PROBEWARD_TEST_LDAP_NAMEOptional: the host name the certificate is for. With SSL_CERT_FILE set to the file of the authority that issued it, the tests that verify the certificate run too.
sh
cargo test -p probeward-sensors --test live_protocols ldap -- --nocapture

AGPL-3.0-only