]> git.sur5r.net Git - openldap/blob - doc/guide/admin/sasl.sdf
Rough cut of GSSAPI using my usual terse style of writing.
[openldap] / doc / guide / admin / sasl.sdf
1 # Copyright 1999-2000, The OpenLDAP Foundation, All Rights Reserved.
2 # COPYING RESTRICTIONS APPLY, see COPYRIGHT.
3
4 H1: Using SASL
5
6 OpenLDAP clients and servers are capable of providing authentication
7 via the {{TERM[expand]SASL}} ({{TERM:SASL}}) system, which is
8 explained in {{REF:RFC2222}}. There are several industry standard
9 authentication mechanisms that can be used with SASL, including
10 Kerberos V4, GSSAPI, and some of the Digest mechanisms. The standard
11 client tools provided with OpenLDAP, such as {{ldapsearch}}(1) and
12 {{ldapmodify}}(1), will by default attempt to authenticate the user
13 to the {{slapd}}(8) server using SASL. Basic authentication service
14 can be set up by the LDAP administrator with a few steps, allowing
15 users to be authenticated to the slapd server as their LDAP entry.
16 With a few extra steps, some users and services can be allowed to
17 exploit SASL's authorization feature, allowing them to authenticate
18 themselves and then switch their identity to that of another user
19 or service.
20
21 Note that in the following text the term "{{user}}" is used to
22 describe a person who is connecting to the LDAP server via a client
23 program, such as {{ldapsearch}}(1).  The term can also be used to
24 describe a computer program that runs itself and accesses the LDAP
25 database, such as a sendmail program or a nightly update program
26 run out of cron.  Thus {{"user"}} refers to any computer process
27 connecting to the LDAP server, whether or not it has a human
28 monitoring it.
29
30 H2: Security Considerations
31
32 SASL offers many different authentication mechanisms.  This section
33 breifly outlines security considerations.
34
35 Some mechanisms, such as PLAIN and LOGIN, offer no security over
36 LDAP "simple" authentication.  Like "simple" authentication, such
37 mechanisms should not be used unless you have adequate security
38 protections in place.  It is recommended that these mechanism be
39 used only in conjunction with {{TERM[expand]TLS}} (TLS).  Use of
40 PLAIN and LOGIN are not discussed further in this document.
41
42 The DIGEST-MD5 mechanism is the mandatory-to-implement authentication
43 mechanism for LDAPv3.  Though DIGEST-MD5 is not a strong authentication
44 mechanism in comparison with trusted third party authentication
45 systems, it does offer significant protections against a number of
46 attacks.  Unlike the CRAM-MD5 mechanism, it prevents chosen plaintext
47 attacks.  DIGEST-MD5 is favored over weaker and even more dangerous
48 use of plaintext password mechanisms.  The CRAM-MD5 mechanism is
49 deprecated in favor of DIGEST-MD5.
50
51 # Use of DIGEST-MD5 is discussed below.
52
53 The KERBEROS_V4 mechanism utilizes Kerberos IV services to provide
54 secure authentication services.  There are also GSSAPI based
55 mechanisms which utilize Kerberos V.  Kerberos is viewed as a
56 secure, distributed authentication system.
57 Use of KERBEROS_V4 is discussed below.
58 #Use of KERBEROS_V4 and GSSAPI are discussed below.
59
60 The EXTERNAL mechanism utilizes authentication services provided
61 by lower level network services such as {{TERM:TLS}} (TLS).  When
62 used in conjunction with TLS X.509-based public key technology,
63 EXTERNAL offers strong authentication.
64 #Use of EXTERNAL is discussed in the TLS chapter.
65
66 There are other strong authentication mechanisms to choose from,
67 including OTP (one time passwords) and SRP (secure remote passwords).
68 These mechanisms are not discussed in this document.
69
70
71 H2: SASL Authentication
72
73 Getting basic SASL authentication running involves a few steps. The
74 first step configures your slapd server environment so
75 that it can communicate with client programs using the security
76 system in place at your site. This usually involves setting up a
77 service key, a public key, or other form of secret. The second step
78 concerns mapping authentication identities to LDAP DN's, which
79 depends on how entries are laid out in your directory. An explanation
80 of the first step will be given in the next section using Kerberos
81 V4 as an example mechanism. The steps necessary for your site's
82 authentication mechanism will be similar, but a guide to every
83 mechanism available under SASL is beyond the scope of this chapter.
84 The next section after that describes the second step of mapping
85 authentication identities to DN's.
86
87
88 H3: GSSAPI and Kerberos V
89
90 This section describes the use of the SASL GSSAPI mechanism and
91 Kerberos V with OpenLDAP.  It will be assumed that you have Kerberos
92 V deployed, you familiar with the operation of the system and that
93 your users are trained its use.  General information about Kerberos
94 is available at {{URL:http://web.mit.edu/kerberos/www/}}.
95
96 To use GSSAPI mechanism with {{slapd}}(8) one must create a service
97 key with a principal for {{ldap}} service within realm for the host
98 on which the service runs.  For example, if your run {{slapd}} on
99 {{EX:directory.example.com}} and your realm is {{EX:EXAMPLE.COM}},
100 you need to create a service key with the principal:
101
102 >       ldap/directory.example.com@EXAMPLE.COM
103
104 When {{slapd}}(8) runs, it must have access to this key.  This is
105 generally done by placing the key into a keytab such as
106 {{FILE:/etc/krb5.keytab}}.
107
108 To use the GSSAPI mechanism to authenticate to the directory, the
109 user obtain a Ticket Granting Ticket (TGT) prior to running the
110 LDAP client.  When using OpenLDAP client tools, the user may mandate
111 use of the GSSAPI mechanism by specifying {{EX:-Y GSSAPI}} as a
112 command option.
113
114 For the purposes of authentication and authorization, {{slapd}}(8)
115 associated the non-mapped authentication DN of
116
117 >       uid=user@REALM,cn=GSSAPI,cn=authzid
118
119 for the GSSAPI principal "user@REALM".  The may be subsequently
120 mapped as detailed below.
121
122
123 H3: KERBEROS_V4
124
125 This section describes the use of the SASL KERBEROS_V4 mechanism
126 with OpenLDAP.  It will be assumed that you are familiar with the
127 workings of Kerberos IV security system, and that your site has
128 either Kerberos IV deployed.  Your users should be familiar with
129 authentication policy, are aware of how to receive credentials in
130 a Kerberos ticket cache, and how to refresh expired credentials.
131
132 Client programs will need to be able to obtain a session key for
133 use when connecting to your LDAP server. This allows the LDAP server
134 to know the identity of the user, and allows the client to know it
135 is connecting to a legitimate server. If encryption layers are to
136 be used, the session key can also be used to help negotiate that
137 option.
138
139 The slapd server runs the service called "{{ldap}}", and the server
140 will require a srvtab file with a service key.  SASL aware client
141 programs will be obtaining an "ldap" service ticket with the user's
142 ticket granting ticket (TGT), with the instance of the ticket
143 matching the hostname of the OpenLDAP server. For example, if your
144 realm is named EXAMPLE.COM and the slapd server is running on the
145 host named directory.example.com, the /etc/srvtab file on the server
146 will have a service key
147
148 >       ldap.directory@EXAMPLE.COM
149
150 When a LDAP client is authenticating a user to the directory using
151 the KERBEROS_IV mechanism, it will request a session key for that
152 same principal, either from the ticket cache or by obtaining a new
153 one from the Kerberos server.  This will require the TGT to be
154 available and valid in the cache as well.  If it is not present or
155 has expired, SASL will print out the message
156
157 >       ldap_sasl_interactive_bind_s: Local error
158
159 When the service ticket is obtained, it will be passed to the LDAP
160 server as proof of the user's identity.  The server will take the
161 user's username and realm out of the service ticket using SASL
162 library calls, and convert them into an {{authentication request
163 DN}} of the form
164
165 >       uid=<username>,cn=<realm>,cn=<mechanism>,cn=authzid
166
167 So in our above example, if the user's name were "adamson", the
168 authentication request DN would be:
169
170 >       uid=ADAMSON,cn=EXAMPLE.COM,cn=KERBEROS_V4,cn=AUTHZID
171
172 This authentication request DN by itself could be placed into ACL's
173 and {{EX:groupOfNames}} "member" attributes, since it is of legitimate
174 LDAP DN format. The next section, however, tells how to map that
175 DN into the DN of a person's own LDAP entry.
176
177 Also note that this example, being for Kerberos, shows the <realm>
178 portion of the DN being filled in with the Kerberos realm of the
179 company. Several other authentication mechanisms do not emply the
180 concept of a realm, so the ",cn=<realm>" portion of the authentication
181 request DN would not appear.
182
183
184 H3: Mapping Authentication identities to LDAP entries
185
186 The authentication mechanism in the slapd server will use SASL
187 library calls to obtain the authenticated user's "username", based
188 on whatever underlying authentication mechanism was used.  This
189 username is in the namespace of the authentication mechanism, and
190 not in the LDAP namespace. As stated in the section above, that
191 username is reformatted into an authentication request DN of the
192 form
193
194 >       uid=<username>,cn=<realm>,cn=<mechanism>,cn=authzid
195
196 or
197
198 >       uid=<username>,cn=<mechanism>,cn=authzid
199
200 depending on whether or not <mechanism> employs the concept of
201 "realms".
202
203 It is not intended that you should add LDAP entries of the above
204 form to your LDAP database. Chances are you have an LDAP entry for
205 each of the people that will be authenticating to LDAP, laid out
206 in your directory tree, and the tree does not start at cn=authzid.
207 But if your site has a clear mapping between the "username" and an
208 LDAP entry for the person, you will be able to configure your LDAP
209 server to automatically map a user's authentication username to
210 their {{authentication DN}}.
211
212 The LDAP administrator will need to tell the slapd server how to
213 map an authentication request DN to a user's authentication DN.
214 This is done by adding one or more {{EX:saslRegexp}} directives to
215 the {{slapd.conf}}(5) file.  This directive takes two arguments:
216
217 >       saslRegexp   <search pattern>   <replacement pattern>
218
219 The authentication request DN is compared to the search pattern
220 using the regular expression functions {{regcomp}}() and {{regexec}}(),
221 and if it matches, it is rewritten as the replacement pattern. If
222 there are multiple {{EX:saslRegexp}} directives, only the first
223 whose search pattern matches the authentication identity is used.
224 The string that is output from the replacement pattern should be
225 the authentication DN of the user, in a legitimate LDAP DN format.
226 It can also be an LDAP URL, which is discussed below.
227
228 The search pattern can contain any of the regular expression
229 characters listed in {{regexec}}(3C). The main characters of note
230 are dot ".", asterisk "*", and the open and close parenthesis "("
231 and ")".  Essentially, the dot matches any character, the asterisk
232 matches one or more characters, and terms in parenthesis are
233 remembered for the replacement pattern.
234
235 The replacement pattern will produce the final authentication DN
236 of the user.  Anything from the authentication request DN that
237 matched a string in parenthesis in the search pattern is stored in
238 the variable "$1". That variable "$1" can appear in the replacement
239 pattern, and will be replaced by the string from the authentication
240 request DN. If there were multiple sets of parenthesis in the search
241 pattern, the variables $2, $3, etc are used.
242
243 For example, suppose the user's authentication identity is written
244 as the DN string
245
246 >       uid=ADAMSON,cn=EXAMPLE.COM,cn=KERBEROS_V4,cn=AUTHZID
247
248 and the user's actual LDAP entry is
249
250 >       uid=ADAMSON,ou=PERSON,dc=EXAMPLE,dc=COM
251
252 The {{EX:saslRegexp}} directive in {{slapd.conf}}(5) could be
253 written
254
255 >       saslRegexp 
256 >         uid=(.*),cn=example.com,cn=kerberos_v4,cn=authzid
257 >         uid=$1,ou=person,dc=example,dc=com
258
259 An even more lenient rule could be written as
260
261 >       saslRegexp
262 >         uid=(.*),.*cn=authzid 
263 >         uid=$1,ou=person,dc=example,dc=com
264
265 Be careful about setting the search pattern too leniently, however,
266 since it may mistakenly allow people to become authenticated as a
267 DN to which they should not have access. It is better to write
268 several strict directives than one lenient directive which has
269 security holes. If there is only one authentication mechanism in
270 place at your site, and zero or one realms in use, you might be
271 able to map between authentication identities and LDAP DN's with
272 a single {{EX:saslRegexp}} directive.
273
274 Some sites may have people's DN's spread to multiple areas of the
275 LDAP tree, such as if there were an ou=accounting tree and an
276 ou=engineering tree, with people interspersed between them. Or
277 there may not be enough information in the authentication identity
278 to isolate the DN, such as if the above person's LDAP entry looked
279 like
280
281 >       dn: cn=mark adamson,ou=person,dc=example,dc=com
282 >       objectclass: Person
283 >       cn: mark adamson
284 >       uid: adamson
285
286 In this case, the information in the authentication identity can
287 only be used to search for the user's DN, not derive it directly.
288 For both of these situations, and others, the replacement pattern
289 in the {{EX:saslRegexp}} directives will need to produce an LDAP
290 URL, described in the next section.
291
292
293 H3: Performing searches for a person's DN
294
295 When there is not enough information in the authentication identity
296 to derive a person's authentication DN directly, the {{EX:saslRegexp}}
297 directives in the {{slapd.conf}}(5) file will need to produce an
298 LDAP URL.  This URL will then be used to perform an internal search
299 of the LDAP database to find the person's authentication DN.
300
301 An LDAP URL, similar to other URL's, is of the form
302
303 >       ldap://<host>/<base>?<attrs>?<scope>?<filter>
304
305 This contains all of the elements necessary to perform an LDAP
306 search:  the name of the server <host>, the LDAP DN search base
307 <base>, the LDAP attributes to retrieve <attrs>, the search scope
308 <scope> which is one of the three options "base", "one", or "sub",
309 and lastly an LDAP search filter <filter>. Since the search is for
310 an LDAP DN on the local machine, the <host> portion is ignored. By
311 the same token the <attrs> field is also ignored since only the DN
312 is of concern.  These two elements are left in the format of the
313 URL to maintain the clarity of what information goes where in the
314 string.
315
316 Suppose that the person in the example from above did in fact have
317 an authentication username of "adamson" and that information was
318 kept in the attribute "uid" in their LDAP entry. The {{EX:saslRegexp}}
319 directive might be written as
320
321 >       saslRegexp 
322 >         uid=(.*),cn=example.com,cn=kerberos_v4,cn=authzid  
323 >         ldap://localhost/ou=person,dc=example,dc=com??sub?uid=$1
324
325 This will initiate an internal search of the LDAP database inside
326 the slapd server. If the search returns exactly one entry, it is
327 accepted as being the DN of the user. If there are more than one
328 entries returned, or if there are zero entries returned, the
329 authentication fails and the user's connection is left bound as
330 the authentication request DN.
331
332 Note that if the search scope <scope> in the URL is "base", then
333 the only LDAP entry that will be returned is the searchbase DN
334 <base>, so the actual search of the database is skipped. This is
335 equivalent to setting the replacement pattern in the directive to
336 a DN directly, as in the section above.
337
338 The attributes that are used in the search filter <filter> in the
339 URL should be indexed to allow faster searching. If they are not,
340 the authentication step alone can take uncomfortably long periods,
341 and users may assume the server is down.
342
343
344 H2: SASL Authorization
345
346 The SASL offers a feature known as {{authorization}}, which allows
347 an authenticated user to request that they act on the behalf of
348 another user.  This step occurs after the user has obtained an
349 authentication DN, and involves sending an authorization identity
350 to the server. The server will then make a decision on whether or
351 not to allow the authorization to occur. If it is allowed, the
352 user's LDAP connection is switched to have a binding DN derived
353 from the authorization identity, and the LDAP session proceeds with
354 the access of the new authorization DN.
355
356 The decision to allow an authorization to proceed depends on the
357 rules and policies of the site where LDAP is running, and thus
358 cannot be made by SASL alone. The SASL library leaves it up to the
359 server to make the decision. The LDAP administrator sets the
360 guidelines of who can authorize to what identity by adding information
361 into the LDAP database entries.
362
363
364 H3: Uses of Authorization
365
366 This sort of service is useful when one entity needs to act on the
367 behalf of many other users. For example, users may be directed to
368 a web page to make changes to their personal information in their
369 LDAP entry. The users authenticate to the web server to establish
370 their identity, but the web server CGI cannot authenticate to the
371 LDAP server as that user to make changes for them. Instead, the
372 web server authenticates itself to the LDAP server as a service
373 identity, say,
374
375 >       cn=WebUpdate,dc=example,dc=com
376
377 and then it will SASL authorize to the DN of the user. Once so
378 authorized, the CGI makes changes to the LDAP entry of the user,
379 and as far as the slapd server can tell for its ACLs, it is the
380 user themself on the other end of the connection. The user could
381 have connected to the LDAP server directly and authenticated as
382 themself, but that would require the user to have more knowledge
383 of LDAP clients, knowledge which the web page provides in an easier
384 format.
385
386 Authorization can also be used to limit access to an account that
387 has greater access to the database. Such an account, perhaps even
388 the root DN specified in {{slapd.conf}}(5), can have a strict list
389 of people who can authorize to that DN. Changes to the LDAP database
390 could then be only allowed by that DN, and in order to become that
391 DN, users must first authenticate as one of the persons on the
392 list. This allows for better auditing of who made changes to the
393 LDAP database.  If people were allowed to authenticate directly to
394 the priviliged account, possibly through the {{EX:rootpw}}
395 {{slapd.conf}}(5) directive or through a {{EX:userPassword}}
396 attribute, then auditing becomes more difficult.
397
398 Note that after a successful authorization, the original authentication
399 DN in the LDAP connection is overwritten by the new DN from the
400 authorization request. If a service program is able to authenticate
401 itself as its own authentication DN and then authorize to other
402 DN's, and it is planning on switching to several different identities
403 during one LDAP session, it will need to authenticate itself each
404 time before authorizing to another DN. The slapd server does not
405 keep record of the service program's ability to switch to other
406 DN's.  On authentication mechanisms like Kerberos this will not
407 require multiple connections being made to the Kerberos server,
408 since the user's TGT and "ldap" session key are valid for multiple
409 uses for the several hours of the ticket lifetime.
410
411
412 H3: Authorization Identities
413
414 The authorization identity is sent to the slapd server via the -X
415 switch for {{ldapsearch}}(1) and other tools, or in the *authzid
416 parameter to the {{lutil_sasl_defaults}}() call. The identity can
417 be in one of two forms, either
418
419 >       u:<username>
420
421 or
422
423 >       dn:<dn>
424
425 In the first form, the <username> is from the same namespace as
426 the authentication identities above. It is the user's username as
427 it is refered to by the underlying authentication mechanism.
428 Authorization identities of this form are converted into a DN format
429 by the same function that the authentication process used, producing
430 an {{authorization request DN}} of the form
431
432 >       uid=<username>,cn=<realm>,cn=authzid
433
434 That authorization request DN is then run through the same
435 {{EX:saslRegexp}} process to convert it into a legitimate authorization
436 DN from the database. If it cannot be converted due to a failed
437 search from an LDAP URL, the authorization request fails with
438 "inappropriate access".  Otherwise, the DN string is now a legitimate
439 authorization DN ready to undergo approval.
440
441 If the authorization identity was provided in the second form, with
442 a "dn:" prefix, the string after the prefix is already in authorization
443 DN form, ready to undergo approval.
444
445
446 H3: Authorization rules
447
448 Once slapd has the authorization DN, the actual approval process
449 begins. There are two attributes that the LDAP administrator can
450 put into LDAP entries to allow authorization:
451
452 >       saslAuthzTo
453 >       saslAuthzFrom
454
455 Both can be multivalued. The first is called a source rule, and it
456 is placed into a person's authentication DN entry to tell what
457 other authorization DN's the person is allowed to change to. The
458 second form is called a destination rule, and it is placed into an
459 authorization DN's entry to tell what authenticated DN a person
460 must be coming from in order to switch to that authorization DN.
461 The choice of which form to use is up to the administrator. Source
462 rules are checked first in the person's authentication DN entry,
463 and if none of the saslAuthzTo rules specify the authorization is
464 permitted, the saslAuthzFrom rules in the authorization DN entry
465 are then checked. If neither case specifies that the request be
466 honored, the request is denied with an "inappropriate access"
467 message. Since the default behaviour is to deny authorization
468 requests, rules only specify that a request be allowed; there are
469 no negative rules telling what authorizations to deny.
470
471 The value(s) in the two attributes are of the same form as the
472 output of the replacement pattern of a {{EX:saslRegexp}} directive:
473 either a DN or an LDAP URL. For example, if a saslAuthzTo value is
474 a DN, that DN is one the authenticated user can authorize to. On
475 the other hand, if the saslAuthzTo value is an LDAP URL, the URL
476 is used as an internal search of the LDAP database, and the
477 authenticated user can become ANY DN returned by the search. If an
478 LDAP entry looked like:
479
480 >       dn: cn=WebUpdate,dc=example,dc=com
481 >       saslAuthzTo: ldap://host/dc=example,dc=com??sub?objectclass=Person
482
483 then any user who authenticated as cn=WebUpdate,dc=example,dc=com
484 could authorize to any other LDAP entry under the search base
485 "dc=example,dc=com" which has an objectClass of "Person".
486
487
488 H4: Notes on Authorization rules
489
490 An LDAP URL in a saslAuthzTo or saslAuthzFrom attribute will return
491 a list of DN's, and that list must be linearly scanned. Searches
492 which return a long list can cause the authorization process to
493 take an uncomfortably long time. Also, searches should be performed
494 on attributes that have been indexed by slapd.
495
496 To help produce more sweeping rules for saslAuthzFrom and saslAuthzTo,
497 the values of these attributes are allowed to be DN's with regular
498 expression characters in them. This means a source rule like
499
500 >       saslAuthzTo: uid=.*,dc=example,dc=com
501
502 would allow that authenticated user to authorize to any DN that
503 matches the regular expression pattern given. This regular expression
504 comparison can be evaluated much faster than an LDAP search for
505 "uid=*".
506
507 Also note that the values in an authorization rule must be one of
508 the two forms: an LDAP URL or a DN (with or without regular expression
509 characters). Anything that does not begin with "ldap://" is taken
510 as a DN. It is not permissable to enter another authorization
511 identity of the form "u:<username>" as an authorization rule.
512
513 The decision of which type of rules to use, saslAuthzFrom or
514 saslAuthzTo, will depend on the site's situation. For example, if
515 the set of people who may become a given identity can easily be
516 written as a search filter, then a single destination rule could
517 be written. If the set of people is not easily defined by a search
518 filter, and the set of people is small, it may be better to write
519 a source rule in the entries of each of those people who should be
520 allowed to perform the authorization.
521