]> git.sur5r.net Git - openldap/blob - doc/man/man5/slapd-meta.5
allow proxies to filter out search references (ITS#5593)
[openldap] / doc / man / man5 / slapd-meta.5
1 .TH SLAPD-META 5 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" Copyright 1998-2008 The OpenLDAP Foundation, All Rights Reserved.
3 .\" Copying restrictions apply.  See the COPYRIGHT file.
4 .\" Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
5 .\" $OpenLDAP$
6 .\"
7 .\" Portions of this document should probably be moved to slapd-ldap(5)
8 .\" and maybe manual pages for librewrite.
9 .\"
10 .SH NAME
11 slapd-meta \- metadirectory backend to slapd
12 .SH SYNOPSIS
13 ETCDIR/slapd.conf
14 .SH DESCRIPTION
15 The
16 .B meta
17 backend to
18 .BR slapd (8)
19 performs basic LDAP proxying with respect to a set of remote LDAP
20 servers, called "targets".
21 The information contained in these servers can be presented as
22 belonging to a single Directory Information Tree (DIT).
23 .LP
24 A basic knowledge of the functionality of the
25 .BR slapd\-ldap (5)
26 backend is recommended.
27 This backend has been designed as an enhancement of the ldap backend.
28 The two backends share many features (actually they also share
29 portions of code).
30 While the
31 .B ldap
32 backend is intended to proxy operations directed to a single server, the
33 .B meta
34 backend is mainly intended for proxying of multiple servers and possibly
35 naming context masquerading.
36 These features, although useful in many scenarios, may result in
37 excessive overhead for some applications, so its use should be
38 carefully considered.
39 In the examples section, some typical scenarios will be discussed.
40
41 .LP
42 Note: When looping back to the same instance of \fBslapd\fP(8), 
43 each connection requires a new thread; as a consequence, \fBslapd\fP(8)
44 must be compiled with thread support, and the \fBthreads\fP parameter 
45 may need some tuning; in those cases, unless the multiple target feature
46 is required, one may consider using \fBslapd-relay\fP(5) instead, 
47 which performs the relayed operation internally and thus reuses 
48 the same connection.
49
50 .SH EXAMPLES
51 There are examples in various places in this document, as well as in the
52 slapd/back-meta/data/ directory in the OpenLDAP source tree.
53 .SH CONFIGURATION
54 These
55 .B slapd.conf
56 options apply to the META backend database.
57 That is, they must follow a "database meta" line and come before any
58 subsequent "backend" or "database" lines.
59 Other database options are described in the
60 .BR slapd.conf (5)
61 manual page.
62 .LP
63 Note: In early versions of back-ldap and back-meta it was recommended to always set
64 .LP
65 .RS
66 .nf
67 lastmod  off
68 .fi
69 .RE
70 .LP
71 for 
72 .B ldap
73 and
74 .B meta
75 databases.
76 This was required because operational attributes related to entry creation 
77 and modification should not be proxied, as they could be mistakenly written
78 to the target server(s), generating an error.
79 The current implementation automatically sets lastmod to \fBoff\fP, 
80 so its use is redundant and should be omitted.
81
82 .SH SPECIAL CONFIGURATION DIRECTIVES
83 Target configuration starts with the "uri" directive.
84 All the configuration directives that are not specific to targets
85 should be defined first for clarity, including those that are common
86 to all backends.
87 They are:
88
89 .TP
90 .B conn-ttl <time>
91 This directive causes a cached connection to be dropped an recreated
92 after a given ttl, regardless of being idle or not.
93
94 .TP
95 .B default-target none
96 This directive forces the backend to reject all those operations
97 that must resolve to a single target in case none or multiple
98 targets are selected.
99 They include: add, delete, modify, modrdn; compare is not included, as
100 well as bind since, as they don't alter entries, in case of multiple
101 matches an attempt is made to perform the operation on any candidate
102 target, with the constraint that at most one must succeed.
103 This directive can also be used when processing targets to mark a
104 specific target as default.
105
106 .TP
107 .B dncache-ttl {DISABLED|forever|<ttl>}
108 This directive sets the time-to-live of the DN cache.
109 This caches the target that holds a given DN to speed up target
110 selection in case multiple targets would result from an uncached
111 search; forever means cache never expires; disabled means no DN
112 caching; otherwise a valid ( > 0 ) ttl is required, in the format
113 illustrated for the 
114 .B idle-timeout
115 directive.
116
117 .TP
118 .B onerr {CONTINUE|report|stop}
119 This directive allows to select the behavior in case an error is returned
120 by one target during a search.
121 The default, \fBcontinue\fP, consists in continuing the operation, 
122 trying to return as much data as possible.
123 If the value is set to \fBstop\fP, the search is terminated as soon 
124 as an error is returned by one target, and the error is immediately 
125 propagated to the client.
126 If the value is set to \fBreport\fP, the search is continuated to the end
127 but, in case at least one target returned an error code, the first
128 non-success error code is returned.
129
130 .TP
131 .B norefs <NO|yes>
132 If
133 .BR yes ,
134 do not return search reference responses.
135 By default, they are returned unless request is LDAPv2.
136 If set before any target specification, it affects all targets, unless
137 overridden by any per-target directive.
138
139 .TP
140 .B protocol\-version {0,2,3}
141 This directive indicates what protocol version must be used to contact
142 the remote server.
143 If set to 0 (the default), the proxy uses the same protocol version 
144 used by the client, otherwise the requested protocol is used.
145 The proxy returns \fIunwillingToPerform\fP if an operation that is 
146 incompatible with the requested protocol is attempted.
147 If set before any target specification, it affects all targets, unless
148 overridden by any per-target directive.
149
150 .TP
151 .B pseudoroot-bind-defer {YES|no}
152 This directive, when set to 
153 .BR yes ,
154 causes the authentication to the remote servers with the pseudo-root
155 identity to be deferred until actually needed by subsequent operations.
156 Otherwise, all binds as the rootdn are propagated to the targets.
157
158 .TP
159 .B quarantine <interval>,<num>[;<interval>,<num>[...]]
160 Turns on quarantine of URIs that returned
161 .IR LDAP_UNAVAILABLE ,
162 so that an attempt to reconnect only occurs at given intervals instead
163 of any time a client requests an operation.
164 The pattern is: retry only after at least
165 .I interval
166 seconds elapsed since last attempt, for exactly
167 .I num
168 times; then use the next pattern.
169 If
170 .I num
171 for the last pattern is "\fB+\fP", it retries forever; otherwise, 
172 no more retries occur.
173 This directive must appear before any target specification;
174 it affects all targets with the same pattern.
175
176 .TP
177 .B rebind-as-user {NO|yes}
178 If this option is given, the client's bind credentials are remembered
179 for rebinds, when trying to re-establish a broken connection,
180 or when chasing a referral, if 
181 .B chase-referrals
182 is set to
183 .IR yes .
184
185 .TP
186 .B session\-tracking\-request {NO|yes}
187 Adds session tracking control for all requests.
188 The client's IP and hostname, and the identity associated to each request,
189 if known, are sent to the remote server for informational purposes.
190 This directive is incompatible with setting \fIprotocol\-version\fP to 2.
191 If set before any target specification, it affects all targets, unless
192 overridden by any per-target directive.
193
194 .TP
195 .B single\-conn {NO|yes}
196 Discards current cached connection when the client rebinds.
197
198 .TP
199 .B use-temporary-conn {NO|yes}
200 when set to 
201 .BR yes ,
202 create a temporary connection whenever competing with other threads
203 for a shared one; otherwise, wait until the shared connection is available.
204
205 .SH TARGET SPECIFICATION
206 Target specification starts with a "uri" directive:
207
208 .TP
209 .B uri <protocol>://[<host>]/<naming context> [...]
210 The <protocol> part can be anything
211 .BR ldap_initialize (3)
212 accepts ({ldap|ldaps|ldapi} and variants); the <host> may be
213 omitted, defaulting to whatever is set in
214 .BR ldap.conf (5).
215 The <naming context> part is \fImandatory\fP for the first URI,
216 but it \fImust be omitted\fP for subsequent ones, if any.
217 The naming context part must be within the naming context defined for the backend,
218 e.g.:
219 .LP
220 .RS
221 .nf
222 suffix "\fBdc=foo,dc=com\fP"
223 uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
224 .fi
225
226 .RE
227 .RS
228 The <naming context> part doesn't need to be unique across the targets;
229 it may also match one of the values of the "suffix" directive.
230 Multiple URIs may be defined in a single URI statement.
231 The additional URIs must be separate arguments and must not have any
232 <naming context> part.  This causes the underlying library
233 to contact the first server of the list that responds.
234 For example, if \fIl1.foo.com\fP and \fIl2.foo.com\fP are shadows
235 of the same server, the directive
236 .LP
237 .nf
238 suffix "\fBdc=foo,dc=com\fP"
239 uri    "ldap://l1.foo.com/\fBdc=foo,dc=com\fP" "ldap://l2.foo.com/"
240 .fi
241
242 .RE
243 .RS
244 causes \fIl2.foo.com\fP to be contacted whenever \fIl1.foo.com\fP
245 does not respond.
246 In that case, the URI list is internally rearranged, by moving unavailable
247 URIs to the end, so that further connection attempts occur with respect to
248 the last URI that succeeded.
249 .RE
250
251 .TP
252 .B acl-authcDN "<administrative DN for access control purposes>"
253 DN which is used to query the target server for acl checking,
254 as in the LDAP backend; it is supposed to have read access 
255 on the target server to attributes used on the proxy for acl checking.
256 There is no risk of giving away such values; they are only used to
257 check permissions.
258 .B The acl-authcDN identity is by no means implicitly used by the proxy 
259 .B when the client connects anonymously.
260
261 .TP
262 .B acl-passwd <password>
263 Password used with the
264 .B 
265 acl-authcDN
266 above.
267
268 .TP
269 .B bind-timeout <microseconds>
270 This directive defines the timeout, in microseconds, used when polling
271 for response after an asynchronous bind connection.  The initial call
272 to ldap_result(3) is performed with a trade-off timeout of 100000 us;
273 if that results in a timeout exceeded, subsequent calls use the value
274 provided with
275 .BR bind-timeout .
276 The default value is used also for subsequent calls if
277 .B bind-timeout
278 is not specified.
279 If set before any target specification, it affects all targets, unless
280 overridden by any per-target directive.
281
282 .TP
283 .B chase-referrals {YES|no}
284 enable/disable automatic referral chasing, which is delegated to the
285 underlying libldap, with rebinding eventually performed if the
286 \fBrebind-as-user\fP directive is used.  The default is to chase referrals.
287 If set before any target specification, it affects all targets, unless
288 overridden by any per-target directive.
289
290 .TP
291 .B default-target [<target>]
292 The "default-target" directive can also be used during target specification.
293 With no arguments it marks the current target as the default.
294 The optional number marks target <target> as the default one, starting
295 from 1.
296 Target <target> must be defined.
297
298 .TP
299 .B idassert-authzFrom <authz-regexp>
300 if defined, selects what
301 .I local
302 identities are authorized to exploit the identity assertion feature.
303 The string
304 .B <authz-regexp>
305 follows the rules defined for the
306 .I authzFrom
307 attribute.
308 See 
309 .BR slapd.conf (5),
310 section related to
311 .BR authz-policy ,
312 for details on the syntax of this field.
313
314 .HP
315 .hy 0
316 .B idassert-bind
317 .B bindmethod=none|simple|sasl [binddn=<simple DN>] [credentials=<simple password>]
318 .B [saslmech=<SASL mech>] [secprops=<properties>] [realm=<realm>]
319 .B [authcId=<authentication ID>] [authzId=<authorization ID>]
320 .B [authz={native|proxyauthz}] [mode=<mode>] [flags=<flags>]
321 .B [tls_cert=<file>]
322 .B [tls_key=<file>]
323 .B [tls_cacert=<file>]
324 .B [tls_cacertdir=<path>]
325 .B [tls_reqcert=never|allow|try|demand]
326 .B [tls_ciphersuite=<ciphers>]
327 .B [tls_crlcheck=none|peer|all]
328 .RS
329 Allows to define the parameters of the authentication method that is 
330 internally used by the proxy to authorize connections that are 
331 authenticated by other databases.
332 The identity defined by this directive, according to the properties
333 associated to the authentication method, is supposed to have auth access 
334 on the target server to attributes used on the proxy for authentication
335 and authorization, and to be allowed to authorize the users.
336 This requires to have
337 .B proxyAuthz
338 privileges on a wide set of DNs, e.g.
339 .BR authzTo=dn.subtree:"" ,
340 and the remote server to have
341 .B authz-policy
342 set to
343 .B to
344 or
345 .BR both .
346 See
347 .BR slapd.conf (5)
348 for details on these statements and for remarks and drawbacks about
349 their usage.
350 The supported bindmethods are
351
352 \fBnone|simple|sasl\fP
353
354 where
355 .B none
356 is the default, i.e. no \fIidentity assertion\fP is performed.
357
358 The authz parameter is used to instruct the SASL bind to exploit 
359 .B native 
360 SASL authorization, if available; since connections are cached,
361 this should only be used when authorizing with a fixed identity
362 (e.g. by means of the 
363 .B authzDN
364 or
365 .B authzID
366 parameters).
367 Otherwise, the default
368 .B proxyauthz
369 is used, i.e. the proxyAuthz control (Proxied Authorization, RFC 4370)
370 is added to all operations.
371
372 The supported modes are:
373
374 \fB<mode> := {legacy|anonymous|none|self}\fP
375
376 If 
377 .B <mode>
378 is not present, and 
379 .B authzId
380 is given, the proxy always authorizes that identity.
381 .B <authorization ID>
382 can be 
383
384 \fBu:<user>\fP
385
386 \fB[dn:]<DN>\fP
387
388 The former is supposed to be expanded by the remote server according 
389 to the authz rules; see
390 .BR slapd.conf (5)
391 for details.
392 In the latter case, whether or not the 
393 .B dn:
394 prefix is present, the string must pass DN validation and normalization.
395
396 The default mode is 
397 .BR legacy ,
398 which implies that the proxy will either perform a simple bind as the
399 .I authcDN
400 or a SASL bind as the
401 .I authcID
402 and assert the client's identity when it is not anonymous.
403 Direct binds are always proxied.
404 The other modes imply that the proxy will always either perform a simple bind 
405 as the
406 .IR authcDN
407 or a SASL bind as the
408 .IR authcID ,
409 unless restricted by
410 .BR idassert-authzFrom
411 rules (see below), in which case the operation will fail;
412 eventually, it will assert some other identity according to
413 .BR <mode> .
414 Other identity assertion modes are
415 .BR anonymous
416 and
417 .BR self ,
418 which respectively mean that the 
419 .I empty 
420 or the 
421 .IR client 's 
422 identity
423 will be asserted;
424 .BR none ,
425 which means that no proxyAuthz control will be used, so the
426 .I authcDN
427 or the
428 .I authcID
429 identity will be asserted.
430 For all modes that require the use of the
431 .I proxyAuthz 
432 control, on the remote server the proxy identity must have appropriate 
433 .I authzTo
434 permissions, or the asserted identities must have appropriate
435 .I authzFrom 
436 permissions.  Note, however, that the ID assertion feature is mostly 
437 useful when the asserted identities do not exist on the remote server.
438
439 Flags can be
440
441 \fBoverride,[non-]prescriptive\fP
442
443 When the 
444 .B override
445 flag is used, identity assertion takes place even when the database
446 is authorizing for the identity of the client, i.e. after binding
447 with the provided identity, and thus authenticating it, the proxy
448 performs the identity assertion using the configured identity and
449 authentication method.
450
451 When the
452 .B prescriptive
453 flag is used (the default), operations fail with
454 \fIinappropriateAuthentication\fP
455 for those identities whose assertion is not allowed by the
456 .B idassert-authzFrom
457 patterns.
458 If the 
459 .B non-prescriptive
460 flag is used, operations are performed anonymously for those identities 
461 whose assertion is not allowed by the
462 .B idassert-authzFrom
463 patterns.
464
465 The TLS settings default to the same as the main slapd TLS settings,
466 except for
467 .B tls_reqcert
468 which defaults to "demand".
469
470 The identity associated to this directive is also used for privileged
471 operations whenever \fBidassert-bind\fP is defined and \fBacl-bind\fP
472 is not.  See \fBacl-bind\fP for details.
473 .RE
474
475 .TP
476 .B idle-timeout <time>
477 This directive causes a cached connection to be dropped an recreated
478 after it has been idle for the specified time.
479 The value can be specified as
480
481 [<d>d][<h>h][<m>m][<s>[s]]
482
483 where <d>, <h>, <m> and <s> are respectively treated as days, hours, 
484 minutes and seconds.
485 If set before any target specification, it affects all targets, unless
486 overridden by any per-target directive.
487
488 .TP
489 .B map "{attribute|objectclass} [<local name>|*] {<foreign name>|*}"
490 This maps object classes and attributes as in the LDAP backend.
491 See
492 .BR slapd-ldap (5).
493
494 .TP
495 .B network-timeout <time>
496 Sets the network timeout value after which
497 .BR poll (2)/ select (2) 
498 following a 
499 .BR connect (2) 
500 returns in case of no activity.
501 The value is in seconds, and it can be specified as for
502 .BR idle-timeout .
503 If set before any target specification, it affects all targets, unless
504 overridden by any per-target directive.
505
506 .TP
507 .B nretries {forever|never|<nretries>}
508 This directive defines how many times a bind should be retried
509 in case of temporary failure in contacting a target.  If defined
510 before any target specification, it applies to all targets (by default,
511 .BR 3
512 times);
513 the global value can be overridden by redefinitions inside each target
514 specification.
515
516 .TP
517 .B pseudorootdn "<substitute DN in case of rootdn bind>"
518 This directive, if present, sets the DN that will be substituted to
519 the bind DN if a bind with the backend's "rootdn" succeeds.
520 The true "rootdn" of the target server ought not be used; an arbitrary
521 administrative DN should used instead.
522
523 .TP
524 .B pseudorootpw "<substitute password in case of rootdn bind>"
525 This directive sets the credential that will be used in case a bind
526 with the backend's "rootdn" succeeds, and the bind is propagated to
527 the target using the "pseudorootdn" DN.
528
529 Note: cleartext credentials must be supplied here; as a consequence,
530 using the pseudorootdn/pseudorootpw directives is inherently unsafe.
531
532 .TP
533 .B rewrite* ...
534 The rewrite options are described in the "REWRITING" section.
535
536 .TP
537 .B subtree-exclude "<DN>"
538 This directive instructs back-meta to ignore the current target
539 for operations whose requestDN is subordinate to
540 .BR DN .
541 There may be multiple occurrences of the
542 .B subtree-exclude
543 directive for each of the targets.
544
545 .TP
546 .B suffixmassage "<virtual naming context>" "<real naming context>"
547 All the directives starting with "rewrite" refer to the rewrite engine
548 that has been added to slapd.
549 The "suffixmassage" directive was introduced in the LDAP backend to
550 allow suffix massaging while proxying.
551 It has been obsoleted by the rewriting tools.
552 However, both for backward compatibility and for ease of configuration
553 when simple suffix massage is required, it has been preserved.
554 It wraps the basic rewriting instructions that perform suffix
555 massaging.  See the "REWRITING" section for a detailed list 
556 of the rewrite rules it implies.
557
558 .TP
559 .B t-f-support {NO|yes|discover}
560 enable if the remote server supports absolute filters
561 (see \fIdraft-zeilenga-ldap-t-f\fP for details).
562 If set to
563 .BR discover ,
564 support is detected by reading the remote server's root DSE.
565 If set before any target specification, it affects all targets, unless
566 overridden by any per-target directive.
567
568 .TP
569 .B timeout [<op>=]<val> [...]
570 This directive allows to set per-operation timeouts.
571 Operations can be
572
573 \fB<op> ::= bind, add, delete, modrdn, modify, compare, search\fP
574
575 The overall duration of the \fBsearch\fP operation is controlled either
576 by the \fBtimelimit\fP parameter or by server-side enforced
577 time limits (see \fBtimelimit\fP and \fBlimits\fP in
578 .BR slapd.conf (5)
579 for details).
580 This \fBtimeout\fP parameter controls how long the target can be 
581 irresponsive before the operation is aborted.
582 Timeout is meaningless for the remaining operations,
583 \fBunbind\fP and \fBabandon\fP, which do not imply any response,
584 while it is not yet implemented in currently supported \fBextended\fP 
585 operations.
586 If no operation is specified, the timeout \fBval\fP affects all
587 supported operations.
588 If specified before any target definition, it affects all targets
589 unless overridden by per-target directives.
590
591 Note: if the timeout is exceeded, the operation is cancelled
592 (according to the \fBcancel\fP directive);
593 the protocol does not provide any means to rollback operations,
594 so the client will not be notified about the result of the operation,
595 which may eventually succeeded or not.
596 In case the timeout is exceeded during a bind operation, the connection
597 is destroyed, according to RFC4511.
598
599 .TP
600 .B tls {[try-]start|[try-]propagate}
601 execute the StartTLS extended operation when the connection is initialized;
602 only works if the URI directive protocol scheme is not \fBldaps://\fP.
603 \fBpropagate\fP issues the StartTLS operation only if the original
604 connection did.
605 The \fBtry-\fP prefix instructs the proxy to continue operations
606 if the StartTLS operation failed; its use is highly deprecated.
607 If set before any target specification, it affects all targets, unless
608 overridden by any per-target directive.
609
610 .SH SCENARIOS
611 A powerful (and in some sense dangerous) rewrite engine has been added
612 to both the LDAP and Meta backends.
613 While the former can gain limited beneficial effects from rewriting
614 stuff, the latter can become an amazingly powerful tool.
615 .LP
616 Consider a couple of scenarios first.
617 .LP
618 1) Two directory servers share two levels of naming context;
619 say "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
620 Then, an unambiguous Meta database can be configured as:
621 .LP
622 .RS
623 .nf
624 database meta
625 suffix   "\fBdc=foo,dc=com\fP"
626 uri      "ldap://a.foo.com/dc=a,\fBdc=foo,dc=com\fP"
627 uri      "ldap://b.foo.com/dc=b,\fBdc=foo,dc=com\fP"
628 .fi
629 .RE
630 .LP
631 Operations directed to a specific target can be easily resolved
632 because there are no ambiguities.
633 The only operation that may resolve to multiple targets is a search
634 with base "dc=foo,dc=com" and scope at least "one", which results in
635 spawning two searches to the targets.
636 .LP
637 2a) Two directory servers don't share any portion of naming context,
638 but they'd present as a single DIT
639 [Caveat: uniqueness of (massaged) entries among the two servers is
640 assumed; integrity checks risk to incur in excessive overhead and have
641 not been implemented].
642 Say we have "dc=bar,dc=org" and "o=Foo,c=US",
643 and we'd like them to appear as branches of "dc=foo,dc=com", say
644 "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
645 Then we need to configure our Meta backend as:
646 .LP
647 .RS
648 .nf
649 database      meta
650 suffix        "dc=foo,dc=com"
651
652 uri           "ldap://a.bar.com/\fBdc=a,dc=foo,dc=com\fP"
653 suffixmassage "\fBdc=a,dc=foo,dc=com\fP" "dc=bar,dc=org"
654
655 uri           "ldap://b.foo.com/\fBdc=b,dc=foo,dc=com\fP"
656 suffixmassage "\fBdc=b,dc=foo,dc=com\fP" "o=Foo,c=US"
657 .fi
658 .RE
659 .LP
660 Again, operations can be resolved without ambiguity, although
661 some rewriting is required.
662 Notice that the virtual naming context of each target is a branch of
663 the database's naming context; it is rewritten back and forth when
664 operations are performed towards the target servers.
665 What "back and forth" means will be clarified later.
666 .LP
667 When a search with base "dc=foo,dc=com" is attempted, if the 
668 scope is "base" it fails with "no such object"; in fact, the
669 common root of the two targets (prior to massaging) does not
670 exist.
671 If the scope is "one", both targets are contacted with the base
672 replaced by each target's base; the scope is derated to "base".
673 In general, a scope "one" search is honored, and the scope is derated,
674 only when the incoming base is at most one level lower of a target's
675 naming context (prior to massaging).
676 .LP
677 Finally, if the scope is "sub" the incoming base is replaced
678 by each target's unmassaged naming context, and the scope
679 is not altered.
680 .LP
681 2b) Consider the above reported scenario with the two servers
682 sharing the same naming context:
683 .LP
684 .RS
685 .nf
686 database      meta
687 suffix        "\fBdc=foo,dc=com\fP"
688
689 uri           "ldap://a.bar.com/\fBdc=foo,dc=com\fP"
690 suffixmassage "\fBdc=foo,dc=com\fP" "dc=bar,dc=org"
691
692 uri           "ldap://b.foo.com/\fBdc=foo,dc=com\fP"
693 suffixmassage "\fBdc=foo,dc=com\fP" "o=Foo,c=US"
694 .fi
695 .RE
696 .LP
697 All the previous considerations hold, except that now there is
698 no way to unambiguously resolve a DN.
699 In this case, all the operations that require an unambiguous target
700 selection will fail unless the DN is already cached or a default
701 target has been set.
702 Practical configurations may result as a combination of all the
703 above scenarios.
704 .SH ACLs
705 Note on ACLs: at present you may add whatever ACL rule you desire
706 to to the Meta (and LDAP) backends.
707 However, the meaning of an ACL on a proxy may require some
708 considerations.
709 Two philosophies may be considered:
710 .LP
711 a) the remote server dictates the permissions; the proxy simply passes
712 back what it gets from the remote server.
713 .LP
714 b) the remote server unveils "everything"; the proxy is responsible
715 for protecting data from unauthorized access.
716 .LP
717 Of course the latter sounds unreasonable, but it is not.
718 It is possible to imagine scenarios in which a remote host discloses
719 data that can be considered "public" inside an intranet, and a proxy
720 that connects it to the internet may impose additional constraints.
721 To this purpose, the proxy should be able to comply with all the ACL
722 matching criteria that the server supports.
723 This has been achieved with regard to all the criteria supported by
724 slapd except a special subtle case (please drop me a note if you can
725 find other exceptions: <ando@openldap.org>).
726 The rule
727 .LP
728 .RS
729 .nf
730 access to dn="<dn>" attrs=<attr>
731        by dnattr=<dnattr> read
732        by * none
733 .fi
734 .RE
735 .LP
736 cannot be matched iff the attribute that is being requested, <attr>,
737 is NOT <dnattr>, and the attribute that determines membership,
738 <dnattr>, has not been requested (e.g. in a search)
739 .LP
740 In fact this ACL is resolved by slapd using the portion of entry it
741 retrieved from the remote server without requiring any further
742 intervention of the backend, so, if the <dnattr> attribute has not
743 been fetched, the match cannot be assessed because the attribute is
744 not present, not because no value matches the requirement!
745 .LP
746 Note on ACLs and attribute mapping: ACLs are applied to the mapped
747 attributes; for instance, if the attribute locally known as "foo" is
748 mapped to "bar" on a remote server, then local ACLs apply to attribute
749 "foo" and are totally unaware of its remote name.
750 The remote server will check permissions for "bar", and the local
751 server will possibly enforce additional restrictions to "foo".
752 .\"
753 .\" If this section is moved, also update the reference in
754 .\" libraries/librewrite/RATIONALE.
755 .\"
756 .SH REWRITING
757 A string is rewritten according to a set of rules, called a `rewrite
758 context'.
759 The rules are based on POSIX (''extended'') regular expressions (regex)
760 with substring matching; basic variable substitution and map resolution 
761 of substrings is allowed by specific mechanisms detailed in the following.
762 The behavior of pattern matching/substitution can be altered by a set
763 of flags.
764 .LP
765 The underlying concept is to build a lightweight rewrite module
766 for the slapd server (initially dedicated to the LDAP backend).
767 .SH Passes
768 An incoming string is matched against a set of rules.
769 Rules are made of a regex match pattern, a substitution pattern
770 and a set of actions, described by a set of flags.
771 In case of match a string rewriting is performed according to the
772 substitution pattern that allows to refer to substrings matched in the
773 incoming string.
774 The actions, if any, are finally performed.
775 The substitution pattern allows map resolution of substrings.
776 A map is a generic object that maps a substitution pattern to a value.
777 The flags are divided in "Pattern matching Flags" and "Action Flags";
778 the former alter the regex match pattern behavior while the latter
779 alter the action that is taken after substitution.
780 .SH "Pattern Matching Flags"
781 .TP
782 .B `C'
783 honors case in matching (default is case insensitive)
784 .TP
785 .B `R'
786 use POSIX ''basic'' regular expressions (default is ''extended'')
787 .TP
788 .B `M{n}'
789 allow no more than
790 .B n
791 recursive passes for a specific rule; does not alter the max total count
792 of passes, so it can only enforce a stricter limit for a specific rule.
793 .SH "Action Flags"
794 .TP
795 .B `:'
796 apply the rule once only (default is recursive)
797 .TP
798 .B `@'
799 stop applying rules in case of match; the current rule is still applied 
800 recursively; combine with `:' to apply the current rule only once 
801 and then stop.
802 .TP
803 .B `#'
804 stop current operation if the rule matches, and issue an `unwilling to
805 perform' error.
806 .TP
807 .B `G{n}'
808 jump
809 .B n
810 rules back and forth (watch for loops!).
811 Note that `G{1}' is implicit in every rule.
812 .TP
813 .B `I'
814 ignores errors in rule; this means, in case of error, e.g. issued by a
815 map, the error is treated as a missed match.
816 The `unwilling to perform' is not overridden.
817 .TP
818 .B `U{n}'
819 uses
820 .B
821 n
822 as return code if the rule matches; the flag does not alter the recursive
823 behavior of the rule, so, to have it performed only once, it must be used 
824 in combination with `:', e.g.
825 .B `:U{16}'
826 returns the value `16' after exactly one execution of the rule, if the
827 pattern matches.
828 As a consequence, its behavior is equivalent to `@', with the return
829 code set to
830 .BR n ;
831 or, in other words, `@' is equivalent to `U{0}'.
832 By convention, the freely available codes are above 16 included;
833 the others are reserved.
834 .LP
835 The ordering of the flags can be significant.
836 For instance: `IG{2}' means ignore errors and jump two lines ahead
837 both in case of match and in case of error, while `G{2}I' means ignore
838 errors, but jump two lines ahead only in case of match.
839 .LP
840 More flags (mainly Action Flags) will be added as needed.
841 .SH "Pattern matching:"
842 See
843 .BR regex (7)
844 and/or
845 .BR re_format (7).
846 .SH "Substitution Pattern Syntax:"
847 Everything starting with `%' requires substitution;
848 .LP
849 the only obvious exception is `%%', which is left as is;
850 .LP
851 the basic substitution is `%d', where `d' is a digit;
852 0 means the whole string, while 1-9 is a submatch;
853 .LP
854 a `%' followed by a `{' invokes an advanced substitution.
855 The pattern is:
856 .LP
857 .RS
858 `%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
859 .RE
860 .LP
861 where <name> must be a legal name for the map, i.e.
862 .LP
863 .RS
864 .nf
865 <name> ::= [a-z][a-z0-9]* (case insensitive)
866 <op> ::= `>' `|' `&' `&&' `*' `**' `$'
867 .fi
868 .RE
869 .LP
870 and <substitution> must be a legal substitution
871 pattern, with no limits on the nesting level.
872 .LP
873 The operators are:
874 .TP
875 .B >
876 sub context invocation; <name> must be a legal, already defined
877 rewrite context name
878 .TP
879 .B |
880 external command invocation; <name> must refer to a legal, already
881 defined command name (NOT IMPL.)
882 .TP
883 .B &
884 variable assignment; <name> defines a variable in the running
885 operation structure which can be dereferenced later; operator
886 .B &
887 assigns a variable in the rewrite context scope; operator
888 .B &&
889 assigns a variable that scopes the entire session, e.g. its value
890 can be dereferenced later by other rewrite contexts
891 .TP
892 .B *
893 variable dereferencing; <name> must refer to a variable that is
894 defined and assigned for the running operation; operator
895 .B *
896 dereferences a variable scoping the rewrite context; operator
897 .B **
898 dereferences a variable scoping the whole session, e.g. the value
899 is passed across rewrite contexts
900 .TP
901 .B $
902 parameter dereferencing; <name> must refer to an existing parameter;
903 the idea is to make some run-time parameters set by the system
904 available to the rewrite engine, as the client host name, the bind DN
905 if any, constant parameters initialized at config time, and so on;
906 no parameter is currently set by either 
907 .B back\-ldap
908 or
909 .BR back\-meta ,
910 but constant parameters can be defined in the configuration file
911 by using the
912 .B rewriteParam
913 directive.
914 .LP
915 Substitution escaping has been delegated to the `%' symbol, 
916 which is used instead of `\e' in string substitution patterns
917 because `\e' is already escaped by slapd's low level parsing routines;
918 as a consequence, regex escaping requires two `\e' symbols,
919 e.g. `\fB.*\e.foo\e.bar\fP' must be written as `\fB.*\e\e.foo\e\e.bar\fP'.
920 .\"
921 .\" The symbol can be altered at will by redefining the related macro in
922 .\" "rewrite-int.h".
923 .\"
924 .SH "Rewrite context:"
925 A rewrite context is a set of rules which are applied in sequence.
926 The basic idea is to have an application initialize a rewrite
927 engine (think of Apache's mod_rewrite ...) with a set of rewrite
928 contexts; when string rewriting is required, one invokes the
929 appropriate rewrite context with the input string and obtains the
930 newly rewritten one if no errors occur.
931 .LP
932 Each basic server operation is associated to a rewrite context;
933 they are divided in two main groups: client \-> server and
934 server \-> client rewriting.
935 .LP
936 client -> server:
937 .LP
938 .RS
939 .nf
940 (default)            if defined and no specific context 
941                      is available
942 bindDN               bind
943 searchBase           search
944 searchFilter         search
945 searchFilterAttrDN   search
946 compareDN            compare
947 compareAttrDN        compare AVA
948 addDN                add
949 addAttrDN            add AVA
950 modifyDN             modify
951 modifyAttrDN         modify AVA
952 modrDN               modrdn
953 newSuperiorDN        modrdn
954 deleteDN             delete
955 exopPasswdDN         password modify extended operation DN if proxy
956 .fi
957 .RE
958 .LP
959 server -> client:
960 .LP
961 .RS
962 .nf
963 searchResult         search (only if defined; no default;
964                      acts on DN and DN-syntax attributes 
965                      of search results)
966 searchAttrDN         search AVA
967 matchedDN            all ops (only if applicable)
968 .fi
969 .RE
970 .LP
971 .SH "Basic configuration syntax"
972 .TP
973 .B rewriteEngine { on | off }
974 If `on', the requested rewriting is performed; if `off', no
975 rewriting takes place (an easy way to stop rewriting without
976 altering too much the configuration file).
977 .TP
978 .B rewriteContext <context name> "[ alias <aliased context name> ]"
979 <Context name> is the name that identifies the context, i.e. the name
980 used by the application to refer to the set of rules it contains.
981 It is used also to reference sub contexts in string rewriting.
982 A context may alias another one.
983 In this case the alias context contains no rule, and any reference to
984 it will result in accessing the aliased one.
985 .TP
986 .B rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
987 Determines how a string can be rewritten if a pattern is matched.
988 Examples are reported below.
989 .SH "Additional configuration syntax:"
990 .TP
991 .B rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
992 Allows to define a map that transforms substring rewriting into
993 something else.
994 The map is referenced inside the substitution pattern of a rule.
995 .TP
996 .B rewriteParam <param name> <param value>
997 Sets a value with global scope, that can be dereferenced by the
998 command `%{$paramName}'.
999 .TP
1000 .B rewriteMaxPasses <number of passes> [<number of passes per rule>]
1001 Sets the maximum number of total rewriting passes that can be
1002 performed in a single rewrite operation (to avoid loops).
1003 A safe default is set to 100; note that reaching this limit is still
1004 treated as a success; recursive invocation of rules is simply 
1005 interrupted.
1006 The count applies to the rewriting operation as a whole, not 
1007 to any single rule; an optional per-rule limit can be set.
1008 This limit is overridden by setting specific per-rule limits
1009 with the `M{n}' flag.
1010 .SH "Configuration examples:"
1011 .nf
1012 # set to `off' to disable rewriting
1013 rewriteEngine on
1014
1015 # the rules the "suffixmassage" directive implies
1016 rewriteEngine on
1017 # all dataflow from client to server referring to DNs
1018 rewriteContext default
1019 rewriteRule "(.*)<virtualnamingcontext>$" "%1<realnamingcontext>" ":"
1020 # empty filter rule
1021 rewriteContext searchFilter
1022 # all dataflow from server to client
1023 rewriteContext searchResult
1024 rewriteRule "(.*)<realnamingcontext>$" "%1<virtualnamingcontext>" ":"
1025 rewriteContext searchAttrDN alias searchResult
1026 rewriteContext matchedDN alias searchResult
1027
1028 # Everything defined here goes into the `default' context.
1029 # This rule changes the naming context of anything sent
1030 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
1031
1032 rewriteRule "(.*)dc=home,[ ]?dc=net"
1033             "%1dc=OpenLDAP, dc=org"  ":"
1034
1035 # since a pretty/normalized DN does not include spaces
1036 # after rdn separators, e.g. `,', this rule suffices:
1037
1038 rewriteRule "(.*)dc=home,dc=net"
1039             "%1dc=OpenLDAP,dc=org"  ":"
1040
1041 # Start a new context (ends input of the previous one).
1042 # This rule adds blanks between DN parts if not present.
1043 rewriteContext  addBlanks
1044 rewriteRule     "(.*),([^ ].*)" "%1, %2"
1045
1046 # This one eats blanks
1047 rewriteContext  eatBlanks
1048 rewriteRule     "(.*),[ ](.*)" "%1,%2"
1049
1050 # Here control goes back to the default rewrite
1051 # context; rules are appended to the existing ones.
1052 # anything that gets here is piped into rule `addBlanks'
1053 rewriteContext  default
1054 rewriteRule     ".*" "%{>addBlanks(%0)}" ":"
1055
1056 .\" # Anything with `uid=username' is looked up in
1057 .\" # /etc/passwd for gecos (I know it's nearly useless,
1058 .\" # but it is there just as a guideline to implementing
1059 .\" # custom maps).
1060 .\" # Note the `I' flag that leaves `uid=username' in place 
1061 .\" # if `username' does not have a valid account, and the
1062 .\" # `:' that forces the rule to be processed exactly once.
1063 .\" rewriteContext  uid2Gecos
1064 .\" rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
1065 .\"                 "%1cn=%2{xpasswd},%3"      "I:"
1066 .\" 
1067 .\" # Finally, in a bind, if one uses a `uid=username' DN,
1068 .\" # it is rewritten in `cn=name surname' if possible.
1069 .\" rewriteContext  bindDN
1070 .\" rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
1071 .\" 
1072 # Rewrite the search base according to `default' rules.
1073 rewriteContext  searchBase alias default
1074
1075 # Search results with OpenLDAP DN are rewritten back with
1076 # `dc=home,dc=net' naming context, with spaces eaten.
1077 rewriteContext  searchResult
1078 rewriteRule     "(.*[^ ]?)[ ]?dc=OpenLDAP,[ ]?dc=org"
1079                 "%{>eatBlanks(%1)}dc=home,dc=net"    ":"
1080
1081 # Bind with email instead of full DN: we first need
1082 # an ldap map that turns attributes into a DN (the
1083 # argument used when invoking the map is appended to 
1084 # the URI and acts as the filter portion)
1085 rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
1086
1087 # Then we need to detect DN made up of a single email,
1088 # e.g. `mail=someone@example.com'; note that the rule
1089 # in case of match stops rewriting; in case of error,
1090 # it is ignored.  In case we are mapping virtual
1091 # to real naming contexts, we also need to rewrite
1092 # regular DNs, because the definition of a bindDn
1093 # rewrite context overrides the default definition.
1094 rewriteContext bindDN
1095 rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" ":@I"
1096
1097 # This is a rather sophisticated example. It massages a
1098 # search filter in case who performs the search has
1099 # administrative privileges.  First we need to keep
1100 # track of the bind DN of the incoming request, which is
1101 # stored in a variable called `binddn' with session scope,
1102 # and left in place to allow regular binding:
1103 rewriteContext  bindDN
1104 rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
1105
1106 # A search filter containing `uid=' is rewritten only
1107 # if an appropriate DN is bound.
1108 # To do this, in the first rule the bound DN is
1109 # dereferenced, while the filter is decomposed in a
1110 # prefix, in the value of the `uid=<arg>' AVA, and 
1111 # in a suffix. A tag `<>' is appended to the DN. 
1112 # If the DN refers to an entry in the `ou=admin' subtree, 
1113 # the filter is rewritten OR-ing the `uid=<arg>' with
1114 # `cn=<arg>'; otherwise it is left as is. This could be
1115 # useful, for instance, to allow apache's auth_ldap-1.4
1116 # module to authenticate users with both `uid' and
1117 # `cn', but only if the request comes from a possible
1118 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
1119 rewriteContext searchFilter
1120 rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
1121   "%{**binddn}<>%{&prefix(%1)}%{&arg(%2)}%{&suffix(%3)}"
1122   ":I"
1123 rewriteRule "[^,]+,ou=admin,dc=home,dc=net"
1124   "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" ":@I"
1125 rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
1126
1127 # This example shows how to strip unwanted DN-valued
1128 # attribute values from a search result; the first rule
1129 # matches DN values below "ou=People,dc=example,dc=com";
1130 # in case of match the rewriting exits successfully.
1131 # The second rule matches everything else and causes
1132 # the value to be rejected.
1133 rewriteContext searchResult
1134 rewriteRule ".*,ou=People,dc=example,dc=com" "%0" ":@"
1135 rewriteRule ".*" "" "#"
1136 .fi
1137 .SH "LDAP Proxy resolution (a possible evolution of slapd\-ldap(5)):"
1138 In case the rewritten DN is an LDAP URI, the operation is initiated
1139 towards the host[:port] indicated in the uri, if it does not refer
1140 to the local server.
1141 E.g.:
1142 .LP
1143 .nf
1144   rewriteRule '^cn=root,.*' '%0'                     'G{3}'
1145   rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' ':@'
1146   rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' ':@'
1147   rewriteRule '.*'          'ldap://ldap3.my.org/%0' ':@'
1148 .fi
1149 .LP
1150 (Rule 1 is simply there to illustrate the `G{n}' action; it could have
1151 been written:
1152 .LP
1153 .nf
1154   rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' ':@'
1155 .fi
1156 .LP
1157 with the advantage of saving one rewrite pass ...)
1158
1159 .SH ACCESS CONTROL
1160 The
1161 .B meta
1162 backend does not honor all ACL semantics as described in
1163 .BR slapd.access (5).
1164 In general, access checking is delegated to the remote server(s).
1165 Only
1166 .B read (=r)
1167 access to the
1168 .B entry
1169 pseudo-attribute and to the other attribute values of the entries
1170 returned by the
1171 .B search
1172 operation is honored, which is performed by the frontend.
1173
1174 .SH PROXY CACHE OVERLAY
1175 The proxy cache overlay 
1176 allows caching of LDAP search requests (queries) in a local database.
1177 See 
1178 .BR slapo-pcache (5)
1179 for details.
1180 .SH FILES
1181 .TP
1182 ETCDIR/slapd.conf
1183 default slapd configuration file
1184 .SH SEE ALSO
1185 .BR slapd.conf (5),
1186 .BR slapd\-ldap (5),
1187 .BR slapo\-pcache (5),
1188 .BR slapd (8),
1189 .BR regex (7),
1190 .BR re_format (7).
1191 .SH AUTHOR
1192 Pierangelo Masarati, based on back-ldap by Howard Chu