2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_ldap.xml.meta">
26 <description>LDAP connection pooling and result caching services for use
27 by other LDAP modules</description>
28 <status>Extension</status>
29 <sourcefile>util_ldap.c</sourcefile>
30 <identifier>ldap_module</identifier>
31 <compatibility>Available in version 2.0.41 and later</compatibility>
34 <p>This module was created to improve the performance of
35 websites relying on backend connections to LDAP servers. In
36 addition to the functions provided by the standard LDAP
37 libraries, this module adds an LDAP connection pool and an LDAP
38 shared memory cache.</p>
40 <p>To enable this module, LDAP support must be compiled into
41 apr-util. This is achieved by adding the <code>--with-ldap</code>
42 flag to the <program>configure</program> script when building
45 <p>SSL/TLS support is dependant on which LDAP toolkit has been
46 linked to <glossary>APR</glossary>. As of this writing, APR-util supports:
47 <a href="http://www.openldap.org/">OpenLDAP SDK</a> (2.x or later),
48 <a href="http://developer.novell.com/ndk/cldap.htm">Novell LDAP
49 SDK</a>, <a href="http://www.mozilla.org/directory/csdk.html">
50 Mozilla LDAP SDK</a>, native Solaris LDAP SDK (Mozilla based),
51 native Microsoft LDAP SDK, or the
52 <a href="http://www.iplanet.com/downloads/developer/">iPlanet
53 (Netscape)</a> SDK. See the <a href="http://apr.apache.org">APR</a>
54 website for details.</p>
58 <section id="exampleconfig"><title>Example Configuration</title>
59 <p>The following is an example configuration that uses
60 <module>mod_ldap</module> to increase the performance of HTTP Basic
61 authentication provided by <module>mod_authnz_ldap</module>.</p>
64 # Enable the LDAP connection pool and shared<br />
65 # memory cache. Enable the LDAP cache status<br />
66 # handler. Requires that mod_ldap and mod_authnz_ldap<br />
67 # be loaded. Change the "yourdomain.example.com" to<br />
68 # match your domain.<br />
70 LDAPSharedCacheSize 200000<br />
71 LDAPCacheEntries 1024<br />
72 LDAPCacheTTL 600<br />
73 LDAPOpCacheEntries 1024<br />
74 LDAPOpCacheTTL 600<br />
76 <Location /ldap-status><br />
78 SetHandler ldap-status<br />
79 Order deny,allow<br />
81 Allow from yourdomain.example.com<br />
82 AuthLDAPURL ldap://127.0.0.1/dc=example,dc=com?uid?one<br />
83 AuthzLDAPAuthoritative off<br />
84 require valid-user<br />
90 <section id="pool"><title>LDAP Connection Pool</title>
92 <p>LDAP connections are pooled from request to request. This
93 allows the LDAP server to remain connected and bound ready for
94 the next request, without the need to unbind/connect/rebind.
95 The performance advantages are similar to the effect of HTTP
98 <p>On a busy server it is possible that many requests will try
99 and access the same LDAP server connection simultaneously.
100 Where an LDAP connection is in use, Apache will create a new
101 connection alongside the original one. This ensures that the
102 connection pool does not become a bottleneck.</p>
104 <p>There is no need to manually enable connection pooling in
105 the Apache configuration. Any module using this module for
106 access to LDAP services will share the connection pool.</p>
109 <section id="cache"><title>LDAP Cache</title>
111 <p>For improved performance, <module>mod_ldap</module> uses an aggressive
112 caching strategy to minimize the number of times that the LDAP
113 server must be contacted. Caching can easily double or triple
114 the throughput of Apache when it is serving pages protected
115 with mod_authnz_ldap. In addition, the load on the LDAP server
116 will be significantly decreased.</p>
118 <p><module>mod_ldap</module> supports two types of LDAP caching during
119 the search/bind phase with a <em>search/bind cache</em> and
120 during the compare phase with two <em>operation
121 caches</em>. Each LDAP URL that is used by the server has
122 its own set of these three caches.</p>
124 <section id="search-bind"><title>The Search/Bind Cache</title>
125 <p>The process of doing a search and then a bind is the
126 most time-consuming aspect of LDAP operation, especially if
127 the directory is large. The search/bind cache is used to
128 cache all searches that resulted in successful binds.
129 Negative results (<em>i.e.</em>, unsuccessful searches, or searches
130 that did not result in a successful bind) are not cached.
131 The rationale behind this decision is that connections with
132 invalid credentials are only a tiny percentage of the total
133 number of connections, so by not caching invalid
134 credentials, the size of the cache is reduced.</p>
136 <p><module>mod_ldap</module> stores the username, the DN
137 retrieved, the password used to bind, and the time of the bind
138 in the cache. Whenever a new connection is initiated with the
139 same username, <module>mod_ldap</module> compares the password
140 of the new connection with the password in the cache. If the
141 passwords match, and if the cached entry is not too old,
142 <module>mod_ldap</module> bypasses the search/bind phase.</p>
144 <p>The search and bind cache is controlled with the <directive
145 module="mod_ldap">LDAPCacheEntries</directive> and <directive
146 module="mod_ldap">LDAPCacheTTL</directive> directives.</p>
149 <section id="opcaches"><title>Operation Caches</title>
150 <p>During attribute and distinguished name comparison
151 functions, <module>mod_ldap</module> uses two operation caches
152 to cache the compare operations. The first compare cache is
153 used to cache the results of compares done to test for LDAP
154 group membership. The second compare cache is used to cache
155 the results of comparisons done between distinguished
158 <p>The behavior of both of these caches is controlled with
159 the <directive module="mod_ldap">LDAPOpCacheEntries</directive>
160 and <directive module="mod_ldap">LDAPOpCacheTTL</directive>
164 <section id="monitoring"><title>Monitoring the Cache</title>
165 <p><module>mod_ldap</module> has a content handler that allows
166 administrators to monitor the cache performance. The name of
167 the content handler is <code>ldap-status</code>, so the
168 following directives could be used to access the
169 <module>mod_ldap</module> cache information:</p>
172 <Location /server/cache-info><br />
174 SetHandler ldap-status<br />
179 <p>By fetching the URL <code>http://servername/cache-info</code>,
180 the administrator can get a status report of every cache that is used
181 by <module>mod_ldap</module> cache. Note that if Apache does not
182 support shared memory, then each <program>httpd</program> instance has its
183 own cache, so reloading the URL will result in different
184 information each time, depending on which <program>httpd</program>
185 instance processes the request.</p>
189 <section id="usingssltls"><title>Using SSL/TLS</title>
191 <p>The ability to create an SSL and TLS connections to an LDAP server
192 is defined by the directives <directive module="mod_ldap">
193 LDAPTrustedGlobalCert</directive>, <directive module="mod_ldap">
194 LDAPTrustedClientCert</directive> and <directive module="mod_ldap">
195 LDAPTrustedMode</directive>. These directives specify the CA and
196 optional client certificates to be used, as well as the type of
197 encryption to be used on the connection (none, SSL or TLS/STARTTLS).</p>
200 # Establish an SSL LDAP connection on port 636. Requires that <br />
201 # mod_ldap and mod_authnz_ldap be loaded. Change the <br />
202 # "yourdomain.example.com" to match your domain.<br />
204 LDAPTrustedGlobalCert CA_DER /certs/certfile.der<br />
206 <Location /ldap-status><br />
208 SetHandler ldap-status<br />
209 Order deny,allow<br />
211 Allow from yourdomain.example.com<br />
212 AuthLDAPURL ldaps://127.0.0.1/dc=example,dc=com?uid?one<br />
213 AuthzLDAPAuthoritative off<br />
214 require valid-user<br />
220 # Establish a TLS LDAP connection on port 389. Requires that <br />
221 # mod_ldap and mod_authnz_ldap be loaded. Change the <br />
222 # "yourdomain.example.com" to match your domain.<br />
224 LDAPTrustedGlobalCert CA_DER /certs/certfile.der<br />
226 <Location /ldap-status><br />
228 SetHandler ldap-status<br />
229 Order deny,allow<br />
231 Allow from yourdomain.example.com<br />
232 AuthLDAPURL ldap://127.0.0.1/dc=example,dc=com?uid?one TLS<br />
233 AuthzLDAPAuthoritative off<br />
234 require valid-user<br />
241 <section id="settingcerts"><title>SSL/TLS Certificates</title>
243 <p>The different LDAP SDKs have widely different methods of setting
244 and handling both CA and client side certificates.</p>
246 <p>If you intend to use SSL or TLS, read this section CAREFULLY so as to
247 understand the differences between configurations on the different LDAP
248 toolkits supported.</p>
250 <section id="settingcerts-netscape"><title>Netscape/Mozilla/iPlanet SDK</title>
251 <p>CA certificates are specified within a file called cert7.db.
252 The SDK will not talk to any LDAP server whose certificate was
253 not signed by a CA specified in this file. If
254 client certificates are required, an optional key3.db file may
255 be specified with an optional password. The secmod file can be
256 specified if required. These files are in the same format as
257 used by the Netscape Communicator or Mozilla web browsers. The easiest
258 way to obtain these files is to grab them from your browser
261 <p>Client certificates are specified per connection using the
262 LDAPTrustedClientCert directive by referring
263 to the certificate "nickname". An optional password may be
264 specified to unlock the certificate's private key.</p>
266 <p>The SDK supports SSL only. An attempt to use STARTTLS will cause
267 an error when an attempt is made to contact the LDAP server at
271 # Specify a Netscape CA certificate file<br />
272 LDAPTrustedGlobalCert CA_CERT7_DB /certs/cert7.db<br />
273 # Specify an optional key3.db file for client certificate support<br />
274 LDAPTrustedGlobalCert CERT_KEY3_DB /certs/key3.db<br />
275 # Specify the secmod file if required<br />
276 LDAPTrustedGlobalCert CA_SECMOD /certs/secmod<br />
277 <Location /ldap-status><br />
279 SetHandler ldap-status<br />
280 Order deny,allow<br />
282 Allow from yourdomain.example.com<br />
283 LDAPTrustedClientCert CERT_NICKNAME <nickname> [password]<br />
284 AuthLDAPURL ldaps://127.0.0.1/dc=example,dc=com?uid?one<br />
285 AuthzLDAPAuthoritative off<br />
286 require valid-user<br />
293 <section id="settingcerts-novell"><title>Novell SDK</title>
295 <p>One or more CA certificates must be specified for the Novell
296 SDK to work correctly. These certificates can be specified as
297 binary DER or Base64 (PEM) encoded files.</p>
299 <p>Note: Client certificates are specified globally rather than per
300 connection, and so must be specified with the LDAPTrustedGlobalCert
301 directive as below. Trying to set client certificates via the
302 LDAPTrustedClientCert directive will cause an error to be logged
303 when an attempt is made to connect to the LDAP server..</p>
305 <p>The SDK supports both SSL and STARTTLS, set using the
306 LDAPTrustedMode parameter. If an ldaps:// URL is specified,
307 SSL mode is forced, override this directive.</p>
310 # Specify two CA certificate files<br />
311 LDAPTrustedGlobalCert CA_DER /certs/cacert1.der<br />
312 LDAPTrustedGlobalCert CA_BASE64 /certs/cacert2.pem<br />
313 # Specify a client certificate file and key<br />
314 LDAPTrustedGlobalCert CERT_BASE64 /certs/cert1.pem<br />
315 LDAPTrustedGlobalCert KEY_BASE64 /certs/key1.pem [password]<br />
316 # Do not use this directive, as it will throw an error<br />
317 #LDAPTrustedClientCert CERT_BASE64 /certs/cert1.pem<br />
322 <section id="settingcerts-openldap"><title>OpenLDAP SDK</title>
324 <p>One or more CA certificates must be specified for the OpenLDAP
325 SDK to work correctly. These certificates can be specified as
326 binary DER or Base64 (PEM) encoded files.</p>
328 <p>Client certificates are specified per connection using the
329 LDAPTrustedClientCert directive.</p>
331 <p>The documentation for the SDK claims to support both SSL and
332 STARTTLS, however STARTTLS does not seem to work on all versions
333 of the SDK. The SSL/TLS mode can be set using the
334 LDAPTrustedMode parameter. If an ldaps:// URL is specified,
335 SSL mode is forced. The OpenLDAP documentation notes that SSL
336 (ldaps://) support has been deprecated to be replaced with TLS,
337 although the SSL functionality still works.</p>
340 # Specify two CA certificate files<br />
341 LDAPTrustedGlobalCert CA_DER /certs/cacert1.der<br />
342 LDAPTrustedGlobalCert CA_BASE64 /certs/cacert2.pem<br />
343 <Location /ldap-status><br />
345 SetHandler ldap-status<br />
346 Order deny,allow<br />
348 Allow from yourdomain.example.com<br />
349 LDAPTrustedClientCert CERT_BASE64 /certs/cert1.pem<br />
350 LDAPTrustedClientCert KEY_BASE64 /certs/key1.pem<br />
351 AuthLDAPURL ldaps://127.0.0.1/dc=example,dc=com?uid?one<br />
352 AuthzLDAPAuthoritative off<br />
353 require valid-user<br />
360 <section id="settingcerts-solaris"><title>Solaris SDK</title>
362 <p>SSL/TLS for the native Solaris LDAP libraries is not yet
363 supported. If required, install and use the OpenLDAP libraries
368 <section id="settingcerts-microsoft"><title>Microsoft SDK</title>
370 <p>SSL/TLS certificate configuration for the native Microsoft
371 LDAP libraries is done inside the system registry, and no
372 configuration directives are required.</p>
374 <p>Both SSL and TLS are supported by using the ldaps:// URL
375 format, or by using the LDAPTrustedMode directive accordingly.</p>
377 <p>Note: The status of support for client certificates is not yet known
378 for this toolkit.</p>
385 <name>LDAPSharedCacheSize</name>
386 <description>Size in bytes of the shared-memory cache</description>
387 <syntax>LDAPSharedCacheSize <var>bytes</var></syntax>
388 <default>LDAPSharedCacheSize 102400</default>
389 <contextlist><context>server config</context></contextlist>
392 <p>Specifies the number of bytes to allocate for the shared
393 memory cache. The default is 100kb. If set to 0, shared memory
394 caching will not be used.</p>
399 <name>LDAPSharedCacheFile</name>
400 <description>Sets the shared memory cache file</description>
401 <syntax>LDAPSharedCacheFile <var>directory-path/filename</var></syntax>
402 <contextlist><context>server config</context></contextlist>
405 <p>Specifies the directory path and file name of the shared memory
406 cache file. If not set, anonymous shared memory will be used if the
407 platform supports it.</p>
412 <name>LDAPCacheEntries</name>
413 <description>Maximum number of entries in the primary LDAP cache</description>
414 <syntax>LDAPCacheEntries <var>number</var></syntax>
415 <default>LDAPCacheEntries 1024</default>
416 <contextlist><context>server config</context></contextlist>
419 <p>Specifies the maximum size of the primary LDAP cache. This
420 cache contains successful search/binds. Set it to 0 to turn off
421 search/bind caching. The default size is 1024 cached
427 <name>LDAPCacheTTL</name>
428 <description>Time that cached items remain valid</description>
429 <syntax>LDAPCacheTTL <var>seconds</var></syntax>
430 <default>LDAPCacheTTL 600</default>
431 <contextlist><context>server config</context></contextlist>
434 <p>Specifies the time (in seconds) that an item in the
435 search/bind cache remains valid. The default is 600 seconds (10
441 <name>LDAPOpCacheEntries</name>
442 <description>Number of entries used to cache LDAP compare
443 operations</description>
444 <syntax>LDAPOpCacheEntries <var>number</var></syntax>
445 <default>LDAPOpCacheEntries 1024</default>
446 <contextlist><context>server config</context></contextlist>
449 <p>This specifies the number of entries <module>mod_ldap</module>
450 will use to cache LDAP compare operations. The default is 1024
451 entries. Setting it to 0 disables operation caching.</p>
456 <name>LDAPOpCacheTTL</name>
457 <description>Time that entries in the operation cache remain
459 <syntax>LDAPOpCacheTTL <var>seconds</var></syntax>
460 <default>LDAPOpCacheTTL 600</default>
461 <contextlist><context>server config</context></contextlist>
464 <p>Specifies the time (in seconds) that entries in the
465 operation cache remain valid. The default is 600 seconds.</p>
470 <name>LDAPTrustedGlobalCert</name>
471 <description>Sets the file or database containing global trusted
472 Certificate Authority or global client certificates</description>
473 <syntax>LDAPTrustedGlobalCert <var>type</var> <var>directory-path/filename</var> <var>[password]</var></syntax>
474 <contextlist><context>server config</context></contextlist>
477 <p>It specifies the directory path and file name of the trusted CA
478 certificates and/or system wide client certificates <module>mod_ldap</module>
479 should use when establishing an SSL or TLS connection to an LDAP
480 server. Note that all certificate information specified using this directive
481 is applied globally to the entire server installation. Some LDAP toolkits
482 (notably Novell) require all client certificates to be set globally using
483 this directive. Most other toolkits require clients certificates to be set
484 per Directory or per Location using LDAPTrustedClientCert. If you get this
485 wrong, an error may be logged when an attempt is made to contact the LDAP
486 server, or the connection may silently fail (See the SSL/TLS certificate
487 guide above for details).
488 The type specifies the kind of certificate parameter being
489 set, depending on the LDAP toolkit being used. Supported types are:</p>
491 <li>CA_DER - binary DER encoded CA certificate</li>
492 <li>CA_BASE64 - PEM encoded CA certificate</li>
493 <li>CA_CERT7_DB - Netscape cert7.db CA certificate database file</li>
494 <li>CA_SECMOD - Netscape secmod database file</li>
495 <li>CERT_DER - binary DER encoded client certificate</li>
496 <li>CERT_BASE64 - PEM encoded client certificate</li>
497 <li>CERT_KEY3_DB - Netscape key3.db client certificate database file</li>
498 <li>CERT_NICKNAME - Client certificate "nickname" (Netscape SDK)</li>
499 <li>CERT_PFX - PKCS#12 encoded client certificate (Novell SDK)</li>
500 <li>KEY_DER - binary DER encoded private key</li>
501 <li>KEY_BASE64 - PEM encoded private key</li>
502 <li>KEY_PFX - PKCS#12 encoded private key (Novell SDK)</li>
508 <name>LDAPTrustedClientCert</name>
509 <description>Sets the file containing or nickname referring to a per
510 connection client certificate. Not all LDAP toolkits support per
511 connection client certificates.</description>
512 <syntax>LDAPTrustedClientCert <var>type</var> <var>directory-path/filename/nickname</var> <var>[password]</var></syntax>
513 <contextlist><context>server config</context><context>virtual host</context>
514 <context>directory</context><context>.htaccess</context></contextlist>
517 <p>It specifies the directory path, file name or nickname of a
518 per connection client certificate used when establishing an SSL
519 or TLS connection to an LDAP server. Different locations or
520 directories may have their own independant client certificate
521 settings. Some LDAP toolkits (notably Novell)
522 do not support per connection client certificates, and will throw an
523 error on LDAP server connection if you try to use this directive
524 (Use the LDAPTrustedGlobalCert directive instead for Novell client
525 certificates - See the SSL/TLS certificate guide above for details).
526 The type specifies the kind of certificate parameter being
527 set, depending on the LDAP toolkit being used. Supported types are:</p>
529 <li>CERT_DER - binary DER encoded client certificate</li>
530 <li>CERT_BASE64 - PEM encoded client certificate</li>
531 <li>CERT_NICKNAME - Client certificate "nickname" (Netscape SDK)</li>
532 <li>KEY_DER - binary DER encoded private key</li>
533 <li>KEY_BASE64 - PEM encoded private key</li>
539 <name>LDAPTrustedMode</name>
540 <description>Specifies the SSL/TLS mode to be used when connecting to an LDAP server.</description>
541 <syntax>LDAPTrustedMode <var>type</var></syntax>
542 <contextlist><context>server config</context><context>virtual host</context></contextlist>
545 <p>The following modes are supported:</p>
547 <li>NONE - no encryption</li>
548 <li>SSL - ldaps:// encryption on default port 636</li>
549 <li>TLS - STARTTLS encryption on default port 389</li>
552 <p>Not all LDAP toolkits support all the above modes. An error message
553 will be logged at runtime if a mode is not supported, and the
554 connection to the LDAP server will fail.
557 <p>If an ldaps:// URL is specified, the mode becomes SSL and the setting
558 of LDAPTrustedMode is ignored.</p>
563 <name>LDAPConnectionTimeout</name>
564 <description>Specifies the socket connection timeout in seconds</description>
565 <syntax>LDAPConnectionTimeout <var>seconds</var></syntax>
566 <contextlist><context>server config</context></contextlist>
569 <p>Specifies the timeout value (in seconds) in which the module will
570 attempt to connect to the LDAP server. If a connection is not
571 successful with the timeout period, either an error will be
572 returned or the module will attempt to connect to a secondary LDAP
573 server if one is specified. The default is 10 seconds.</p>
578 <name>LDAPVerifyServerCert</name>
579 <description>Force server certificate verification</description>
580 <syntax>LDAPVerifyServerCert <var>On|Off</var></syntax>
581 <default>LDAPVerifyServerCert On</default>
582 <contextlist><context>server config</context></contextlist>
585 <p>Specifies whether to force the verification of a
586 server certificate when establishing an SSL connection to the