]> git.sur5r.net Git - openldap/blob - doc/guide/admin/sasl.sdf
Add GSSAPI section and more
[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 auth
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 {{PROD:Cyrus}} {{PROD::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 breifly outlines security considerations.
40
41 Some mechanisms, such as PLAIN and LOGIN, offer no 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), 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 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 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 read
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 GSSAPI mechanism with {{slapd}}(8) one must create a service
107 key with a principal for {{ldap}} service within 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 obtain 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 associated the non-mapped authentication DN of
126
127 >       uid=user@REALM,cn=GSSAPI,cn=authzid
128
129 for the GSSAPI principal "user@REALM".  The may be subsequently
130 mapped as detailed below.
131
132
133 H3: KERBEROS_V4
134
135 This section describes the use of the SASL KERBEROS_V4 mechanism
136 with OpenLDAP.  It will be assumed that you are familiar with the
137 workings of Kerberos IV security system, and that your site has
138 either Kerberos IV deployed.  Your users should be familiar with
139 authentication policy, are aware of how to receive credentials in
140 a Kerberos ticket cache, and how to refresh expired credentials.
141
142 Client programs will need to be able to obtain a session key for
143 use when connecting to your LDAP server. This allows the LDAP server
144 to know the identity of the user, and allows the client to know it
145 is connecting to a legitimate server. If encryption layers are to
146 be used, the session key can also be used to help negotiate that
147 option.
148
149 The slapd server runs the service called "{{ldap}}", and the server
150 will require a srvtab file with a service key.  SASL aware client
151 programs will be obtaining an "ldap" service ticket with the user's
152 ticket granting ticket (TGT), with the instance of the ticket
153 matching the hostname of the OpenLDAP server. For example, if your
154 realm is named {{EX:EXAMPLE.COM}} and the slapd server is running
155 on the host named {{EX:directory.example.com}}, the {{FILE:/etc/srvtab}}
156 file on the server will have a service key
157
158 >       ldap.directory@EXAMPLE.COM
159
160 When a LDAP client is authenticating a user to the directory using
161 the KERBEROS_IV mechanism, it will request a session key for that
162 same principal, either from the ticket cache or by obtaining a new
163 one from the Kerberos server.  This will require the TGT to be
164 available and valid in the cache as well.  If it is not present or
165 has expired, SASL will print out the message
166
167 >       ldap_sasl_interactive_bind_s: Local error
168
169 When the service ticket is obtained, it will be passed to the LDAP
170 server as proof of the user's identity.  The server will extract
171 the identity and realm out of the service ticket using SASL
172 library calls, and convert them into an {{authentication request
173 DN}} of the form
174
175 >       uid=<username>,cn=<realm>,cn=<mechanism>,cn=authzid
176
177 So in our above example, if the user's name were "adamson", the
178 authentication request DN would be:
179
180 >       uid=ADAMSON,cn=EXAMPLE.COM,cn=KERBEROS_V4,cn=AUTHZID
181
182 This authentication request DN by itself could be placed into ACL's
183 and {{EX:groupOfNames}} "member" attributes, since it is of legitimate
184 LDAP DN format. The next section, however, tells how to map that
185 DN into the DN of a person's own LDAP entry.
186
187 Also note that this example, being for Kerberos, shows the <realm>
188 portion of the DN being filled in with the Kerberos realm of the
189 company. Several other authentication mechanisms do not emply the
190 concept of a realm, so the ",cn=<realm>" portion of the authentication
191 request DN would not appear.
192
193
194 H3: Mapping Authentication identities to LDAP entries
195
196 The authentication mechanism in the slapd server will use SASL
197 library calls to obtain the authenticated user's "username", based
198 on whatever underlying authentication mechanism was used.  This
199 username is in the namespace of the authentication mechanism, and
200 not in the LDAP namespace. As stated in the section above, that
201 username is reformatted into an authentication request DN of the
202 form
203
204 >       uid=<username>,cn=<realm>,cn=<mechanism>,cn=authzid
205
206 or
207
208 >       uid=<username>,cn=<mechanism>,cn=authzid
209
210 depending on whether or not <mechanism> employs the concept of
211 "realms".
212
213 It is not intended that you should add LDAP entries of the above
214 form to your LDAP database. Chances are you have an LDAP entry for
215 each of the people that will be authenticating to LDAP, laid out
216 in your directory tree, and the tree does not start at cn=authzid.
217 But if your site has a clear mapping between the "username" and an
218 LDAP entry for the person, you will be able to configure your LDAP
219 server to automatically map a user's authentication username to
220 their {{authentication DN}}.
221
222 The LDAP administrator will need to tell the slapd server how to
223 map an authentication request DN to a user's authentication DN.
224 This is done by adding one or more {{EX:saslRegexp}} directives to
225 the {{slapd.conf}}(5) file.  This directive takes two arguments:
226
227 >       saslRegexp   <search pattern>   <replacement pattern>
228
229 The authentication request DN is compared to the search pattern
230 using the regular expression functions {{regcomp}}() and {{regexec}}(),
231 and if it matches, it is rewritten as the replacement pattern. If
232 there are multiple {{EX:saslRegexp}} directives, only the first
233 whose search pattern matches the authentication identity is used.
234 The string that is output from the replacement pattern should be
235 the authentication DN of the user, in a legitimate LDAP DN format.
236 It can also be an LDAP URL, which is discussed below.
237
238 The search pattern can contain any of the regular expression
239 characters listed in {{regexec}}(3C). The main characters of note
240 are dot ".", asterisk "*", and the open and close parenthesis "("
241 and ")".  Essentially, the dot matches any character, the asterisk
242 matches one or more characters, and terms in parenthesis are
243 remembered for the replacement pattern.
244
245 The replacement pattern will produce the final authentication DN
246 of the user.  Anything from the authentication request DN that
247 matched a string in parenthesis in the search pattern is stored in
248 the variable "$1". That variable "$1" can appear in the replacement
249 pattern, and will be replaced by the string from the authentication
250 request DN. If there were multiple sets of parenthesis in the search
251 pattern, the variables $2, $3, etc are used.
252
253 For example, suppose the user's authentication identity is written
254 as the DN string
255
256 >       uid=ADAMSON,cn=EXAMPLE.COM,cn=KERBEROS_V4,cn=AUTHZID
257
258 and the user's actual LDAP entry is
259
260 >       uid=ADAMSON,ou=PERSON,dc=EXAMPLE,dc=COM
261
262 The {{EX:saslRegexp}} directive in {{slapd.conf}}(5) could be
263 written
264
265 >       saslRegexp 
266 >         uid=(.*),cn=example.com,cn=kerberos_v4,cn=authzid
267 >         uid=$1,ou=person,dc=example,dc=com
268
269 An even more lenient rule could be written as
270
271 >       saslRegexp
272 >         uid=(.*),.*cn=authzid 
273 >         uid=$1,ou=person,dc=example,dc=com
274
275 Be careful about setting the search pattern too leniently, however,
276 since it may mistakenly allow people to become authenticated as a
277 DN to which they should not have access. It is better to write
278 several strict directives than one lenient directive which has
279 security holes. If there is only one authentication mechanism in
280 place at your site, and zero or one realms in use, you might be
281 able to map between authentication identities and LDAP DN's with
282 a single {{EX:saslRegexp}} directive.
283
284 Some sites may have people's DN's spread to multiple areas of the
285 LDAP tree, such as if there were an ou=accounting tree and an
286 ou=engineering tree, with people interspersed between them. Or
287 there may not be enough information in the authentication identity
288 to isolate the DN, such as if the above person's LDAP entry looked
289 like
290
291 >       dn: cn=mark adamson,ou=person,dc=example,dc=com
292 >       objectclass: Person
293 >       cn: mark adamson
294 >       uid: adamson
295
296 In this case, the information in the authentication identity can
297 only be used to search for the user's DN, not derive it directly.
298 For both of these situations, and others, the replacement pattern
299 in the {{EX:saslRegexp}} directives will need to produce an LDAP
300 URL, described in the next section.
301
302
303 H3: Performing searches for a person's DN
304
305 When there is not enough information in the authentication identity
306 to derive a person's authentication DN directly, the {{EX:saslRegexp}}
307 directives in the {{slapd.conf}}(5) file will need to produce an
308 LDAP URL.  This URL will then be used to perform an internal search
309 of the LDAP database to find the person's authentication DN.
310
311 An LDAP URL, similar to other URL's, is of the form
312
313 >       ldap://<host>/<base>?<attrs>?<scope>?<filter>
314
315 This contains all of the elements necessary to perform an LDAP
316 search:  the name of the server <host>, the LDAP DN search base
317 <base>, the LDAP attributes to retrieve <attrs>, the search scope
318 <scope> which is one of the three options "base", "one", or "sub",
319 and lastly an LDAP search filter <filter>. Since the search is for
320 an LDAP DN on the local machine, the <host> portion is ignored. By
321 the same token the <attrs> field is also ignored since only the DN
322 is of concern.  These two elements are left in the format of the
323 URL to maintain the clarity of what information goes where in the
324 string.
325
326 Suppose that the person in the example from above did in fact have
327 an authentication username of "adamson" and that information was
328 kept in the attribute "uid" in their LDAP entry. The {{EX:saslRegexp}}
329 directive might be written as
330
331 >       saslRegexp 
332 >         uid=(.*),cn=example.com,cn=kerberos_v4,cn=authzid  
333 >         ldap://localhost/ou=person,dc=example,dc=com??sub?uid=$1
334
335 This will initiate an internal search of the LDAP database inside
336 the slapd server. If the search returns exactly one entry, it is
337 accepted as being the DN of the user. If there are more than one
338 entries returned, or if there are zero entries returned, the
339 authentication fails and the user's connection is left bound as
340 the authentication request DN.
341
342 Note that if the search scope <scope> in the URL is "base", then
343 the only LDAP entry that will be returned is the searchbase DN
344 <base>, so the actual search of the database is skipped. This is
345 equivalent to setting the replacement pattern in the directive to
346 a DN directly, as in the section above.
347
348 The attributes that are used in the search filter <filter> in the
349 URL should be indexed to allow faster searching. If they are not,
350 the authentication step alone can take uncomfortably long periods,
351 and users may assume the server is down.
352
353
354 H2: SASL Authorization
355
356 The SASL offers a feature known as {{authorization}}, which allows
357 an authenticated user to request that they act on the behalf of
358 another user.  This step occurs after the user has obtained an
359 authentication DN, and involves sending an authorization identity
360 to the server. The server will then make a decision on whether or
361 not to allow the authorization to occur. If it is allowed, the
362 user's LDAP connection is switched to have a binding DN derived
363 from the authorization identity, and the LDAP session proceeds with
364 the access of the new authorization DN.
365
366 The decision to allow an authorization to proceed depends on the
367 rules and policies of the site where LDAP is running, and thus
368 cannot be made by SASL alone. The SASL library leaves it up to the
369 server to make the decision. The LDAP administrator sets the
370 guidelines of who can authorize to what identity by adding information
371 into the LDAP database entries.
372
373
374 H3: Uses of Authorization
375
376 This sort of service is useful when one entity needs to act on the
377 behalf of many other users. For example, users may be directed to
378 a web page to make changes to their personal information in their
379 LDAP entry. The users authenticate to the web server to establish
380 their identity, but the web server CGI cannot authenticate to the
381 LDAP server as that user to make changes for them. Instead, the
382 web server authenticates itself to the LDAP server as a service
383 identity, say,
384
385 >       cn=WebUpdate,dc=example,dc=com
386
387 and then it will SASL authorize to the DN of the user. Once so
388 authorized, the CGI makes changes to the LDAP entry of the user,
389 and as far as the slapd server can tell for its ACLs, it is the
390 user themself on the other end of the connection. The user could
391 have connected to the LDAP server directly and authenticated as
392 themself, but that would require the user to have more knowledge
393 of LDAP clients, knowledge which the web page provides in an easier
394 format.
395
396 Authorization can also be used to limit access to an account that
397 has greater access to the database. Such an account, perhaps even
398 the root DN specified in {{slapd.conf}}(5), can have a strict list
399 of people who can authorize to that DN. Changes to the LDAP database
400 could then be only allowed by that DN, and in order to become that
401 DN, users must first authenticate as one of the persons on the
402 list. This allows for better auditing of who made changes to the
403 LDAP database.  If people were allowed to authenticate directly to
404 the priviliged account, possibly through the {{EX:rootpw}}
405 {{slapd.conf}}(5) directive or through a {{EX:userPassword}}
406 attribute, then auditing becomes more difficult.
407
408 Note that after a successful authorization, the original authentication
409 DN in the LDAP connection is overwritten by the new DN from the
410 authorization request. If a service program is able to authenticate
411 itself as its own authentication DN and then authorize to other
412 DN's, and it is planning on switching to several different identities
413 during one LDAP session, it will need to authenticate itself each
414 time before authorizing to another DN. The slapd server does not
415 keep record of the service program's ability to switch to other
416 DN's.  On authentication mechanisms like Kerberos this will not
417 require multiple connections being made to the Kerberos server,
418 since the user's TGT and "ldap" session key are valid for multiple
419 uses for the several hours of the ticket lifetime.
420
421
422 H3: Authorization Identities
423
424 The authorization identity is sent to the slapd server via the -X
425 switch for {{ldapsearch}}(1) and other tools, or in the *authzid
426 parameter to the {{lutil_sasl_defaults}}() call. The identity can
427 be in one of two forms, either
428
429 >       u:<username>
430
431 or
432
433 >       dn:<dn>
434
435 In the first form, the <username> is from the same namespace as
436 the authentication identities above. It is the user's username as
437 it is refered to by the underlying authentication mechanism.
438 Authorization identities of this form are converted into a DN format
439 by the same function that the authentication process used, producing
440 an {{authorization request DN}} of the form
441
442 >       uid=<username>,cn=<realm>,cn=authzid
443
444 That authorization request DN is then run through the same
445 {{EX:saslRegexp}} process to convert it into a legitimate authorization
446 DN from the database. If it cannot be converted due to a failed
447 search from an LDAP URL, the authorization request fails with
448 "inappropriate access".  Otherwise, the DN string is now a legitimate
449 authorization DN ready to undergo approval.
450
451 If the authorization identity was provided in the second form, with
452 a "dn:" prefix, the string after the prefix is already in authorization
453 DN form, ready to undergo approval.
454
455
456 H3: Authorization rules
457
458 Once slapd has the authorization DN, the actual approval process
459 begins. There are two attributes that the LDAP administrator can
460 put into LDAP entries to allow authorization:
461
462 >       saslAuthzTo
463 >       saslAuthzFrom
464
465 Both can be multivalued. The first is called a source rule, and it
466 is placed into a person's authentication DN entry to tell what
467 other authorization DN's the person is allowed to change to. The
468 second form is called a destination rule, and it is placed into an
469 authorization DN's entry to tell what authenticated DN a person
470 must be coming from in order to switch to that authorization DN.
471 The choice of which form to use is up to the administrator. Source
472 rules are checked first in the person's authentication DN entry,
473 and if none of the saslAuthzTo rules specify the authorization is
474 permitted, the saslAuthzFrom rules in the authorization DN entry
475 are then checked. If neither case specifies that the request be
476 honored, the request is denied with an "inappropriate access"
477 message. Since the default behaviour is to deny authorization
478 requests, rules only specify that a request be allowed; there are
479 no negative rules telling what authorizations to deny.
480
481 The value(s) in the two attributes are of the same form as the
482 output of the replacement pattern of a {{EX:saslRegexp}} directive:
483 either a DN or an LDAP URL. For example, if a saslAuthzTo value is
484 a DN, that DN is one the authenticated user can authorize to. On
485 the other hand, if the saslAuthzTo value is an LDAP URL, the URL
486 is used as an internal search of the LDAP database, and the
487 authenticated user can become ANY DN returned by the search. If an
488 LDAP entry looked like:
489
490 >       dn: cn=WebUpdate,dc=example,dc=com
491 >       saslAuthzTo: ldap://host/dc=example,dc=com??sub?objectclass=Person
492
493 then any user who authenticated as cn=WebUpdate,dc=example,dc=com
494 could authorize to any other LDAP entry under the search base
495 "dc=example,dc=com" which has an objectClass of "Person".
496
497
498 H4: Notes on Authorization rules
499
500 An LDAP URL in a saslAuthzTo or saslAuthzFrom attribute will return
501 a list of DN's, and that list must be linearly scanned. Searches
502 which return a long list can cause the authorization process to
503 take an uncomfortably long time. Also, searches should be performed
504 on attributes that have been indexed by slapd.
505
506 To help produce more sweeping rules for saslAuthzFrom and saslAuthzTo,
507 the values of these attributes are allowed to be DN's with regular
508 expression characters in them. This means a source rule like
509
510 >       saslAuthzTo: uid=.*,dc=example,dc=com
511
512 would allow that authenticated user to authorize to any DN that
513 matches the regular expression pattern given. This regular expression
514 comparison can be evaluated much faster than an LDAP search for
515 "uid=*".
516
517 Also note that the values in an authorization rule must be one of
518 the two forms: an LDAP URL or a DN (with or without regular expression
519 characters). Anything that does not begin with "ldap://" is taken
520 as a DN. It is not permissable to enter another authorization
521 identity of the form "u:<username>" as an authorization rule.
522
523 The decision of which type of rules to use, saslAuthzFrom or
524 saslAuthzTo, will depend on the site's situation. For example, if
525 the set of people who may become a given identity can easily be
526 written as a search filter, then a single destination rule could
527 be written. If the set of people is not easily defined by a search
528 filter, and the set of people is small, it may be better to write
529 a source rule in the entries of each of those people who should be
530 allowed to perform the authorization.
531