📄 sasl.sdf
字号:
The search pattern can contain any of the regular expressioncharacters listed in {{regexec}}(3C). The main characters of noteare dot ".", asterisk "*", and the open and close parenthesis "("and ")". Essentially, the dot matches any character, the asteriskallows zero or more repeats of the immediately preceding characteror pattern, and terms in parenthesis are remembered for the replacementpattern.The replacement pattern will produce either a DN or URL referingto the user. Anything from the authentication request DN thatmatched a string in parenthesis in the search pattern is stored inthe variable "$1". That variable "$1" can appear in the replacementpattern, and will be replaced by the string from the authenticationrequest DN. If there were multiple sets of parentheses in the searchpattern, the variables $2, $3, etc are used.H3: Direct MappingWhere possible, direct mapping of the authentication request DN tothe user's DN is generally recommended. Aside from avoiding theexpense of searching for the user's DN, it allows mapping toDNs which refer to entries not held by this server. Suppose the authentication request DN is written as:> uid=adamson,cn=example.com,cn=gssapi,cn=authand the user's actual LDAP entry is:> uid=adamson,ou=people,dc=example,dc=comthen the following {{EX:authz-regexp}} directive in {{slapd.conf}}(5)would provide for direct mapping.> authz-regexp > uid=([^,]*),cn=example.com,cn=gssapi,cn=auth> uid=$1,ou=people,dc=example,dc=comAn even more lenient rule could be written as> authz-regexp> uid=([^,]*),cn=[^,]*,cn=auth > uid=$1,ou=people,dc=example,dc=comBe careful about setting the search pattern too leniently, however,since it may mistakenly allow persons to become authenticated as aDN to which they should not have access. It is better to writeseveral strict directives than one lenient directive which hassecurity holes. If there is only one authentication mechanism inplace at your site, and zero or one realms in use, you might beable to map between authentication identities and LDAP DN's with asingle {{EX:authz-regexp}} directive.Don't forget to allow for the case where the realm is omitted aswell as the case with an explicitly specified realm. This may wellrequire a separate {{EX:authz-regexp}} directive for each case, withthe explicit-realm entry being listed first.H3: Search-based mappingsThere are a number of cases where mapping to a LDAP URL may beappropriate. For instance, some sites may have person objectslocated in multiple areas of the LDAP tree, such as if there werean {{EX:ou=accounting}} tree and an {{EX:ou=engineering}} tree,with persons interspersed between them. Or, maybe the desiredmapping must be based upon information in the user's information.Consider the need to map the above authentication request DN touser whose entry is as follows:> dn: cn=Mark Adamson,ou=People,dc=Example,dc=COM> objectclass: person> cn: Mark Adamson> uid: adamsonThe information in the authentication request DN is insufficientto allow the user's DN to be directly derived, instead the user'sDN must be searched for. For these situations, a replacement patternwhich produces a LDAP URL can be used in the {{EX:authz-regexp}}directives. This URL will then be used to perform an internalsearch of the LDAP database to find the person's authentication DN.An LDAP URL, similar to other URL's, is of the form> ldap://<host>/<base>?<attrs>?<scope>?<filter>This contains all of the elements necessary to perform an LDAPsearch: the name of the server <host>, the LDAP DN search base<base>, the LDAP attributes to retrieve <attrs>, the search scope<scope> which is one of the three options "base", "one", or "sub",and lastly an LDAP search filter <filter>. Since the search is foran LDAP DN within the current server, the <host> portion should beempty. The <attrs> field is also ignored since only the DN is ofconcern. These two elements are left in the format of the URL tomaintain the clarity of what information goes where in the string.Suppose that the person in the example from above did in fact havean authentication username of "adamson" and that information waskept in the attribute "uid" in their LDAP entry. The {{EX:authz-regexp}}directive might be written as> authz-regexp > uid=([^,]*),cn=example.com,cn=gssapi,cn=auth > ldap:///ou=people,dc=example,dc=com??one?(uid=$1)This will initiate an internal search of the LDAP database insidethe slapd server. If the search returns exactly one entry, it isaccepted as being the DN of the user. If there are more than oneentries returned, or if there are zero entries returned, theauthentication fails and the user's connection is left bound as theauthentication request DN.The attributes that are used in the search filter <filter> in theURL should be indexed to allow faster searching. If they are not,the authentication step alone can take uncomfortably long periods,and users may assume the server is down.A more complex site might have several realms in use, each mappingto a different subtree in the directory. These can be handled withstatements of the form:> # Match Engineering realm> authz-regexp> uid=([^,]*),cn=engineering.example.com,cn=digest-md5,cn=auth> ldap:///dc=eng,dc=example,dc=com??one?(&(uid=$1)(objectClass=person))>> # Match Accounting realm> authz-regexp> uid=([^,].*),cn=accounting.example.com,cn=digest-md5,cn=auth> ldap:///dc=accounting,dc=example,dc=com??one?(&(uid=$1)(objectClass=person))>> # Default realm is customers.example.com> authz-regexp> uid=([^,]*),cn=digest-md5,cn=auth> ldap:///dc=customers,dc=example,dc=com??one?(&(uid=$1)(objectClass=person))Note that the explicitly-named realms are handled first, to avoidthe realm name becoming part of the UID. Also note the use of scopeand filters to limit matching to desirable entries.See {{slapd.conf}}(5) for more detailed information.H2: SASL Proxy AuthorizationThe SASL offers a feature known as {{proxy authorization}}, whichallows an authenticated user to request that they act on the behalfof another user. This step occurs after the user has obtained anauthentication DN, and involves sending an authorization identityto the server. The server will then make a decision on whether ornot to allow the authorization to occur. If it is allowed, theuser's LDAP connection is switched to have a binding DN derivedfrom the authorization identity, and the LDAP session proceeds withthe access of the new authorization DN.The decision to allow an authorization to proceed depends on therules and policies of the site where LDAP is running, and thuscannot be made by SASL alone. The SASL library leaves it up to theserver to make the decision. The LDAP administrator sets theguidelines of who can authorize to what identity by adding informationinto the LDAP database entries. By default, the authorizationfeatures are disabled, and must be explicitly configured by theLDAP administrator before use.H3: Uses of Proxy AuthorizationThis sort of service is useful when one entity needs to act on thebehalf of many other users. For example, users may be directed toa web page to make changes to their personal information in theirLDAP entry. The users authenticate to the web server to establishtheir identity, but the web server CGI cannot authenticate to theLDAP server as that user to make changes for them. Instead, theweb server authenticates itself to the LDAP server as a serviceidentity, say,> cn=WebUpdate,dc=example,dc=comand then it will SASL authorize to the DN of the user. Once soauthorized, the CGI makes changes to the LDAP entry of the user,and as far as the slapd server can tell for its ACLs, it is theuser themself on the other end of the connection. The user couldhave connected to the LDAP server directly and authenticated asthemself, but that would require the user to have more knowledgeof LDAP clients, knowledge which the web page provides in an easierformat.Proxy authorization can also be used to limit access to an accountthat has greater access to the database. Such an account, perhapseven the root DN specified in {{slapd.conf}}(5), can have a strictlist of people who can authorize to that DN. Changes to the LDAPdatabase could then be only allowed by that DN, and in order tobecome that DN, users must first authenticate as one of the personson the list. This allows for better auditing of who made changesto the LDAP database. If people were allowed to authenticatedirectly to the priviliged account, possibly through the {{EX:rootpw}}{{slapd.conf}}(5) directive or through a {{EX:userPassword}}attribute, then auditing becomes more difficult.Note that after a successful proxy authorization, the originalauthentication DN of the LDAP connection is overwritten by the newDN from the authorization request. If a service program is able toauthenticate itself as its own authentication DN and then authorizeto other DN's, and it is planning on switching to several differentidentities during one LDAP session, it will need to authenticateitself each time before authorizing to another DN (or use a differentproxy authorization mechanism). The slapd server does not keeprecord of the service program's ability to switch to other DN's.On authentication mechanisms like Kerberos this will not requiremultiple connections being made to the Kerberos server, since theuser's TGT and "ldap" session key are valid for multiple uses forthe several hours of the ticket lifetime.H3: SASL Authorization IdentitiesThe SASL authorization identity is sent to the LDAP server via the{{EX:-X}} switch for {{ldapsearch}}(1) and other tools, or in the{{EX:*authzid}} parameter to the {{lutil_sasl_defaults}}() call.The identity can be in one of two forms, either> u:<username>or> dn:<dn>In the first form, the <username> is from the same namespace asthe authentication identities above. It is the user's username asit is refered to by the underlying authentication mechanism.Authorization identities of this form are converted into a DN formatby the same function that the authentication process used, producingan {{authorization request DN}} of the form> uid=<username>,cn=<realm>,cn=<mechanism>,cn=authThat authorization request DN is then run through the same{{EX:authz-regexp}} process to convert it into a legitimate authorizationDN from the database. If it cannot be converted due to a failedsearch from an LDAP URL, the authorization request fails with"inappropriate access". Otherwise, the DN string is now a legitimateauthorization DN ready to undergo approval.If the authorization identity was provided in the second form, witha {{EX:"dn:"}} prefix, the string after the prefix is already inauthorization DN form, ready to undergo approval.H3: Proxy Authorization RulesOnce slapd has the authorization DN, the actual approval processbegins. There are two attributes that the LDAP administrator canput into LDAP entries to allow authorization:> authzTo> authzFromBoth can be multivalued. The {{EX:authzTo}} attribute is asource rule, and it is placed into the entry associated with theauthentication DN to tell what authorization DNs the authenticatedDN is allowed to assume. The second attribute is a destinationrule, and it is placed into the entry associated with the requestedauthorization DN to tell which authenticated DNs may assume it.The choice of which authorization policy attribute to use is up tothe administrator. Source rules are checked first in the person'sauthentication DN entry, and if none of the {{EX:authzTo}} rulesspecify the authorization is permitted, the {{EX:authzFrom}}rules in the authorization DN entry are then checked. If neithercase specifies that the request be honored, the request is denied.Since the default behaviour is to deny authorization requests, rulesonly specify that a request be allowed; there are no negative rulestelling what authorizations to deny.The value(s) in the two attributes are of the same form as theoutput of the replacement pattern of a {{EX:authz-regexp}} directive:either a DN or an LDAP URL. For example, if a {{EX:authzTo}}value is a DN, that DN is one the authenticated user can authorizeto. On the other hand, if the {{EX:authzTo}} value is an LDAPURL, the URL is used as an internal search of the LDAP database,and the authenticated user can become ANY DN returned by the search.If an LDAP entry looked like:> dn: cn=WebUpdate,dc=example,dc=com> authzTo: ldap:///dc=example,dc=com??sub?(objectclass=person)then any user who authenticated as {{EX:cn=WebUpdate,dc=example,dc=com}}could authorize to any other LDAP entry under the search base{{EX:dc=example,dc=com}} which has an objectClass of {{EX:Person}}.H4: Notes on Proxy Authorization RulesAn LDAP URL in a {{EX:authzTo}} or {{EX:authzFrom}} attributewill return a set of DNs. Each DN returned will be checked. Searcheswhich return a large set can cause the authorization process totake an uncomfortably long time. Also, searches should be performedon attributes that have been indexed by slapd.To help produce more sweeping rules for {{EX:authzFrom}} and{{EX:authzTo}}, the values of these attributes are allowed tobe DNs with regular expression characters in them. This means asource rule like> authzTo: uid=[^,]*,dc=example,dc=comwould allow that authenticated user to authorize to any DN thatmatches the regular expression pattern given. This regular expressioncomparison can be evaluated much faster than an LDAP search for{{EX:(uid=*)}}.Also note that the values in an authorization rule must be one ofthe two forms: an LDAP URL or a DN (with or without regular expressioncharacters). Anything that does not begin with "{{EX:ldap://}}" istaken as a DN. It is not permissable to enter another authorizationidentity of the form "{{EX:u:<username>}}" as an authorization rule.H4: Policy ConfigurationThe decision of which type of rules to use, {{EX:authzFrom}}or {{EX:authzTo}}, will depend on the site's situation. Forexample, if the set of people who may become a given identity caneasily be written as a search filter, then a single destinationrule could be written. If the set of people is not easily definedby a search filter, and the set of people is small, it may be betterto write a source rule in the entries of each of those people whoshould be allowed to perform the proxy authorization.By default, processing of proxy authorization rules is disabled.The {{EX:authz-policy}} directive must be set in the{{slapd.conf}}(5) file to enable authorization. This directive canbe set to {{EX:none}} for no rules (the default), {{EX:to}} forsource rules, {{EX:from}} for destination rules, or {{EX:both}} forboth source and destination rules.Destination rules are extremely powerful. If ordinary users haveaccess to write the {{EX:authzTo}} attribute in their ownentries, then they can write rules that would allow them to authorizeas anyone else. As such, when using destination rules, the{{EX:authzTo}} attribute should be protected with an ACL thatonly allows privileged users to set its values.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -