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