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