2 # Copyright 1999-2012 The OpenLDAP Foundation, All Rights Reserved.
3 # COPYING RESTRICTIONS APPLY, see COPYRIGHT.
9 As the directory gets populated with more and more data of varying sensitivity,
10 controlling the kinds of access granted to the directory becomes more and more
11 critical. For instance, the directory may contain data of a confidential nature
12 that you may need to protect by contract or by law. Or, if using the directory
13 to control access to other services, inappropriate access to the directory may
14 create avenues of attack to your sites security that result in devastating
15 damage to your assets.
17 Access to your directory can be configured via two methods, the first using
18 {{SECT:The slapd Configuration File}} and the second using the {{slapd-config}}(5)
19 format ({{SECT:Configuring slapd}}).
21 The default access control policy is allow read by all clients. Regardless of
22 what access control policy is defined, the {{rootdn}} is always allowed full
23 rights (i.e. auth, search, compare, read and write) on everything and anything.
25 As a consequence, it's useless (and results in a performance penalty) to explicitly
26 list the {{rootdn}} among the {{<by>}} clauses.
28 The following sections will describe Access Control Lists in greater depth and
29 follow with some examples and recommendations. See {{slapd.access}}(5) for
32 H2: Access Control via Static Configuration
34 Access to entries and attributes is controlled by the
35 access configuration file directive. The general form of an
38 > <access directive> ::= access to <what>
39 > [by <who> [<access>] [<control>] ]+
41 > [dn[.<basic-style>]=<regex> | dn.<scope-style>=<DN>]
42 > [filter=<ldapfilter>] [attrs=<attrlist>]
43 > <basic-style> ::= regex | exact
44 > <scope-style> ::= base | one | subtree | children
45 > <attrlist> ::= <attr> [val[.<basic-style>]=<regex>] | <attr> , <attrlist>
46 > <attr> ::= <attrname> | entry | children
47 > <who> ::= * | [anonymous | users | self
48 > | dn[.<basic-style>]=<regex> | dn.<scope-style>=<DN>]
50 > [group[/<objectclass>[/<attrname>][.<basic-style>]]=<regex>]
51 > [peername[.<basic-style>]=<regex>]
52 > [sockname[.<basic-style>]=<regex>]
53 > [domain[.<basic-style>]=<regex>]
54 > [sockurl[.<basic-style>]=<regex>]
57 > <access> ::= [self]{<level>|<priv>}
58 > <level> ::= none | disclose | auth | compare | search | read | write | manage
59 > <priv> ::= {=|+|-}{m|w|r|s|c|x|d|0}+
60 > <control> ::= [stop | continue | break]
62 where the <what> part selects the entries and/or attributes to which
63 the access applies, the {{EX:<who>}} part specifies which entities
64 are granted access, and the {{EX:<access>}} part specifies the
65 access granted. Multiple {{EX:<who> <access> <control>}} triplets
66 are supported, allowing many entities to be granted different access
67 to the same set of entries and attributes. Not all of these access
68 control options are described here; for more details see the
69 {{slapd.access}}(5) man page.
72 H3: What to control access to
74 The <what> part of an access specification determines the entries
75 and attributes to which the access control applies. Entries are
76 commonly selected in two ways: by DN and by filter. The following
77 qualifiers select entries by DN:
80 > to dn[.<basic-style>]=<regex>
81 > to dn.<scope-style>=<DN>
83 The first form is used to select all entries. The second form may
84 be used to select entries by matching a regular expression against
85 the target entry's {{normalized DN}}. (The second form is not
86 discussed further in this document.) The third form is used to
87 select entries which are within the requested scope of DN. The
88 <DN> is a string representation of the Distinguished Name, as
89 described in {{REF:RFC4514}}.
91 The scope can be either {{EX:base}}, {{EX:one}}, {{EX:subtree}},
92 or {{EX:children}}. Where {{EX:base}} matches only the entry with
93 provided DN, {{EX:one}} matches the entries whose parent is the
94 provided DN, {{EX:subtree}} matches all entries in the subtree whose
95 root is the provided DN, and {{EX:children}} matches all entries
96 under the DN (but not the entry named by the DN).
98 For example, if the directory contained entries named:
101 > 1: cn=Manager,o=suffix
102 > 2: ou=people,o=suffix
103 > 3: uid=kdz,ou=people,o=suffix
104 > 4: cn=addresses,uid=kdz,ou=people,o=suffix
105 > 5: uid=hyc,ou=people,o=suffix
108 . {{EX:dn.base="ou=people,o=suffix"}} match 2;
109 . {{EX:dn.one="ou=people,o=suffix"}} match 3, and 5;
110 . {{EX:dn.subtree="ou=people,o=suffix"}} match 2, 3, 4, and 5; and
111 . {{EX:dn.children="ou=people,o=suffix"}} match 3, 4, and 5.
114 Entries may also be selected using a filter:
116 > to filter=<ldap filter>
118 where <ldap filter> is a string representation of an LDAP
119 search filter, as described in {{REF:RFC4515}}. For example:
121 > to filter=(objectClass=person)
123 Note that entries may be selected by both DN and filter by
124 including both qualifiers in the <what> clause.
126 > to dn.one="ou=people,o=suffix" filter=(objectClass=person)
128 Attributes within an entry are selected by including a comma-separated
129 list of attribute names in the <what> selector:
131 > attrs=<attribute list>
133 A specific value of an attribute is selected by using a single
134 attribute name and also using a value selector:
136 > attrs=<attribute> val[.<style>]=<regex>
138 There are two special {{pseudo}} attributes {{EX:entry}} and
139 {{EX:children}}. To read (and hence return) a target entry, the
140 subject must have {{EX:read}} access to the target's {{entry}}
141 attribute. To perform a search, the subject must have
142 {{EX:search}} access to the search base's {{entry}} attribute.
143 To add or delete an entry, the subject must have
144 {{EX:write}} access to the entry's {{EX:entry}} attribute AND must
145 have {{EX:write}} access to the entry's parent's {{EX:children}}
146 attribute. To rename an entry, the subject must have {{EX:write}}
147 access to entry's {{EX:entry}} attribute AND have {{EX:write}}
148 access to both the old parent's and new parent's {{EX:children}}
149 attributes. The complete examples at the end of this section should
150 help clear things up.
152 Lastly, there is a special entry selector {{EX:"*"}} that is used to
153 select any entry. It is used when no other {{EX:<what>}}
154 selector has been provided. It's equivalent to "{{EX:dn=.*}}"
157 H3: Who to grant access to
159 The <who> part identifies the entity or entities being granted
160 access. Note that access is granted to "entities" not "entries."
161 The following table summarizes entity specifiers:
163 !block table; align=Center; coltags="EX,N"; \
164 title="Table 6.3: Access Entity Specifiers"
166 *|All, including anonymous and authenticated users
167 anonymous|Anonymous (non-authenticated) users
168 users|Authenticated users
169 self|User associated with target entry
170 dn[.<basic-style>]=<regex>|Users matching a regular expression
171 dn.<scope-style>=<DN>|Users within scope of a DN
174 The DN specifier behaves much like <what> clause DN specifiers.
176 Other control factors are also supported. For example, a {{EX:<who>}}
177 can be restricted by an entry listed in a DN-valued attribute in
178 the entry to which the access applies:
180 > dnattr=<dn-valued attribute name>
182 The dnattr specification is used to give access to an entry
183 whose DN is listed in an attribute of the entry (e.g., give
184 access to a group entry to whoever is listed as the owner of
187 Some factors may not be appropriate in all environments (or any).
188 For example, the domain factor relies on IP to domain name lookups.
189 As these can easily be spoofed, the domain factor should be avoided.
192 H3: The access to grant
194 The kind of <access> granted can be one of the following:
196 !block table; colaligns="LRL"; coltags="EX,EX,N"; align=Center; \
197 title="Table 6.4: Access Levels"
198 Level Privileges Description
200 disclose =d needed for information disclosure on error
201 auth =dx needed to authenticate (bind)
202 compare =cdx needed to compare
203 search =scdx needed to apply search filters
204 read =rscdx needed to read search results
205 write =wrscdx needed to modify/rename
206 manage =mwrscdx needed to manage
209 Each level implies all lower levels of access. So, for example,
210 granting someone {{EX:write}} access to an entry also grants them
211 {{EX:read}}, {{EX:search}}, {{EX:compare}}, {{EX:auth}} and
212 {{EX:disclose}} access. However, one may use the privileges specifier
213 to grant specific permissions.
216 H3: Access Control Evaluation
218 When evaluating whether some requester should be given access to
219 an entry and/or attribute, slapd compares the entry and/or attribute
220 to the {{EX:<what>}} selectors given in the configuration file.
221 For each entry, access controls provided in the database which holds
222 the entry (or the global access directives if not held in any database) apply
223 first, followed by the global access directives. However, when dealing with
224 an access list, because the global access list is effectively appended
225 to each per-database list, if the resulting list is non-empty then the
226 access list will end with an implicit {{EX:access to * by * none}} directive.
227 If there are no access directives applicable to a backend, then a default
231 priority, access directives are examined in the order in which they
232 appear in the config file. Slapd stops with the first {{EX:<what>}}
233 selector that matches the entry and/or attribute. The corresponding
234 access directive is the one slapd will use to evaluate access.
236 Next, slapd compares the entity requesting access to the {{EX:<who>}}
237 selectors within the access directive selected above in the order
238 in which they appear. It stops with the first {{EX:<who>}} selector
239 that matches the requester. This determines the access the entity
240 requesting access has to the entry and/or attribute.
242 Finally, slapd compares the access granted in the selected
243 {{EX:<access>}} clause to the access requested by the client. If
244 it allows greater or equal access, access is granted. Otherwise,
247 The order of evaluation of access directives makes their placement
248 in the configuration file important. If one access directive is
249 more specific than another in terms of the entries it selects, it
250 should appear first in the config file. Similarly, if one {{EX:<who>}}
251 selector is more specific than another it should come first in the
252 access directive. The access control examples given below should
253 help make this clear.
257 H3: Access Control Examples
259 The access control facility described above is quite powerful. This
260 section shows some examples of its use for descriptive purposes.
264 > access to * by * read
266 This access directive grants read access to everyone.
273 This directive allows the user to modify their entry, allows anonymous
274 to authentication against these entries, and allows all others to
275 read these entries. Note that only the first {{EX:by <who>}} clause
276 which matches applies. Hence, the anonymous users are granted
277 {{EX:auth}}, not {{EX:read}}. The last clause could just as well
278 have been "{{EX:by users read}}".
280 It is often desirable to restrict operations based upon the level
281 of protection in place. The following shows how security strength
282 factors (SSF) can be used.
285 > by ssf=128 self write
286 > by ssf=64 anonymous auth
287 > by ssf=64 users read
289 This directive allows users to modify their own entries if security
290 protections have of strength 128 or better have been established,
291 allows authentication access to anonymous users, and read access
292 when 64 or better security protections have been established. If
293 client has not establish sufficient security protections, the
294 implicit {{EX:by * none}} clause would be applied.
296 The following example shows the use of a style specifiers to select
297 the entries by DN in two access directives where ordering is
300 > access to dn.children="dc=example,dc=com"
302 > access to dn.children="dc=com"
305 Read access is granted to entries under the {{EX:dc=com}} subtree,
306 except for those entries under the {{EX:dc=example,dc=com}} subtree,
307 to which search access is granted. No access is granted to
308 {{EX:dc=com}} as neither access directive matches this DN. If the
309 order of these access directives was reversed, the trailing directive
310 would never be reached, since all entries under {{EX:dc=example,dc=com}}
311 are also under {{EX:dc=com}} entries.
313 Also note that if no {{EX:access to}} directive matches or no {{EX:by
314 <who>}} clause, {{B:access is denied}}. That is, every {{EX:access
315 to}} directive ends with an implicit {{EX:by * none}} clause. When dealing
316 with an access list, because the global access list is effectively appended
317 to each per-database list, if the resulting list is non-empty then the access
318 list will end with an implicit {{EX:access to * by * none}} directive. If
319 there are no access directives applicable to a backend, then a default read is
322 The next example again shows the importance of ordering, both of
323 the access directives and the {{EX:by <who>}} clauses. It also
324 shows the use of an attribute selector to grant access to a specific
325 attribute and various {{EX:<who>}} selectors.
327 > access to dn.subtree="dc=example,dc=com" attrs=homePhone
329 > by dn.children="dc=example,dc=com" search
330 > by peername.regex=IP:10\..+ read
331 > access to dn.subtree="dc=example,dc=com"
333 > by dn.children="dc=example,dc=com" search
336 This example applies to entries in the "{{EX:dc=example,dc=com}}"
337 subtree. To all attributes except {{EX:homePhone}}, an entry can
338 write to itself, entries under {{EX:example.com}} entries can search
339 by them, anybody else has no access (implicit {{EX:by * none}})
340 excepting for authentication/authorization (which is always done
341 anonymously). The {{EX:homePhone}} attribute is writable by the
342 entry, searchable by entries under {{EX:example.com}}, readable by
343 clients connecting from network 10, and otherwise not readable
344 (implicit {{EX:by * none}}). All other access is denied by the
345 implicit {{EX:access to * by * none}}.
347 Sometimes it is useful to permit a particular DN to add or
348 remove itself from an attribute. For example, if you would like to
349 create a group and allow people to add and remove only
350 their own DN from the member attribute, you could accomplish
351 it with an access directive like this:
353 > access to attrs=member,entry
354 > by dnattr=member selfwrite
356 The dnattr {{EX:<who>}} selector says that the access applies to
357 entries listed in the {{EX:member}} attribute. The {{EX:selfwrite}} access
358 selector says that such members can only add or delete their
359 own DN from the attribute, not other values. The addition of
360 the entry attribute is required because access to the entry is
361 required to access any of the entry's attributes.
364 For more details on how to use the {{EX:access}} directive,
365 consult the {{Advanced Access Control}} chapter.
369 H2: Access Control via Dynamic Configuration
371 Access to slapd entries and attributes is controlled by the
372 olcAccess attribute, whose values are a sequence of access directives.
373 The general form of the olcAccess configuration is:
375 > olcAccess: <access directive>
376 > <access directive> ::= to <what>
377 > [by <who> [<access>] [<control>] ]+
379 > [dn[.<basic-style>]=<regex> | dn.<scope-style>=<DN>]
380 > [filter=<ldapfilter>] [attrs=<attrlist>]
381 > <basic-style> ::= regex | exact
382 > <scope-style> ::= base | one | subtree | children
383 > <attrlist> ::= <attr> [val[.<basic-style>]=<regex>] | <attr> , <attrlist>
384 > <attr> ::= <attrname> | entry | children
385 > <who> ::= * | [anonymous | users | self
386 > | dn[.<basic-style>]=<regex> | dn.<scope-style>=<DN>]
387 > [dnattr=<attrname>]
388 > [group[/<objectclass>[/<attrname>][.<basic-style>]]=<regex>]
389 > [peername[.<basic-style>]=<regex>]
390 > [sockname[.<basic-style>]=<regex>]
391 > [domain[.<basic-style>]=<regex>]
392 > [sockurl[.<basic-style>]=<regex>]
395 > <access> ::= [self]{<level>|<priv>}
396 > <level> ::= none | disclose | auth | compare | search | read | write | manage
397 > <priv> ::= {=|+|-}{m|w|r|s|c|x|d|0}+
398 > <control> ::= [stop | continue | break]
400 where the <what> part selects the entries and/or attributes to which
401 the access applies, the {{EX:<who>}} part specifies which entities
402 are granted access, and the {{EX:<access>}} part specifies the
403 access granted. Multiple {{EX:<who> <access> <control>}} triplets
404 are supported, allowing many entities to be granted different access
405 to the same set of entries and attributes. Not all of these access
406 control options are described here; for more details see the
407 {{slapd.access}}(5) man page.
410 H3: What to control access to
412 The <what> part of an access specification determines the entries
413 and attributes to which the access control applies. Entries are
414 commonly selected in two ways: by DN and by filter. The following
415 qualifiers select entries by DN:
418 > to dn[.<basic-style>]=<regex>
419 > to dn.<scope-style>=<DN>
421 The first form is used to select all entries. The second form may
422 be used to select entries by matching a regular expression against
423 the target entry's {{normalized DN}}. (The second form is not
424 discussed further in this document.) The third form is used to
425 select entries which are within the requested scope of DN. The
426 <DN> is a string representation of the Distinguished Name, as
427 described in {{REF:RFC4514}}.
429 The scope can be either {{EX:base}}, {{EX:one}}, {{EX:subtree}},
430 or {{EX:children}}. Where {{EX:base}} matches only the entry with
431 provided DN, {{EX:one}} matches the entries whose parent is the
432 provided DN, {{EX:subtree}} matches all entries in the subtree whose
433 root is the provided DN, and {{EX:children}} matches all entries
434 under the DN (but not the entry named by the DN).
436 For example, if the directory contained entries named:
439 > 1: cn=Manager,o=suffix
440 > 2: ou=people,o=suffix
441 > 3: uid=kdz,ou=people,o=suffix
442 > 4: cn=addresses,uid=kdz,ou=people,o=suffix
443 > 5: uid=hyc,ou=people,o=suffix
446 . {{EX:dn.base="ou=people,o=suffix"}} match 2;
447 . {{EX:dn.one="ou=people,o=suffix"}} match 3, and 5;
448 . {{EX:dn.subtree="ou=people,o=suffix"}} match 2, 3, 4, and 5; and
449 . {{EX:dn.children="ou=people,o=suffix"}} match 3, 4, and 5.
452 Entries may also be selected using a filter:
454 > to filter=<ldap filter>
456 where <ldap filter> is a string representation of an LDAP
457 search filter, as described in {{REF:RFC4515}}. For example:
459 > to filter=(objectClass=person)
461 Note that entries may be selected by both DN and filter by
462 including both qualifiers in the <what> clause.
464 > to dn.one="ou=people,o=suffix" filter=(objectClass=person)
466 Attributes within an entry are selected by including a comma-separated
467 list of attribute names in the <what> selector:
469 > attrs=<attribute list>
471 A specific value of an attribute is selected by using a single
472 attribute name and also using a value selector:
474 > attrs=<attribute> val[.<style>]=<regex>
476 There are two special {{pseudo}} attributes {{EX:entry}} and
477 {{EX:children}}. To read (and hence return) a target entry, the
478 subject must have {{EX:read}} access to the target's {{entry}}
479 attribute. To perform a search, the subject must have
480 {{EX:search}} access to the search base's {{entry}} attribute.
481 To add or delete an entry, the subject must have
482 {{EX:write}} access to the entry's {{EX:entry}} attribute AND must
483 have {{EX:write}} access to the entry's parent's {{EX:children}}
484 attribute. To rename an entry, the subject must have {{EX:write}}
485 access to entry's {{EX:entry}} attribute AND have {{EX:write}}
486 access to both the old parent's and new parent's {{EX:children}}
487 attributes. The complete examples at the end of this section should
488 help clear things up.
490 Lastly, there is a special entry selector {{EX:"*"}} that is used to
491 select any entry. It is used when no other {{EX:<what>}}
492 selector has been provided. It's equivalent to "{{EX:dn=.*}}"
495 H3: Who to grant access to
497 The <who> part identifies the entity or entities being granted
498 access. Note that access is granted to "entities" not "entries."
499 The following table summarizes entity specifiers:
501 !block table; align=Center; coltags="EX,N"; \
502 title="Table 5.3: Access Entity Specifiers"
504 *|All, including anonymous and authenticated users
505 anonymous|Anonymous (non-authenticated) users
506 users|Authenticated users
507 self|User associated with target entry
508 dn[.<basic-style>]=<regex>|Users matching a regular expression
509 dn.<scope-style>=<DN>|Users within scope of a DN
512 The DN specifier behaves much like <what> clause DN specifiers.
514 Other control factors are also supported. For example, a {{EX:<who>}}
515 can be restricted by an entry listed in a DN-valued attribute in
516 the entry to which the access applies:
518 > dnattr=<dn-valued attribute name>
520 The dnattr specification is used to give access to an entry
521 whose DN is listed in an attribute of the entry (e.g., give
522 access to a group entry to whoever is listed as the owner of
525 Some factors may not be appropriate in all environments (or any).
526 For example, the domain factor relies on IP to domain name lookups.
527 As these can easily be spoofed, the domain factor should be avoided.
530 H3: The access to grant
532 The kind of <access> granted can be one of the following:
534 !block table; colaligns="LRL"; coltags="EX,EX,N"; align=Center; \
535 title="Table 5.4: Access Levels"
536 Level Privileges Description
538 disclose =d needed for information disclosure on error
539 auth =dx needed to authenticate (bind)
540 compare =cdx needed to compare
541 search =scdx needed to apply search filters
542 read =rscdx needed to read search results
543 write =wrscdx needed to modify/rename
544 manage =mwrscdx needed to manage
547 Each level implies all lower levels of access. So, for example,
548 granting someone {{EX:write}} access to an entry also grants them
549 {{EX:read}}, {{EX:search}}, {{EX:compare}}, {{EX:auth}} and
550 {{EX:disclose}} access. However, one may use the privileges specifier
551 to grant specific permissions.
554 H3: Access Control Evaluation
556 When evaluating whether some requester should be given access to
557 an entry and/or attribute, slapd compares the entry and/or attribute
558 to the {{EX:<what>}} selectors given in the configuration. For
559 each entry, access controls provided in the database which holds
560 the entry (or the global access directives if not held in any database) apply
561 first, followed by the global access directives (which are held in
562 the {{EX:frontend}} database definition). However, when dealing with
563 an access list, because the global access list is effectively appended
564 to each per-database list, if the resulting list is non-empty then the
565 access list will end with an implicit {{EX:access to * by * none}} directive.
566 If there are no access directives applicable to a backend, then a default
569 Within this priority,
570 access directives are examined in the order in which they appear
571 in the configuration attribute. Slapd stops with the first
572 {{EX:<what>}} selector that matches the entry and/or attribute. The
573 corresponding access directive is the one slapd will use to evaluate
576 Next, slapd compares the entity requesting access to the {{EX:<who>}}
577 selectors within the access directive selected above in the order
578 in which they appear. It stops with the first {{EX:<who>}} selector
579 that matches the requester. This determines the access the entity
580 requesting access has to the entry and/or attribute.
582 Finally, slapd compares the access granted in the selected
583 {{EX:<access>}} clause to the access requested by the client. If
584 it allows greater or equal access, access is granted. Otherwise,
587 The order of evaluation of access directives makes their placement
588 in the configuration file important. If one access directive is
589 more specific than another in terms of the entries it selects, it
590 should appear first in the configuration. Similarly, if one {{EX:<who>}}
591 selector is more specific than another it should come first in the
592 access directive. The access control examples given below should
593 help make this clear.
597 H3: Access Control Examples
599 The access control facility described above is quite powerful. This
600 section shows some examples of its use for descriptive purposes.
604 > olcAccess: to * by * read
606 This access directive grants read access to everyone.
613 This directive allows the user to modify their entry, allows anonymous
614 to authenticate against these entries, and allows all others to
615 read these entries. Note that only the first {{EX:by <who>}} clause
616 which matches applies. Hence, the anonymous users are granted
617 {{EX:auth}}, not {{EX:read}}. The last clause could just as well
618 have been "{{EX:by users read}}".
620 It is often desirable to restrict operations based upon the level
621 of protection in place. The following shows how security strength
622 factors (SSF) can be used.
625 > by ssf=128 self write
626 > by ssf=64 anonymous auth
627 > by ssf=64 users read
629 This directive allows users to modify their own entries if security
630 protections of strength 128 or better have been established,
631 allows authentication access to anonymous users, and read access
632 when strength 64 or better security protections have been established. If
633 the client has not establish sufficient security protections, the
634 implicit {{EX:by * none}} clause would be applied.
636 The following example shows the use of style specifiers to select
637 the entries by DN in two access directives where ordering is
640 > olcAccess: to dn.children="dc=example,dc=com"
642 > olcAccess: to dn.children="dc=com"
645 Read access is granted to entries under the {{EX:dc=com}} subtree,
646 except for those entries under the {{EX:dc=example,dc=com}} subtree,
647 to which search access is granted. No access is granted to
648 {{EX:dc=com}} as neither access directive matches this DN. If the
649 order of these access directives was reversed, the trailing directive
650 would never be reached, since all entries under {{EX:dc=example,dc=com}}
651 are also under {{EX:dc=com}} entries.
653 Also note that if no {{EX:olcAccess: to}} directive matches or no {{EX:by
654 <who>}} clause, {{B:access is denied}}. When dealing with an access list,
655 because the global access list is effectively appended to each per-database
656 list, if the resulting list is non-empty then the access list will end with
657 an implicit {{EX:access to * by * none}} directive. If there are no access
658 directives applicable to a backend, then a default read is used.
660 The next example again shows the importance of ordering, both of
661 the access directives and the {{EX:by <who>}} clauses. It also
662 shows the use of an attribute selector to grant access to a specific
663 attribute and various {{EX:<who>}} selectors.
665 > olcAccess: to dn.subtree="dc=example,dc=com" attrs=homePhone
667 > by dn.children=dc=example,dc=com" search
668 > by peername.regex=IP:10\..+ read
669 > olcAccess: to dn.subtree="dc=example,dc=com"
671 > by dn.children="dc=example,dc=com" search
674 This example applies to entries in the "{{EX:dc=example,dc=com}}"
675 subtree. To all attributes except {{EX:homePhone}}, an entry can
676 write to itself, entries under {{EX:example.com}} entries can search
677 by them, anybody else has no access (implicit {{EX:by * none}})
678 excepting for authentication/authorization (which is always done
679 anonymously). The {{EX:homePhone}} attribute is writable by the
680 entry, searchable by entries under {{EX:example.com}}, readable by
681 clients connecting from network 10, and otherwise not readable
682 (implicit {{EX:by * none}}). All other access is denied by the
683 implicit {{EX:access to * by * none}}.
685 Sometimes it is useful to permit a particular DN to add or
686 remove itself from an attribute. For example, if you would like to
687 create a group and allow people to add and remove only
688 their own DN from the member attribute, you could accomplish
689 it with an access directive like this:
691 > olcAccess: to attrs=member,entry
692 > by dnattr=member selfwrite
694 The dnattr {{EX:<who>}} selector says that the access applies to
695 entries listed in the {{EX:member}} attribute. The {{EX:selfwrite}} access
696 selector says that such members can only add or delete their
697 own DN from the attribute, not other values. The addition of
698 the entry attribute is required because access to the entry is
699 required to access any of the entry's attributes.
703 H3: Access Control Ordering
705 Since the ordering of {{EX:olcAccess}} directives is essential to their
706 proper evaluation, but LDAP attributes normally do not preserve the
707 ordering of their values, OpenLDAP uses a custom schema extension to
708 maintain a fixed ordering of these values. This ordering is maintained
709 by prepending a {{EX:"{X}"}} numeric index to each value, similarly to
710 the approach used for ordering the configuration entries. These index
711 tags are maintained automatically by slapd and do not need to be specified
712 when originally defining the values. For example, when you create the
715 > olcAccess: to attrs=member,entry
716 > by dnattr=member selfwrite
717 > olcAccess: to dn.children="dc=example,dc=com"
719 > olcAccess: to dn.children="dc=com"
722 when you read them back using slapcat or ldapsearch they will contain
724 > olcAccess: {0}to attrs=member,entry
725 > by dnattr=member selfwrite
726 > olcAccess: {1}to dn.children="dc=example,dc=com"
728 > olcAccess: {2}to dn.children="dc=com"
731 The numeric index may be used to specify a particular value to change
732 when using ldapmodify to edit the access rules. This index can be used
733 instead of (or in addition to) the actual access value. Using this
734 numeric index is very helpful when multiple access rules are being managed.
736 For example, if we needed to change the second rule above to grant
737 write access instead of search, we could try this LDIF:
741 > olcAccess: to dn.children="dc=example,dc=com" by * search
744 > olcAccess: to dn.children="dc=example,dc=com" by * write
747 But this example {{B:will not}} guarantee that the existing values remain in
748 their original order, so it will most likely yield a broken security
749 configuration. Instead, the numeric index should be used:
756 > olcAccess: {1}to dn.children="dc=example,dc=com" by * write
759 This example deletes whatever rule is in value #1 of the {{EX:olcAccess}}
760 attribute (regardless of its value) and adds a new value that is
761 explicitly inserted as value #1. The result will be
763 > olcAccess: {0}to attrs=member,entry
764 > by dnattr=member selfwrite
765 > olcAccess: {1}to dn.children="dc=example,dc=com"
767 > olcAccess: {2}to dn.children="dc=com"
770 which is exactly what was intended.
773 For more details on how to use the {{EX:access}} directive,
774 consult the {{Advanced Access Control}} chapter.
778 H2: Access Control Common Examples
782 Generally one should start with some basic ACLs such as:
784 > access to attr=userPassword
795 The first ACL allows users to update (but not read) their passwords, anonymous
796 users to authenticate against this attribute, and (implicitly) denying all
799 The second ACL allows users full access to their entry, authenticated users read
800 access to anything, and (implicitly) denying all access to others (in this case,
804 H3: Matching Anonymous and Authenticated users
806 An anonymous user has a empty DN. While the {{dn.exact=""}} or {{dn.regex="^$"}}
807 could be used, {{slapd}}(8)) offers an anonymous shorthand which should be
814 denies all access to anonymous users while granting others read.
816 Authenticated users have a subject DN. While {{dn.regex=".+"}} will match any
817 authenticated user, OpenLDAP provides the users short hand which should be used
824 This ACL grants read permissions to authenticated users while denying others
825 (i.e.: anonymous users).
828 H3: Controlling rootdn access
830 You could specify the {{rootdn}} in {{slapd.conf}}(5) or {{slapd.d}} without
831 specifying a {{rootpw}}. Then you have to add an actual directory entry with
834 > dn: cn=Manager,o=MyOrganization
837 > objectClass: person
839 > userPassword: {SSHA}someSSHAdata
841 Then binding as the {{rootdn}} will require a regular bind to that DN, which
842 in turn requires auth access to that entry's DN and {{userPassword}}, and this
843 can be restricted via ACLs. E.g.:
845 > access to dn.base="cn=Manager,o=MyOrganization"
846 > by peername.regex=127\.0\.0\.1 auth
847 > by peername.regex=192\.168\.0\..* auth
851 The ACLs above will only allow binding using rootdn from localhost and
855 H3: Managing access with Groups
857 There are a few ways to do this. One approach is illustrated here. Consider the
858 following DIT layout:
860 > +-dc=example,dc=com
861 > +---cn=administrators,dc=example,dc=com
862 > +---cn=fred blogs,dc=example,dc=com
864 and the following group object (in LDIF format):
866 > dn: cn=administrators,dc=example,dc=com
867 > cn: administrators of this region
868 > objectclass: groupOfNames (important for the group acl feature)
869 > member: cn=fred blogs,dc=example,dc=com
870 > member: cn=somebody else,dc=example,dc=com
872 One can then grant access to the members of this this group by adding appropriate
873 {{by group}} clause to an access directive in {{slapd.conf}}(5). For instance,
875 > access to dn.children="dc=example,dc=com"
877 > by group.exact="cn=Administrators,dc=example,dc=com" write
880 Like by {{dn}} clauses, one can also use {{expand}} to expand the group name
881 based upon the regular expression matching of the target, that is, the to {{dn.regex}}).
884 > access to dn.regex="(.+,)?ou=People,(dc=[^,]+,dc=[^,]+)$"
885 > attrs=children,entry,uid
886 > by group.expand="cn=Managers,$2" write
891 The above illustration assumed that the group members are to be found in the
892 {{member}} attribute type of the {{groupOfNames}} object class. If you need to
893 use a different group object and/or a different attribute type then use the
894 following {{slapd.conf}}(5) (abbreviated) syntax:
897 > by group/<objectclass>/<attributename>=<DN> <access>
902 > by group/organizationalRole/roleOccupant="cn=Administrator,dc=example,dc=com" write
904 In this case, we have an ObjectClass {{organizationalRole}} which contains the
905 administrator DN's in the {{roleOccupant}} attribute. For instance:
907 > dn: cn=Administrator,dc=example,dc=com
909 > objectclass: organizationalRole
910 > roleOccupant: cn=Jane Doe,dc=example,dc=com
912 Note: the specified member attribute type MUST be of DN or {{NameAndOptionalUID}} syntax,
913 and the specified object class SHOULD allow the attribute type.
915 Dynamic Groups are also supported in Access Control. Please see {{slapo-dynlist}}(5)
916 and the {{SECT:Dynamic Lists}} overlay section.
919 H3: Granting access to a subset of attributes
921 You can grant access to a set of attributes by specifying a list of attribute names
922 in the ACL {{to}} clause. To be useful, you also need to grant access to the
923 {{entry}} itself. Also note how {{children}} controls the ability to add, delete,
926 > # mail: self may write, authenticated users may read
927 > access to attrs=mail
932 > # cn, sn: self my write, all may read
933 > access to attrs=cn,sn
937 > # immediate children: only self can add/delete entries under this entry
938 > access to attrs=children
941 > # entry itself: self may write, all may read
942 > access to attrs=entry
946 > # other attributes: self may write, others have no access
951 ObjectClass names may also be specified in this list, which will affect
952 all the attributes that are required and/or allowed by that {{objectClass}}.
953 Actually, names in {{attrlist}} that are prefixed by {{@}} are directly treated
954 as objectClass names. A name prefixed by {{!}} is also treated as an objectClass,
955 but in this case the access rule affects the attributes that are not required
956 nor allowed by that {{objectClass}}.
959 H3: Allowing a user write to all entries below theirs
961 For a setup where a user can write to its own record and to all of its children:
963 > access to dn.regex="(.+,)?(uid=[^,]+,o=Company)$"
964 > by dn.exact,expand="$2" write
967 (Add more examples for above)
970 H3: Allowing entry creation
972 Let's say, you have it like this:
976 > associatedDomain=<somedomain>
979 > uid=<someotheruserid>
985 and, for another domain <someotherdomain>:
989 > associatedDomain=<someotherdomain>
992 > uid=<someotheruserid>
994 > uid=<someotheruserid>
998 then, if you wanted user {{uid=<someuserid>}} to {{B:ONLY}} create an entry
999 for its own thing, you could write an ACL like this:
1001 > # this rule lets users of "associatedDomain=<matcheddomain>"
1002 > # write under "ou=addressbook,associatedDomain=<matcheddomain>,ou=domains,o=<basedn>",
1003 > # i.e. a user can write ANY entry below its domain's address book;
1004 > # this permission is necessary, but not sufficient, the next
1005 > # will restrict this permission further
1008 > access to dn.regex="^ou=addressbook,associatedDomain=([^,]+),ou=domains,o=<basedn>$" attrs=children
1009 > by dn.regex="^uid=([^,]+),ou=users,associatedDomain=$1,ou=domains,o=<basedn>$$" write
1013 > # Note that above the "by" clause needs a "regex" style to make sure
1014 > # it expands to a DN that starts with a "uid=<someuserid>" pattern
1015 > # while substituting the associatedDomain submatch from the "what" clause.
1018 > # This rule lets a user with "uid=<matcheduid>" of "<associatedDomain=matcheddomain>"
1019 > # write (i.e. add, modify, delete) the entry whose DN is exactly
1020 > # "uid=<matcheduid>,ou=addressbook,associatedDomain=<matcheddomain>,ou=domains,o=<basedn>"
1021 > # and ANY entry as subtree of it
1024 > access to dn.regex="^(.+,)?uid=([^,]+),ou=addressbook,associatedDomain=([^,]+),ou=domains,o=<basedn>$"
1025 > by dn.exact,expand="uid=$2,ou=users,associatedDomain=$3,ou=domains,o=<basedn>" write
1029 > # Note that above the "by" clause uses the "exact" style with the "expand"
1030 > # modifier because now the whole pattern can be rebuilt by means of the
1031 > # submatches from the "what" clause, so a "regex" compilation and evaluation
1032 > # is no longer required.
1035 H3: Tips for using regular expressions in Access Control
1037 Always use {{dn.regex=<pattern>}} when you intend to use regular expression
1038 matching. {{dn=<pattern>}} alone defaults to {{dn.exact<pattern>}}.
1040 Use {{(.+)}} instead of {{(.*)}} when you want at least one char to be matched.
1041 {{(.*)}} matches the empty string as well.
1043 Don't use regular expressions for matches that can be done otherwise in a safer
1044 and cheaper manner. Examples:
1046 > dn.regex=".*dc=example,dc=com"
1048 is unsafe and expensive:
1050 * unsafe because any string containing {{dc=example,dc=com }}will match,
1051 not only those that end with the desired pattern; use {{.*dc=example,dc=com$}} instead.
1052 * unsafe also because it would allow any {{attributeType}} ending with {{dc}}
1053 as naming attribute for the first RDN in the string, e.g. a custom attributeType
1054 {{mydc}} would match as well. If you really need a regular expression that allows
1055 just {{dc=example,dc=com}} or any of its subtrees, use {{^(.+,)?dc=example,dc=com$}},
1056 which means: anything to the left of dc=..., if any (the question mark after the
1057 pattern within brackets), must end with a comma;
1058 * expensive because if you don't need submatches, you could use scoping styles, e.g.
1060 > dn.subtree="dc=example,dc=com"
1062 to include {{dc=example,dc=com}} in the matching patterns,
1064 > dn.children="dc=example,dc=com"
1066 to exclude {{dc=example,dc=com}} from the matching patterns, or
1068 > dn.onelevel="dc=example,dc=com"
1070 to allow exactly one sublevel matches only.
1072 Always use {{^}} and {{$}} in regexes, whenever appropriate, because
1073 {{ou=(.+),ou=(.+),ou=addressbooks,o=basedn}} will match
1074 {{something=bla,ou=xxx,ou=yyy,ou=addressbooks,o=basedn,ou=addressbooks,o=basedn,dc=some,dc=org}}
1076 Always use {{([^,]+)}} to indicate exactly one RDN, because {{(.+)}} can
1077 include any number of RDNs; e.g. {{ou=(.+),dc=example,dc=com}} will match
1078 {{ou=My,o=Org,dc=example,dc=com}}, which might not be what you want.
1080 Never add the rootdn to the by clauses. ACLs are not even processed for operations
1081 performed with rootdn identity (otherwise there would be no reason to define a
1084 Use shorthands. The user directive matches authenticated users and the anonymous
1085 directive matches anonymous users.
1087 Don't use the {{dn.regex}} form for <by> clauses if all you need is scoping
1088 and/or substring replacement; use scoping styles (e.g. {{exact}}, {{onelevel}},
1089 {{children}} or {{subtree}}) and the style modifier expand to cause substring expansion.
1093 > access to dn.regex=".+,dc=([^,]+),dc=([^,]+)$"
1094 > by dn.regex="^[^,],ou=Admin,dc=$1,dc=$2$$" write
1096 although correct, can be safely and efficiently replaced by
1098 > access to dn.regex=".+,(dc=[^,]+,dc=[^,]+)$"
1099 > by dn.onelevel,expand="ou=Admin,$1" write
1101 where the regex in the {{<what>}} clause is more compact, and the one in the {{<by>}}
1102 clause is replaced by a much more efficient scoping style of onelevel with substring expansion.
1105 H3: Granting and Denying access based on security strength factors (ssf)
1107 You can restrict access based on the security strength factor (SSF)
1109 > access to dn="cn=example,cn=edu"
1112 0 (zero) implies no protection,
1113 1 implies integrity protection only,
1114 56 DES or other weak ciphers,
1115 112 triple DES and other strong ciphers,
1116 128 RC4, Blowfish and other modern strong ciphers.
1118 Other possibilities:
1126 See {{slapd.conf}}(5) for information on {{ssf}}.
1129 H3: When things aren't working as expected
1131 Consider this example:
1142 You may think this will allow any user to login, to read everything and change
1143 his own data if he is logged in. But in this example only the login works and
1144 an ldapsearch returns no data. The Problem is that SLAPD goes through its access
1145 config line by line and stops as soon as it finds a match in the part of the
1146 access rule.(here: {{to *}})
1148 To get what we wanted the file has to read:
1155 The general rule is: "special access rules first, generic access rules last"
1157 See also {{slapd.access}}(5), loglevel 128 and {{slapacl}}(8) for debugging
1161 H2: Sets - Granting rights based on relationships
1163 Sets are best illustrated via examples. The following sections will present
1164 a few set ACL examples in order to facilitate their understanding.
1166 (Sets in Access Controls FAQ Entry: {{URL:http://www.openldap.org/faq/data/cache/1133.html}})
1168 Note: Sets are considered experimental.
1171 H3: Groups of Groups
1173 The OpenLDAP ACL for groups doesn't expand groups within groups, which are
1174 groups that have another group as a member. For example:
1176 > dn: cn=sudoadm,ou=group,dc=example,dc=com
1178 > objectClass: groupOfNames
1179 > member: uid=john,ou=people,dc=example,dc=com
1180 > member: cn=accountadm,ou=group,dc=example,dc=com
1182 > dn: cn=accountadm,ou=group,dc=example,dc=com
1184 > objectClass: groupOfNames
1185 > member: uid=mary,ou=people,dc=example,dc=com
1187 If we use standard group ACLs with the above entries and allow members of the
1188 {{F:sudoadm}} group to write somewhere, {{F:mary}} won't be included:
1190 > access to dn.subtree="ou=sudoers,dc=example,dc=com"
1191 > by group.exact="cn=sudoadm,ou=group,dc=example,dc=com" write
1194 With sets we can make the ACL be recursive and consider group within groups. So
1195 for each member that is a group, it is further expanded:
1197 > access to dn.subtree="ou=sudoers,dc=example,dc=com"
1198 > by set="[cn=sudoadm,ou=group,dc=example,dc=com]/member* & user" write
1201 This set ACL means: take the {{F:cn=sudoadm}} DN, check its {{F:member}}
1202 attribute(s) (where the "{{F:*}}" means recursively) and intersect the result
1203 with the authenticated user's DN. If the result is non-empty, the ACL is
1204 considered a match and write access is granted.
1206 The following drawing explains how this set is built:
1207 !import "set-recursivegroup.png"; align="center"; title="Building a recursive group"
1208 FT[align="Center"] Figure X.Y: Populating a recursive group set
1210 First we get the {{F:uid=john}} DN. This entry doesn't have a {{F:member}}
1211 attribute, so the expansion stops here. Now we get to {{F:cn=accountadm}}.
1212 This one does have a {{F:member}} attribute, which is {{F:uid=mary}}. The
1213 {{F:uid=mary}} entry, however, doesn't have member, so we stop here again. The
1216 > {"uid=john,ou=people,dc=example,dc=com","uid=mary,ou=people,dc=example,dc=com"} & user
1218 If the authenticated user's DN is any one of those two, write access is
1219 granted. So this set will include {{F:mary}} in the {{F:sudoadm}} group and she
1220 will be allowed the write access.
1222 H3: Group ACLs without DN syntax
1224 The traditional group ACLs, and even the previous example about recursive groups, require
1225 that the members are specified as DNs instead of just usernames.
1227 With sets, however, it's also possible to use simple names in group ACLs, as this example will
1230 Let's say we want to allow members of the {{F:sudoadm}} group to write to the
1231 {{F:ou=suders}} branch of our tree. But our group definition now is using {{F:memberUid}} for
1234 > dn: cn=sudoadm,ou=group,dc=example,dc=com
1236 > objectClass: posixGroup
1240 With this type of group, we can't use group ACLs. But with a set ACL we can
1241 grant the desired access:
1243 > access to dn.subtree="ou=sudoers,dc=example,dc=com"
1244 > by set="[cn=sudoadm,ou=group,dc=example,dc=com]/memberUid & user/uid" write
1247 We use a simple intersection where we compare the {{F:uid}} attribute
1248 of the connecting (and authenticated) user with the {{F:memberUid}} attributes
1249 of the group. If they match, the intersection is non-empty and the ACL will
1252 This drawing illustrates this set when the connecting user is authenticated as
1253 {{F:uid=john,ou=people,dc=example,dc=com}}:
1254 !import "set-memberUid.png"; align="center"; title="Sets with memberUid"
1255 FT[align="Center"] Figure X.Y: Sets with {{F:memberUid}}
1257 In this case, it's a match. If it were {{F:mary}} authenticating, however, she
1258 would be denied write access to {{F:ou=sudoers}} because her {{F:uid}}
1259 attribute is not listed in the group's {{F:memberUid}}.
1261 H3: Following references
1263 We will now show a quite powerful example of what can be done with sets. This
1264 example tends to make OpenLDAP administrators smile after they have understood
1265 it and its implications.
1267 Let's start with an user entry:
1269 > dn: uid=john,ou=people,dc=example,dc=com
1271 > objectClass: inetOrgPerson
1275 > manager: uid=mary,ou=people,dc=example,dc=com
1277 Writing an ACL to allow the manager to update some attributes is quite simple
1280 > access to dn.exact="uid=john,ou=people,dc=example,dc=com"
1281 > attrs=carLicense,homePhone,mobile,pager,telephoneNumber
1283 > by set="this/manager & user" write
1286 In that set, {{F:this}} expands to the entry being accessed, so that
1287 {{F:this/manager}} expands to {{F:uid=mary,ou=people,dc=example,dc=com}} when
1288 john's entry is accessed. If the manager herself is accessing John's entry,
1289 the ACL will match and write access to those attributes will be granted.
1291 So far, this same behavior can be obtained with the {{F:dnattr}} keyword. With
1292 sets, however, we can further enhance this ACL. Let's say we want to allow the
1293 secretary of the manager to also update these attributes. This is how we do it:
1295 > access to dn.exact="uid=john,ou=people,dc=example,dc=com"
1296 > attrs=carLicense,homePhone,mobile,pager,telephoneNumber
1298 > by set="this/manager & user" write
1299 > by set="this/manager/secretary & user" write
1302 Now we need a picture to help explain what is happening here (entries shortened
1305 !import "set-following-references.png"; align="center"; title="Sets jumping through entries"
1306 FT[align="Center"] Figure X.Y: Sets jumping through entries
1308 In this example, Jane is the secretary of Mary, which is the manager of John.
1309 This whole relationship is defined with the {{F:manager}} and {{F:secretary}}
1310 attributes, which are both of the distinguishedName syntax (i.e., full DNs).
1311 So, when the {{F:uid=john}} entry is being accessed, the
1312 {{F:this/manager/secretary}} set becomes
1313 {{F:{"uid=jane,ou=people,dc=example,dc=com"}}} (follow the references in the
1316 > this = [uid=john,ou=people,dc=example,dc=com]
1318 > [uid=john,ou=people,dc=example,dc=com]/manager = uid=mary,ou=people,dc=example,dc=com
1319 > this/manager/secretary = \
1320 > [uid=mary,ou=people,dc=example,dc=com]/secretary = uid=jane,ou=people,dc=example,dc=com
1322 The end result is that when Jane accesses John's entry, she will be granted
1323 write access to the specified attributes. Better yet, this will happen to any
1324 entry she accesses which has Mary as the manager.
1326 This is all cool and nice, but perhaps gives too much power to secretaries. Maybe we need to further
1327 restrict it. For example, let's only allow executive secretaries to have this power:
1329 > access to dn.exact="uid=john,ou=people,dc=example,dc=com"
1330 > attrs=carLicense,homePhone,mobile,pager,telephoneNumber
1332 > by set="this/manager & user" write
1333 > by set="this/manager/secretary &
1334 > [cn=executive,ou=group,dc=example,dc=com]/member* &
1338 It's almost the same ACL as before, but we now also require that the connecting user be a member
1339 of the (possibly nested) {{F:cn=executive}} group.