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