summaryrefslogtreecommitdiff
path: root/docs/manual/mod/mod_ldap.xml
blob: 451ccad5a21129b75cda2f4d1ea9180523cc151b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?xml version="1.0"?>
<!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
<?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
<!-- $LastChangedRevision$ -->

<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<modulesynopsis metafile="mod_ldap.xml.meta">

<name>mod_ldap</name>
<description>LDAP connection pooling and result caching services for use
by other LDAP modules</description>
<status>Experimental</status>
<sourcefile>util_ldap.c</sourcefile>
<identifier>ldap_module</identifier>
<compatibility>Available in version 2.0.41 and later</compatibility>

<summary>
    <p>This module was created to improve the performance of
    websites relying on backend connections to LDAP servers. In
    addition to the functions provided by the standard LDAP
    libraries, this module adds an LDAP connection pool and an LDAP
    shared memory cache.</p>

    <p>To enable this module, LDAP support must be compiled into
    apr-util. This is achieved by adding the <code>--with-ldap</code>
    flag to the <program>configure</program> script when building
    Apache.</p>

    <p>SSL support requires that <module>mod_ldap</module> be linked
    with one of the following LDAP SDKs: <a href="http://www.openldap.org/">
    OpenLDAP SDK</a> (both 1.x and 2.x), <a href="http://developer.novell.com/ndk/cldap.htm">
    Novell LDAP SDK</a> or the <a href="http://www.iplanet.com/downloads/developer/">
    iPlanet(Netscape)</a> SDK.</p>

</summary>

<section id="exampleconfig"><title>Example Configuration</title>
    <p>The following is an example configuration that uses
    <module>mod_ldap</module> to increase the performance of HTTP Basic
    authentication provided by <module>mod_auth_ldap</module>.</p>

    <example>
      # Enable the LDAP connection pool and shared<br />
      # memory cache. Enable the LDAP cache status<br />
      # handler. Requires that mod_ldap and mod_auth_ldap<br />
      # be loaded. Change the "yourdomain.example.com" to<br />
      # match your domain.<br />
      <br />
      LDAPSharedCacheSize 200000<br />
      LDAPCacheEntries 1024<br />
      LDAPCacheTTL 600<br />
      LDAPOpCacheEntries 1024<br />
      LDAPOpCacheTTL 600<br />
      <br />
      &lt;Location /ldap-status&gt;<br />
      <indent>
        SetHandler ldap-status<br />
        Order deny,allow<br />
        Deny from all<br />
        Allow from yourdomain.example.com<br />
        AuthLDAPEnabled on<br />
        AuthLDAPURL ldap://127.0.0.1/dc=example,dc=com?uid?one<br />
        AuthLDAPAuthoritative on<br />
        Require valid-user<br />
      </indent>
      &lt;/Location&gt;
    </example>
</section>

<section id="pool"><title>LDAP Connection Pool</title>

    <p>LDAP connections are pooled from request to request. This
    allows the LDAP server to remain connected and bound ready for
    the next request, without the need to unbind/connect/rebind.
    The performance advantages are similar to the effect of HTTP
    keepalives.</p>

    <p>On a busy server it is possible that many requests will try
    and access the same LDAP server connection simultaneously.
    Where an LDAP connection is in use, Apache will create a new
    connection alongside the original one. This ensures that the
    connection pool does not become a bottleneck.</p>

    <p>There is no need to manually enable connection pooling in
    the Apache configuration. Any module using this module for
    access to LDAP services will share the connection pool.</p>
</section>

<section id="cache"><title>LDAP Cache</title>

    <p>For improved performance, <module>mod_ldap</module> uses an aggressive
    caching strategy to minimize the number of times that the LDAP
    server must be contacted. Caching can easily double or triple
    the throughput of Apache when it is serving pages protected
    with mod_auth_ldap. In addition, the load on the LDAP server
    will be significantly decreased.</p>

    <p><module>mod_ldap</module> supports two types of LDAP caching during
    the search/bind phase with a <em>search/bind cache</em> and
    during the compare phase with two <em>operation
    caches</em>. Each LDAP URL that is used by the server has
    its own set of these three caches.</p>

    <section id="search-bind"><title>The Search/Bind Cache</title>
      <p>The process of doing a search and then a bind is the
      most time-consuming aspect of LDAP operation, especially if
      the directory is large. The search/bind cache is used to
      cache all searches that resulted in successful binds.
      Negative results (<em>i.e.</em>, unsuccessful searches, or searches
      that did not result in a successful bind) are not cached.
      The rationale behind this decision is that connections with
      invalid credentials are only a tiny percentage of the total
      number of connections, so by not caching invalid
      credentials, the size of the cache is reduced.</p>

      <p><module>mod_ldap</module> stores the username, the DN
      retrieved, the password used to bind, and the time of the bind
      in the cache. Whenever a new connection is initiated with the
      same username, <module>mod_ldap</module> compares the password
      of the new connection with the password in the cache. If the
      passwords match, and if the cached entry is not too old,
      <module>mod_ldap</module> bypasses the search/bind phase.</p>

      <p>The search and bind cache is controlled with the <directive
      module="mod_ldap">LDAPCacheEntries</directive> and <directive
      module="mod_ldap">LDAPCacheTTL</directive> directives.</p>
    </section>

    <section id="opcaches"><title>Operation Caches</title>
      <p>During attribute and distinguished name comparison
      functions, <module>mod_ldap</module> uses two operation caches
      to cache the compare operations. The first compare cache is
      used to cache the results of compares done to test for LDAP
      group membership. The second compare cache is used to cache
      the results of comparisons done between distinguished
      names.</p>

      <p>The behavior of both of these caches is controlled with
      the <directive module="mod_ldap">LDAPOpCacheEntries</directive>
      and <directive module="mod_ldap">LDAPOpCacheTTL</directive>
      directives.</p>
    </section>

    <section id="monitoring"><title>Monitoring the Cache</title>
      <p><module>mod_ldap</module> has a content handler that allows
      administrators to monitor the cache performance. The name of
      the content handler is <code>ldap-status</code>, so the
      following directives could be used to access the
      <module>mod_ldap</module> cache information:</p>

      <example>
        &lt;Location /server/cache-info&gt;<br />
        <indent>
          SetHandler ldap-status<br />
        </indent>
        &lt;/Location&gt;
      </example>

      <p>By fetching the URL <code>http://servername/cache-info</code>,
      the administrator can get a status report of every cache that is used
      by <module>mod_ldap</module> cache. Note that if Apache does not
      support shared memory, then each <program>httpd</program> instance has its
      own cache, so reloading the URL will result in different
      information each time, depending on which <program>httpd</program>
      instance processes the request.</p>
    </section>
</section>

<section id="usingssltls"><title>Using SSL</title>

    <p>The ability to create an SSL connections to an LDAP server 
    is defined by the directives <directive module="mod_ldap">
    LDAPTrustedCA</directive> and <directive module="mod_ldap">
    LDAPTrustedCAType</directive>. These directives specify the certificate
    file or database and the certificate type. Whenever the LDAP url
    includes <em>ldaps://</em>, <module>mod_ldap</module> will establish
    a secure connection to the LDAP server.</p>

    <example>
      # Establish an SSL LDAP connection. Requires that <br />
      # mod_ldap and mod_auth_ldap be loaded. Change the <br />
      # "yourdomain.example.com" to match your domain.<br />
      <br />
      LDAPTrustedCA /certs/certfile.der<br />
      LDAPTrustedCAType DER_FILE<br />
      <br />
      &lt;Location /ldap-status&gt;<br />
      <indent>
        SetHandler ldap-status<br />
        Order deny,allow<br />
        Deny from all<br />
        Allow from yourdomain.example.com<br />
        AuthLDAPEnabled on<br />
        AuthLDAPURL ldaps://127.0.0.1/dc=example,dc=com?uid?one<br />
        AuthLDAPAuthoritative on<br />
        Require valid-user<br />
      </indent>
      &lt;/Location&gt;
    </example>

    <p>If <module>mod_ldap</module> is linked against the
    Netscape/iPlanet LDAP SDK, it will not talk to any SSL server
    unless that server has a certificate signed by a known Certificate
    Authority. As part of the configuration
    <module>mod_ldap</module> needs to be told where it can find
    a database containing the known CAs. This database is in the same
    format as Netscape Communicator's <code>cert7.db</code>
    database. The easiest way to get this file is to start up a fresh
    copy of Netscape, and grab the resulting
    <code>$HOME/.netscape/cert7.db</code> file.</p>

</section>

<directivesynopsis>
<name>LDAPSharedCacheSize</name>
<description>Size in bytes of the shared-memory cache</description>
<syntax>LDAPSharedCacheSize <var>bytes</var></syntax>
<default>LDAPSharedCacheSize 102400</default>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>Specifies the number of bytes to allocate for the shared
    memory cache. The default is 100kb. If set to 0, shared memory
    caching will not be used.</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPSharedCacheFile</name>
<description>Sets the shared memory cache file</description>
<syntax>LDAPSharedCacheFile <var>directory-path/filename</var></syntax>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>Specifies the directory path and file name of the shared memory
    cache file. If not set, anonymous shared memory will be used if the
    platform supports it.</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPCacheEntries</name>
<description>Maximum number of entries in the primary LDAP cache</description>
<syntax>LDAPCacheEntries <var>number</var></syntax>
<default>LDAPCacheEntries 1024</default>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>Specifies the maximum size of the primary LDAP cache. This
    cache contains successful search/binds. Set it to 0 to turn off
    search/bind caching. The default size is 1024 cached
    searches.</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPCacheTTL</name>
<description>Time that cached items remain valid</description>
<syntax>LDAPCacheTTL <var>seconds</var></syntax>
<default>LDAPCacheTTL 600</default>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>Specifies the time (in seconds) that an item in the
    search/bind cache remains valid. The default is 600 seconds (10
    minutes).</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPOpCacheEntries</name>
<description>Number of entries used to cache LDAP compare 
operations</description>
<syntax>LDAPOpCacheEntries <var>number</var></syntax>
<default>LDAPOpCacheEntries 1024</default>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>This specifies the number of entries <module>mod_ldap</module>
    will use to cache LDAP compare operations. The default is 1024
    entries.  Setting it to 0 disables operation caching.</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPOpCacheTTL</name>
<description>Time that entries in the operation cache remain
valid</description>
<syntax>LDAPOpCacheTTL <var>seconds</var></syntax>
<default>LDAPOpCacheTTL 600</default>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>Specifies the time (in seconds) that entries in the
    operation cache remain valid. The default is 600 seconds.</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPTrustedCA</name>
<description>Sets the file containing the trusted Certificate Authority certificate or database</description>
<syntax>LDAPTrustedCA <var>directory-path/filename</var></syntax>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>It specifies the directory path and file name of the trusted CA
    <module>mod_ldap</module> should use when establishing an SSL
    connection to an LDAP server. If using the Netscape/iPlanet Directory
    SDK, the file name should be <code>cert7.db</code>.</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPTrustedCAType</name>
<description>Specifies the type of the Certificate Authority file</description>
<syntax>LDAPTrustedCAType <var>type</var></syntax>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>The following types are supported:<br />
          DER_FILE      - file in binary DER format<br />
          BASE64_FILE   - file in Base64 format<br />
          CERT7_DB_PATH - Netscape certificate database file ")</p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>LDAPConnectionTimeout</name>
<description>Specifies the socket connection timeout in seconds</description>
<syntax>LDAPConnectionTimeout <var>seconds</var></syntax>
<contextlist><context>server config</context></contextlist>

<usage>
    <p>Specifies the timeout value (in seconds) in which the module will
    attempt to connect to the LDAP server.  If a connection is not
    successful with the timeout period, either an error will be 
    returned or the module will attempt to connect to a secondary LDAP 
    server if one is specified. The default is 10 seconds.</p>
</usage>
</directivesynopsis>

</modulesynopsis>