What you will have at the end
Two Routes on which a caller signs in with the user name and password of their directory account, over LDAPS, and is refused when the directory refuses them: a wrong password, a disabled account, or an account that is not mapped to a Consumer. directory-api uses ldap-auth, which binds as the user under a base DN and suits a directory whose entries are named by the account name. people-api uses ldap-auth-advanced, which searches Active Directory for the account name with a service account and then binds as the person, the way entries named CN=First Last need. The requests are records in Traffic Explorer with the Consumer beside the Route, and the bind password of the service account is masked in the audit log.
This is about callers of your APIs. Signing console users in with their directory accounts is set up separately, for the console itself, and is not touched here.
Prerequisites
- A directory the gateway can reach. The lab runs a Samba domain controller as a stand-in for Active Directory,
g8-samba-ad, LDAP on 389 and LDAPS on 636, with the test treeOU=g8-test,DC=ad,DC=g8dev,DC=lab: people underOU=Users-Dirty, a branch office under an OU with a comma in its name, groups underOU=Groups-Dirty, and a service accountsvc-g8-bindunderOU=Service. One measured fact about it first: it refuses a simple bind over plain LDAP,Transport encryption required, as a Windows domain controller with LDAP signing required does, so every bind below is over LDAPS. - An echo backend, so the article can show what the backend receives; both Routes forward to
httpbin-backendwith aproxy-rewrite. - Traffic logging turned on under Traffic Explorer › Settings, and a role that may manage Routes and Consumers. The screenshots below were taken as
nora.becker.
Part one: ldap-auth, the bind under a base DN
Open the Route directory-api, Plugins, Add plugin, ldap-auth:
- LDAP URI:
g8-samba-ad:636, host and port, not a URL. The note says why the port is written even with TLS on: without one the connection goes to 389. - Base DN:
OU=Users-Dirty,OU=g8-test,DC=ad,DC=g8dev,DC=lab. No search runs: the sign-in name is built as<UID>=<user name>,<base DN>, so the note is right that users in deeper OUs cannot sign in. - UID:
cn, the attribute the entries are named by. The More note under it is the sentence this article turns on: on Active Directory user entries are named bycn, so the sign-in name has to equal the entry’s CN;sAMAccountNamedoes not form a DN. - Use TLS on. TLS verify checks the certificate the directory presents; on this install the engine does not hold the lab’s CA, so with it on every sign-in was refused with
unable to verify the first certificatein the engine’s log, and it is off for the measurement. On an installation whose engine trusts your CA, leave it on. - Realm:
directory-api, sent back on every refusal. Hide credentials: on. Left off, the directory password travels to the backend with the request.

Select Add plugin. Then the Consumer: the directory accepting a bind is not enough, the DN must also belong to a Consumer. Open Consumers, the Consumer upn_alt, the Credentials tab, New credential, choose the Plugin ldap-auth, and write the User DN. The note under the field is exact: it must equal <UID>=<user name>,<base DN> exactly, letter case included, and any other spelling of the same DN gets the same 401 as a wrong password.

Six requests with curl -u user:password:
### no credentials at all
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="directory-api"
{"message":"Missing authorization in request"}
### upn.alt, an entry named by its account name, with the right password
HTTP/1.1 200 OK
### what the backend received for upn.alt
{'X-Consumer-Username': ['upn_alt'], 'X-Credential-Identifier': ['upn-alt-directory']}
### upn.alt with a wrong password
HTTP/1.1 401 Unauthorized
{"message":"Invalid user authorization"}
### uac.disabled, a disabled account, with the right password
HTTP/1.1 401 Unauthorized
{"message":"Invalid user authorization"}
### uac.neverexpire, an enabled account with no Consumer, with the right password
HTTP/1.1 401 Unauthorized
{"message":"Invalid user authorization"}
### ahmet.yilmaz, whose entry is named Ahmet Yilmaz, with the right password
HTTP/1.1 401 Unauthorized
{"message":"Invalid user authorization"}
The backend received the Consumer’s name and the credential’s id and no Authorization header. The client gets one sentence for every refusal; the reasons are in the engine’s log, where the directory’s own code tells a wrong password, data 52e, from a disabled account, data 533: the directory checked the password of uac.disabled and then refused the account.
The last line is the Active Directory problem. Ahmet’s entry is CN=Ahmet Yilmaz,OU=Users-Dirty,…, named by display name, while he signs in everywhere else as ahmet.yilmaz, his sAMAccountName; the DN cn=ahmet.yilmaz,… does not exist. Signing in as Ahmet Yilmaz was refused as well, by the directory, with invalid credentials in the engine’s log: the Plugin removes whitespace from the user name before it builds the DN, so the name it bound as was cn=AhmetYilmaz,…, which does not exist either. ldap-auth is right for a directory whose entries are named by the account name. For people in Active Directory, the next part.
Part two: ldap-auth-advanced, a search and then a bind
Open the Route people-api, Plugins, Add plugin, ldap-auth-advanced. Under Basics:
- LDAP URI:
g8-samba-ad:636and Use LDAPS on. Use StartTLS, under Behavior, is the other way to TLS, from a plain connection upgraded; not both. - Base DN:
OU=g8-test,DC=ad,DC=g8dev,DC=lab. This time it is where the search starts, and every entry below it is searched: both OUs of people, the branch office with the comma in its name included. - Bind DN and LDAP password: the service account the search runs as,
CN=svc-g8-bind,OU=Service,…, and its password, stored on the engine and shown only to roles that manage the Route. Left empty, the search binds anonymously, which a domain controller refuses. - Attribute:
sAMAccountName, the attribute the user name is matched against, as(sAMAccountName=ahmet.yilmaz). The note says what happens when a name matches more than one entry: the sign-in is refused, so the attribute must identify one person. - Header type:
basic, so the client sends an ordinaryAuthorization: Basicheader and an unauthenticated request is answered withBasicinWWW-Authenticate; the other value isldap. Realm:people-api. - Consumer required stays on. Its note is the policy decision of this Plugin: on, a user the directory accepts is still refused unless a Consumer holds their DN as a credential; off, the directory alone decides, and no Consumer is attached to the request.
- SSL verify is off for the same reason as above, the lab CA.

Select Add plugin. On the Consumer ahmet_yilmaz, a credential of the Plugin ldap-auth-advanced with the User DN as the directory holds it, which is what the search returns: CN=Ahmet Yilmaz,OU=Users-Dirty,OU=g8-test,DC=ad,DC=g8dev,DC=lab.

### no credentials at all
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="people-api"
{"message":"Authorization required"}
### ahmet.yilmaz with the right password
HTTP/1.1 200 OK
### what the backend received
{'Authorization': 'Basic (the credentials, passed on)', 'X-Consumer-Username': ['ahmet_yilmaz'], 'X-Credential-Identifier': ['ahmet-ad']}
### ahmet.yilmaz with a wrong password
HTTP/1.1 401 Unauthorized
### uac.disabled, a disabled account, with the right password
HTTP/1.1 401 Unauthorized
### sube.kadikoy, an account in another OU with no Consumer, Consumer required on
HTTP/1.1 401 Unauthorized
Ahmet is in, as the Consumer ahmet_yilmaz. Two things to read off the backend’s view: the Consumer and credential headers are there, and so is the Authorization header, because this Plugin has no setting to hide it; a backend that must not see directory passwords needs the header removed on the Route, with proxy-rewrite, which was not measured here. The engine’s log names each refusal: user authentication failed for the wrong password and the disabled account, and no Consumer maps to the authenticated user_dn for the branch-office account the directory accepted.
Switch Consumer required off and the last case changes:
### Consumer required switched off: sube.kadikoy again
HTTP/1.1 200 OK
### what the backend received for sube.kadikoy
{'Authorization': '(present)'}
### SVC$backup, a service account with a dollar sign in its name
HTTP/1.1 200 OK
### uac.disabled, Consumer required off
HTTP/1.1 401 Unauthorized
Every account the directory accepts is in, from any OU under the base DN, with no Consumer attached, so no per-Consumer rate limit or ACL applies; the disabled account is still out, because the directory still decides. The switch was turned back on after the measurement.
What Traffic Explorer shows
Every request is a record. A request that signed in as a Consumer carries the Consumer’s name beside the Route, people-api · ahmet_yilmaz; a request accepted with Consumer required off carries the Route alone; a refusal is a 401 answered by the gateway.

What the audit log keeps
Adding either Plugin is a Route update; adding a credential is a credential.created record naming the Consumer. The ldap-auth-advanced records carry the bind password as •••• on both sides, and the switch of Consumer required is its own record, one line changed.

What to do next
- Give the signed-in Consumer a budget and a scope: Rate limiting per Consumer.
- Give a machine caller a certificate instead of a directory password: Mutual TLS at the gateway with your organization’s CA.
- Prefer tokens over passwords where the caller can get them: OAuth 2.0 access tokens at the gateway.
- The identity Plugins side by side are in the capabilities reference and on API Security; the solution page is API security and identity.