1# $OpenLDAP$ 2# Copyright 1999-2021 The OpenLDAP Foundation, All Rights Reserved. 3# COPYING RESTRICTIONS APPLY, see COPYRIGHT. 4 5H1: Using SASL 6 7OpenLDAP clients and servers are capable of authenticating via the 8{{TERM[expand]SASL}} ({{TERM:SASL}}) framework, which is detailed 9in {{REF:RFC4422}}. This chapter describes how to make use of 10SASL in OpenLDAP. 11 12There are several industry standard authentication mechanisms that 13can be used with SASL, including {{TERM:GSSAPI}} for {{TERM:Kerberos}} 14V, {{TERM:DIGEST-MD5}}, and {{TERM:PLAIN}} and {{TERM:EXTERNAL}} 15for use with {{TERM[expand]TLS}} (TLS). 16 17The standard client tools provided with OpenLDAP Software, such as 18{{ldapsearch}}(1) and {{ldapmodify}}(1), will by default attempt 19to authenticate the user to the {{TERM:LDAP}} directory server using 20SASL. Basic authentication service can be set up by the LDAP 21administrator with a few steps, allowing users to be authenticated 22to the slapd server as their LDAP entry. With a few extra steps, 23some users and services can be allowed to exploit SASL's proxy 24authorization feature, allowing them to authenticate themselves and 25then switch their identity to that of another user or service. 26 27This chapter assumes you have read {{Cyrus SASL for System 28Administrators}}, provided with the {{PRD:Cyrus SASL}} 29package (in {{FILE:doc/sysadmin.html}}) and have a working Cyrus 30SASL installation. You should use the Cyrus SASL {{EX:sample_client}} 31and {{EX:sample_server}} to test your SASL installation before 32attempting to make use of it with OpenLDAP Software. 33 34Note that in the following text the term {{user}} is used to describe 35a person or application entity who is connecting to the LDAP server 36via an LDAP client, such as {{ldapsearch}}(1). That is, the term 37{{user}} not only applies to both an individual using an LDAP client, 38but to an application entity which issues LDAP client operations 39without direct user control. For example, an e-mail server which 40uses LDAP operations to access information held in an LDAP server 41is an application entity. 42 43 44H2: SASL Security Considerations 45 46SASL offers many different authentication mechanisms. This section 47briefly outlines security considerations. 48 49Some mechanisms, such as PLAIN and LOGIN, offer no greater security 50over LDAP {{simple}} authentication. Like LDAP {{simple}} 51authentication, such mechanisms should not be used unless you have 52adequate security protections in place. It is recommended that 53these mechanisms be used only in conjunction with {{TERM[expand]TLS}} 54(TLS). Use of PLAIN and LOGIN are not discussed further in this 55document. 56 57The DIGEST-MD5 mechanism is the mandatory-to-implement authentication 58mechanism for LDAPv3. Though DIGEST-MD5 is not a strong authentication 59mechanism in comparison with trusted third party authentication 60systems (such as {{TERM:Kerberos}} or public key systems), it does 61offer significant protections against a number of attacks. Unlike 62the {{TERM:CRAM-MD5}} mechanism, it prevents chosen plaintext 63attacks. DIGEST-MD5 is favored over the use of plaintext password 64mechanisms. The CRAM-MD5 mechanism is deprecated in favor of 65DIGEST-MD5. Use of {{SECT:DIGEST-MD5}} is discussed below. 66 67The GSSAPI mechanism utilizes {{TERM:GSS-API}} {{TERM:Kerberos}} V 68to provide secure authentication services. The KERBEROS_V4 mechanism 69is available for those using Kerberos IV. Kerberos is viewed as a 70secure, distributed authentication system suitable for both small 71and large enterprises. Use of {{SECT:GSSAPI}} and {{SECT:KERBEROS_V4}} 72are discussed below. 73 74The EXTERNAL mechanism utilizes authentication services provided 75by lower level network services such as {{TERM[expand]TLS}} ({{TERM:TLS}}). When 76used in conjunction with {{TERM:TLS}} {{TERM:X.509}}-based public 77key technology, EXTERNAL offers strong authentication. 78TLS is discussed in the {{SECT:Using TLS}} chapter. 79 80EXTERNAL can also be used with the {{EX:ldapi:///}} transport, as 81Unix-domain sockets can report the UID and GID of the client process. 82 83There are other strong authentication mechanisms to choose from, 84including {{TERM:OTP}} (one time passwords) and {{TERM:SRP}} (secure 85remote passwords). These mechanisms are not discussed in this 86document. 87 88 89H2: SASL Authentication 90 91Getting basic SASL authentication running involves a few steps. 92The first step configures your slapd server environment so that it 93can communicate with client programs using the security system in 94place at your site. This usually involves setting up a service key, 95a public key, or other form of secret. The second step concerns 96mapping authentication identities to LDAP {{TERM:DN}}'s, which 97depends on how entries are laid out in your directory. An explanation 98of the first step will be given in the next section using Kerberos 99V4 as an example mechanism. The steps necessary for your site's 100authentication mechanism will be similar, but a guide to every 101mechanism available under SASL is beyond the scope of this chapter. 102The second step is described in the section {{SECT:Mapping 103Authentication Identities}}. 104 105 106H3: GSSAPI 107 108This section describes the use of the SASL GSSAPI mechanism and 109Kerberos V with OpenLDAP. It will be assumed that you have Kerberos 110V deployed, you are familiar with the operation of the system, and 111that your users are trained in its use. This section also assumes 112you have familiarized yourself with the use of the GSSAPI mechanism 113by reading {{Configuring GSSAPI and Cyrus SASL}} (provided with 114Cyrus SASL in the {{FILE:doc/gssapi}} file) and successfully 115experimented with the Cyrus provided {{EX:sample_server}} and 116{{EX:sample_client}} applications. General information about 117Kerberos is available at {{URL:http://web.mit.edu/kerberos/www/}}. 118 119To use the GSSAPI mechanism with {{slapd}}(8) one must create a service 120key with a principal for {{ldap}} service within the realm for the host 121on which the service runs. For example, if you run {{slapd}} on 122{{EX:directory.example.com}} and your realm is {{EX:EXAMPLE.COM}}, 123you need to create a service key with the principal: 124 125> ldap/directory.example.com@EXAMPLE.COM 126 127When {{slapd}}(8) runs, it must have access to this key. This is 128generally done by placing the key into a keytab file, 129{{FILE:/etc/krb5.keytab}}. See your Kerberos and Cyrus SASL 130documentation for information regarding keytab location settings. 131 132To use the GSSAPI mechanism to authenticate to the directory, the 133user obtains a Ticket Granting Ticket (TGT) prior to running the 134LDAP client. When using OpenLDAP client tools, the user may mandate 135use of the GSSAPI mechanism by specifying {{EX:-Y GSSAPI}} as a 136command option. 137 138For the purposes of authentication and authorization, {{slapd}}(8) 139associates an authentication request DN of the form: 140 141> uid=<primary[/instance][@realm]>,cn=gssapi,cn=auth 142 143The realm is omitted by Cyrus SASL if it's equal to the default realm of the 144server in {{FILE:/etc/krb5.conf}}. 145 146Continuing our example, a user with the Kerberos principal 147{{EX:kurt@EXAMPLE.COM}} would have the associated DN: 148 149> uid=kurt,cn=gssapi,cn=auth 150 151and the principal {{EX:ursula/admin@FOREIGN.REALM}} would have the 152associated DN: 153 154> uid=ursula/admin@foreign.realm,cn=gssapi,cn=auth 155 156 157The authentication request DN can be used directly in ACLs and 158{{EX:groupOfNames}} "member" attributes, since it is of legitimate 159LDAP DN format. Or alternatively, the authentication DN could be 160mapped before use. See the section {{SECT:Mapping Authentication 161Identities}} for details. 162 163If you configure the {{olcSaslRealm}} then it will be inserted as 164an extra component in the authorization DN, regardless of any 165Kerberos realms in use. For example, if you set olcSaslRealm to 166{{EX:example.com}} then you will get: 167 168> uid=kurt,cn=example.com,cn=gssapi,cn=auth 169> uid=ursula/admin@foreign.realm,cn=example.com,cn=gssapi,cn=auth 170 171H3: KERBEROS_V4 172 173This section describes the use of the SASL KERBEROS_V4 mechanism 174with OpenLDAP. It will be assumed that you are familiar with the 175workings of the Kerberos IV security system, and that your site has 176Kerberos IV deployed. Your users should be familiar with 177authentication policy, how to receive credentials in 178a Kerberos ticket cache, and how to refresh expired credentials. 179 180Note: KERBEROS_V4 and Kerberos IV are deprecated in favor of GSSAPI 181and Kerberos V. 182 183Client programs will need to be able to obtain a session key for 184use when connecting to your LDAP server. This allows the LDAP server 185to know the identity of the user, and allows the client to know it 186is connecting to a legitimate server. If encryption layers are to 187be used, the session key can also be used to help negotiate that 188option. 189 190The slapd server runs the service called "{{ldap}}", and the server 191will require a srvtab file with a service key. SASL aware client 192programs will be obtaining an "ldap" service ticket with the user's 193ticket granting ticket (TGT), with the instance of the ticket 194matching the hostname of the OpenLDAP server. For example, if your 195realm is named {{EX:EXAMPLE.COM}} and the slapd server is running 196on the host named {{EX:directory.example.com}}, the {{FILE:/etc/srvtab}} 197file on the server will have a service key 198 199> ldap.directory@EXAMPLE.COM 200 201When an LDAP client is authenticating a user to the directory using 202the KERBEROS_IV mechanism, it will request a session key for that 203same principal, either from the ticket cache or by obtaining a new 204one from the Kerberos server. This will require the TGT to be 205available and valid in the cache as well. If it is not present or 206has expired, the client may print out the message: 207 208> ldap_sasl_interactive_bind_s: Local error 209 210When the service ticket is obtained, it will be passed to the LDAP 211server as proof of the user's identity. The server will extract 212the identity and realm out of the service ticket using SASL 213library calls, and convert them into an {{authentication request 214DN}} of the form 215 216> uid=<username>,cn=<realm>,cn=<mechanism>,cn=auth 217 218So in our above example, if the user's name were "adamson", the 219authentication request DN would be: 220 221> uid=adamson,cn=example.com,cn=kerberos_v4,cn=auth 222 223This authentication request DN can be used directly ACLs or, 224alternatively, mapped prior to use. See the section {{SECT:Mapping 225Authentication Identities}} for details. 226 227 228H3: DIGEST-MD5 229 230This section describes the use of the SASL DIGEST-MD5 mechanism 231using secrets stored either in the directory itself or in Cyrus 232SASL's own database. DIGEST-MD5 relies on the client and the server 233sharing a "secret", usually a password. The server generates a 234challenge and the client a response proving that it knows the shared 235secret. This is much more secure than simply sending the secret 236over the wire. 237 238Cyrus SASL supports several shared-secret mechanisms. To do this, 239it needs access to the plaintext password (unlike mechanisms which 240pass plaintext passwords over the wire, where the server can store 241a hashed version of the password). 242 243The server's copy of the shared-secret may be stored in Cyrus SASL's 244own {{sasldb}} database, in an external system accessed via 245{{saslauthd}}, or in LDAP database itself. In either case it is 246very important to apply file access controls and LDAP access controls 247to prevent exposure of the passwords. The configuration and commands 248discussed in this section assume the use of Cyrus SASL 2.1. 249 250To use secrets stored in {{sasldb}}, simply add users with the 251{{saslpasswd2}} command: 252 253> saslpasswd2 -c <username> 254 255The passwords for such users must be managed with the {{saslpasswd2}} 256command. 257 258To use secrets stored in the LDAP directory, place plaintext passwords 259in the {{EX:userPassword}} attribute. It will be necessary to add 260an option to {{EX:slapd.conf}} to make sure that passwords set using 261the LDAP Password Modify Operation are stored in plaintext: 262 263> password-hash {CLEARTEXT} 264 265Passwords stored in this way can be managed either with {{ldappasswd}}(1) 266or by simply modifying the {{EX:userPassword}} attribute. Regardless of 267where the passwords are stored, a mapping will be needed from 268authentication request DN to user's DN. 269 270The DIGEST-MD5 mechanism produces authentication IDs of the form: 271 272> uid=<username>,cn=<realm>,cn=digest-md5,cn=auth 273 274If the default realm is used, the realm name is omitted from the ID, 275giving: 276 277> uid=<username>,cn=digest-md5,cn=auth 278 279See {{SECT: Mapping Authentication Identities}} below for information 280on optional mapping of identities. 281 282With suitable mappings in place, users can specify SASL IDs when 283performing LDAP operations, and the password stored in {{sasldb}} or in 284the directory itself will be used to verify the authentication. 285For example, the user identified by the directory entry: 286 287> dn: cn=Andrew Findlay+uid=u000997,dc=example,dc=com 288> objectclass: inetOrgPerson 289> objectclass: person 290> sn: Findlay 291> uid: u000997 292> userPassword: secret 293 294can issue commands of the form: 295 296> ldapsearch -Y DIGEST-MD5 -U u000997 ... 297 298Note: in each of the above cases, no authorization identity (e.g. 299{{EX:-X}}) was provided. Unless you are attempting {{SECT:SASL 300Proxy Authorization}}, no authorization identity should be specified. 301The server will infer an authorization identity from authentication 302identity (as described below). 303 304 305H3: EXTERNAL 306 307The SASL EXTERNAL mechanism makes use of an authentication performed 308by a lower-level protocol: usually {{TERM:TLS}} or Unix {{TERM:IPC}} 309 310Each transport protocol returns Authentication Identities in its own 311format: 312 313H4: TLS Authentication Identity Format 314 315This is the Subject DN from the client-side certificate. 316Note that DNs are displayed differently by LDAP and by X.509, so 317a certificate issued to 318> C=gb, O=The Example Organisation, CN=A Person 319 320will produce an authentication identity of: 321 322> cn=A Person,o=The Example Organisation,c=gb 323 324Note that you must set a suitable value for TLSVerifyClient to make the server 325request the use of a client-side certificate. Without this, the SASL EXTERNAL 326mechanism will not be offered. 327Refer to the {{SECT:Using TLS}} chapter for details. 328 329H4: IPC (ldapi:///) Identity Format 330 331This is formed from the Unix UID and GID of the client process: 332 333> gidNumber=<number>+uidNumber=<number>,cn=peercred,cn=external,cn=auth 334 335Thus, a client process running as {{EX:root}} will be: 336 337> gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth 338 339 340H3: Mapping Authentication Identities 341 342The authentication mechanism in the slapd server will use SASL 343library calls to obtain the authenticated user's "username", based 344on whatever underlying authentication mechanism was used. This 345username is in the namespace of the authentication mechanism, and 346not in the normal LDAP namespace. As stated in the sections above, 347that username is reformatted into an authentication request DN of 348the form 349 350> uid=<username>,cn=<realm>,cn=<mechanism>,cn=auth 351 352or 353 354> uid=<username>,cn=<mechanism>,cn=auth 355 356depending on whether or not <mechanism> employs the concept of 357"realms". Note also that the realm part will be omitted if the 358default realm was used in the authentication. 359 360The {{ldapwhoami}}(1) command may be used to determine the identity 361associated with the user. It is very useful for determining proper 362function of mappings. 363 364It is not intended that you should add LDAP entries of the above 365form to your LDAP database. Chances are you have an LDAP entry for 366each of the persons that will be authenticating to LDAP, laid out 367in your directory tree, and the tree does not start at cn=auth. 368But if your site has a clear mapping between the "username" and an 369LDAP entry for the person, you will be able to configure your LDAP 370server to automatically map a authentication request DN to the 371user's {{authentication DN}}. 372 373Note: it is not required that the authentication request DN nor the 374user's authentication DN resulting from the mapping refer to an 375entry held in the directory. However, additional capabilities 376become available (see below). 377 378The LDAP administrator will need to tell the slapd server how to 379map an authentication request DN to a user's authentication DN. 380This is done by adding one or more {{EX:authz-regexp}} directives to 381the {{slapd.conf}}(5) file. This directive takes two arguments: 382 383> authz-regexp <search pattern> <replacement pattern> 384 385The authentication request DN is compared to the search pattern 386using the regular expression functions {{regcomp}}() and {{regexec}}(), 387and if it matches, it is rewritten as the replacement pattern. If 388there are multiple {{EX:authz-regexp}} directives, only the first 389whose search pattern matches the authentication identity is used. 390The string that is output from the replacement pattern should be 391the authentication DN of the user or an LDAP URL. If replacement 392string produces a DN, the entry named by this DN need not be held 393by this server. If the replace string produces an LDAP URL, that 394LDAP URL must evaluate to one and only one entry held by this server. 395 396The search pattern can contain any of the regular expression 397characters listed in {{regexec}}(3C). The main characters of note 398are dot ".", asterisk "*", and the open and close parenthesis "(" 399and ")". Essentially, the dot matches any character, the asterisk 400allows zero or more repeats of the immediately preceding character 401or pattern, and terms in parenthesis are remembered for the replacement 402pattern. 403 404The replacement pattern will produce either a DN or URL referring 405to the user. Anything from the authentication request DN that 406matched a string in parenthesis in the search pattern is stored in 407the variable "$1". That variable "$1" can appear in the replacement 408pattern, and will be replaced by the string from the authentication 409request DN. If there were multiple sets of parentheses in the search 410pattern, the variables $2, $3, etc are used. 411 412H3: Direct Mapping 413 414Where possible, direct mapping of the authentication request DN to 415the user's DN is generally recommended. Aside from avoiding the 416expense of searching for the user's DN, it allows mapping to 417DNs which refer to entries not held by this server. 418 419Suppose the authentication request DN is written as: 420 421> uid=adamson,cn=example.com,cn=gssapi,cn=auth 422 423and the user's actual LDAP entry is: 424 425> uid=adamson,ou=people,dc=example,dc=com 426 427then the following {{EX:authz-regexp}} directive in {{slapd.conf}}(5) 428would provide for direct mapping. 429 430> authz-regexp 431> uid=([^,]*),cn=example.com,cn=gssapi,cn=auth 432> uid=$1,ou=people,dc=example,dc=com 433 434An even more lenient rule could be written as 435 436> authz-regexp 437> uid=([^,]*),cn=[^,]*,cn=auth 438> uid=$1,ou=people,dc=example,dc=com 439 440Be careful about setting the search pattern too leniently, however, 441since it may mistakenly allow persons to become authenticated as a 442DN to which they should not have access. It is better to write 443several strict directives than one lenient directive which has 444security holes. If there is only one authentication mechanism in 445place at your site, and zero or one realms in use, you might be 446able to map between authentication identities and LDAP DN's with a 447single {{EX:authz-regexp}} directive. 448 449Don't forget to allow for the case where the realm is omitted as 450well as the case with an explicitly specified realm. This may well 451require a separate {{EX:authz-regexp}} directive for each case, with 452the explicit-realm entry being listed first. 453 454H3: Search-based mappings 455 456There are a number of cases where mapping to a LDAP URL may be 457appropriate. For instance, some sites may have person objects 458located in multiple areas of the LDAP tree, such as if there were 459an {{EX:ou=accounting}} tree and an {{EX:ou=engineering}} tree, 460with persons interspersed between them. Or, maybe the desired 461mapping must be based upon information in the user's information. 462Consider the need to map the above authentication request DN to 463user whose entry is as follows: 464 465> dn: cn=Mark Adamson,ou=People,dc=Example,dc=COM 466> objectclass: person 467> cn: Mark Adamson 468> uid: adamson 469 470The information in the authentication request DN is insufficient 471to allow the user's DN to be directly derived, instead the user's 472DN must be searched for. For these situations, a replacement pattern 473which produces a LDAP URL can be used in the {{EX:authz-regexp}} 474directives. This URL will then be used to perform an internal 475search of the LDAP database to find the person's authentication DN. 476 477An LDAP URL, similar to other URL's, is of the form 478 479> ldap://<host>/<base>?<attrs>?<scope>?<filter> 480 481This contains all of the elements necessary to perform an LDAP 482search: the name of the server <host>, the LDAP DN search base 483<base>, the LDAP attributes to retrieve <attrs>, the search scope 484<scope> which is one of the three options "base", "one", or "sub", 485and lastly an LDAP search filter <filter>. Since the search is for 486an LDAP DN within the current server, the <host> portion should be 487empty. The <attrs> field is also ignored since only the DN is of 488concern. These two elements are left in the format of the URL to 489maintain the clarity of what information goes where in the string. 490 491Suppose that the person in the example from above did in fact have 492an authentication username of "adamson" and that information was 493kept in the attribute "uid" in their LDAP entry. The {{EX:authz-regexp}} 494directive might be written as 495 496> authz-regexp 497> uid=([^,]*),cn=example.com,cn=gssapi,cn=auth 498> ldap:///ou=people,dc=example,dc=com??one?(uid=$1) 499 500This will initiate an internal search of the LDAP database inside 501the slapd server. If the search returns exactly one entry, it is 502accepted as being the DN of the user. If there are more than one 503entries returned, or if there are zero entries returned, the 504authentication fails and the user's connection is left bound as the 505authentication request DN. 506 507The attributes that are used in the search filter <filter> in the 508URL should be indexed to allow faster searching. If they are not, 509the authentication step alone can take uncomfortably long periods, 510and users may assume the server is down. 511 512A more complex site might have several realms in use, each mapping 513to a different subtree in the directory. These can be handled with 514statements of the form: 515 516> # Match Engineering realm 517> authz-regexp 518> uid=([^,]*),cn=engineering.example.com,cn=digest-md5,cn=auth 519> ldap:///dc=eng,dc=example,dc=com??one?(&(uid=$1)(objectClass=person)) 520> 521> # Match Accounting realm 522> authz-regexp 523> uid=([^,].*),cn=accounting.example.com,cn=digest-md5,cn=auth 524> ldap:///dc=accounting,dc=example,dc=com??one?(&(uid=$1)(objectClass=person)) 525> 526> # Default realm is customers.example.com 527> authz-regexp 528> uid=([^,]*),cn=digest-md5,cn=auth 529> ldap:///dc=customers,dc=example,dc=com??one?(&(uid=$1)(objectClass=person)) 530 531Note that the explicitly-named realms are handled first, to avoid 532the realm name becoming part of the UID. Also note the use of scope 533and filters to limit matching to desirable entries. 534 535Note as well that {{EX:authz-regexp}} internal search are subject 536to access controls. Specifically, the authentication identity 537must have {{EX:auth}} access. 538 539See {{slapd.conf}}(5) for more detailed information. 540 541 542H2: SASL Proxy Authorization 543 544The SASL offers a feature known as {{proxy authorization}}, which 545allows an authenticated user to request that they act on the behalf 546of another user. This step occurs after the user has obtained an 547authentication DN, and involves sending an authorization identity 548to the server. The server will then make a decision on whether or 549not to allow the authorization to occur. If it is allowed, the 550user's LDAP connection is switched to have a binding DN derived 551from the authorization identity, and the LDAP session proceeds with 552the access of the new authorization DN. 553 554The decision to allow an authorization to proceed depends on the 555rules and policies of the site where LDAP is running, and thus 556cannot be made by SASL alone. The SASL library leaves it up to the 557server to make the decision. The LDAP administrator sets the 558guidelines of who can authorize to what identity by adding information 559into the LDAP database entries. By default, the authorization 560features are disabled, and must be explicitly configured by the 561LDAP administrator before use. 562 563 564H3: Uses of Proxy Authorization 565 566This sort of service is useful when one entity needs to act on the 567behalf of many other users. For example, users may be directed to 568a web page to make changes to their personal information in their 569LDAP entry. The users authenticate to the web server to establish 570their identity, but the web server CGI cannot authenticate to the 571LDAP server as that user to make changes for them. Instead, the 572web server authenticates itself to the LDAP server as a service 573identity, say, 574 575> cn=WebUpdate,dc=example,dc=com 576 577and then it will SASL authorize to the DN of the user. Once so 578authorized, the CGI makes changes to the LDAP entry of the user, 579and as far as the slapd server can tell for its ACLs, it is the 580user themself on the other end of the connection. The user could 581have connected to the LDAP server directly and authenticated as 582themself, but that would require the user to have more knowledge 583of LDAP clients, knowledge which the web page provides in an easier 584format. 585 586Proxy authorization can also be used to limit access to an account 587that has greater access to the database. Such an account, perhaps 588even the root DN specified in {{slapd.conf}}(5), can have a strict 589list of people who can authorize to that DN. Changes to the LDAP 590database could then be only allowed by that DN, and in order to 591become that DN, users must first authenticate as one of the persons 592on the list. This allows for better auditing of who made changes 593to the LDAP database. If people were allowed to authenticate 594directly to the privileged account, possibly through the {{EX:rootpw}} 595{{slapd.conf}}(5) directive or through a {{EX:userPassword}} 596attribute, then auditing becomes more difficult. 597 598Note that after a successful proxy authorization, the original 599authentication DN of the LDAP connection is overwritten by the new 600DN from the authorization request. If a service program is able to 601authenticate itself as its own authentication DN and then authorize 602to other DN's, and it is planning on switching to several different 603identities during one LDAP session, it will need to authenticate 604itself each time before authorizing to another DN (or use a different 605proxy authorization mechanism). The slapd server does not keep 606record of the service program's ability to switch to other DN's. 607On authentication mechanisms like Kerberos this will not require 608multiple connections being made to the Kerberos server, since the 609user's TGT and "ldap" session key are valid for multiple uses for 610the several hours of the ticket lifetime. 611 612 613H3: SASL Authorization Identities 614 615The SASL authorization identity is sent to the LDAP server via the 616{{EX:-X}} switch for {{ldapsearch}}(1) and other tools, or in the 617{{EX:*authzid}} parameter to the {{lutil_sasl_defaults}}() call. 618The identity can be in one of two forms, either 619 620> u:<username> 621 622or 623 624> dn:<dn> 625 626In the first form, the <username> is from the same namespace as 627the authentication identities above. It is the user's username as 628it is referred to by the underlying authentication mechanism. 629Authorization identities of this form are converted into a DN format 630by the same function that the authentication process used, producing 631an {{authorization request DN}} of the form 632 633> uid=<username>,cn=<realm>,cn=<mechanism>,cn=auth 634 635That authorization request DN is then run through the same 636{{EX:authz-regexp}} process to convert it into a legitimate authorization 637DN from the database. If it cannot be converted due to a failed 638search from an LDAP URL, the authorization request fails with 639"inappropriate access". Otherwise, the DN string is now a legitimate 640authorization DN ready to undergo approval. 641 642If the authorization identity was provided in the second form, with 643a {{EX:"dn:"}} prefix, the string after the prefix is already in 644authorization DN form, ready to undergo approval. 645 646 647H3: Proxy Authorization Rules 648 649Once slapd has the authorization DN, the actual approval process 650begins. There are two attributes that the LDAP administrator can 651put into LDAP entries to allow authorization: 652 653> authzTo 654> authzFrom 655 656Both can be multivalued. The {{EX:authzTo}} attribute is a 657source rule, and it is placed into the entry associated with the 658authentication DN to tell what authorization DNs the authenticated 659DN is allowed to assume. The second attribute is a destination 660rule, and it is placed into the entry associated with the requested 661authorization DN to tell which authenticated DNs may assume it. 662 663The choice of which authorization policy attribute to use is up to 664the administrator. Source rules are checked first in the person's 665authentication DN entry, and if none of the {{EX:authzTo}} rules 666specify the authorization is permitted, the {{EX:authzFrom}} 667rules in the authorization DN entry are then checked. If neither 668case specifies that the request be honored, the request is denied. 669Since the default behavior is to deny authorization requests, rules 670only specify that a request be allowed; there are no negative rules 671telling what authorizations to deny. 672 673The value(s) in the two attributes are of the same form as the 674output of the replacement pattern of a {{EX:authz-regexp}} directive: 675either a DN or an LDAP URL. For example, if a {{EX:authzTo}} 676value is a DN, that DN is one the authenticated user can authorize 677to. On the other hand, if the {{EX:authzTo}} value is an LDAP 678URL, the URL is used as an internal search of the LDAP database, 679and the authenticated user can become ANY DN returned by the search. 680If an LDAP entry looked like: 681 682> dn: cn=WebUpdate,dc=example,dc=com 683> authzTo: ldap:///dc=example,dc=com??sub?(objectclass=person) 684 685then any user who authenticated as {{EX:cn=WebUpdate,dc=example,dc=com}} 686could authorize to any other LDAP entry under the search base 687{{EX:dc=example,dc=com}} which has an objectClass of {{EX:Person}}. 688 689 690H4: Notes on Proxy Authorization Rules 691 692An LDAP URL in a {{EX:authzTo}} or {{EX:authzFrom}} attribute 693will return a set of DNs. Each DN returned will be checked. Searches 694which return a large set can cause the authorization process to 695take an uncomfortably long time. Also, searches should be performed 696on attributes that have been indexed by slapd. 697 698To help produce more sweeping rules for {{EX:authzFrom}} and 699{{EX:authzTo}}, the values of these attributes are allowed to 700be DNs with regular expression characters in them. This means a 701source rule like 702 703> authzTo: dn.regex:^uid=[^,]*,dc=example,dc=com$ 704 705would allow that authenticated user to authorize to any DN that 706matches the regular expression pattern given. This regular expression 707comparison can be evaluated much faster than an LDAP search for 708{{EX:(uid=*)}}. 709 710Also note that the values in an authorization rule must be one of 711the two forms: an LDAP URL or a DN (with or without regular expression 712characters). Anything that does not begin with "{{EX:ldap://}}" is 713taken as a DN. It is not permissible to enter another authorization 714identity of the form "{{EX:u:<username>}}" as an authorization rule. 715 716 717H4: Policy Configuration 718 719The decision of which type of rules to use, {{EX:authzFrom}} 720or {{EX:authzTo}}, will depend on the site's situation. For 721example, if the set of people who may become a given identity can 722easily be written as a search filter, then a single destination 723rule could be written. If the set of people is not easily defined 724by a search filter, and the set of people is small, it may be better 725to write a source rule in the entries of each of those people who 726should be allowed to perform the proxy authorization. 727 728By default, processing of proxy authorization rules is disabled. 729The {{EX:authz-policy}} directive must be set in the 730{{slapd.conf}}(5) file to enable authorization. This directive can 731be set to {{EX:none}} for no rules (the default), {{EX:to}} for 732source rules, {{EX:from}} for destination rules, or {{EX:both}} for 733both source and destination rules. 734 735Source rules are extremely powerful. If ordinary users have 736access to write the {{EX:authzTo}} attribute in their own 737entries, then they can write rules that would allow them to authorize 738as anyone else. As such, when using source rules, the 739{{EX:authzTo}} attribute should be protected with an ACL that 740only allows privileged users to set its values. 741 742