summaryrefslogtreecommitdiffstats
path: root/roles/common-LDAP/templates/etc/ldap/database.ldif.j2
blob: b9f282f65f8637d622d550aa3866eadede1d551f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# Fripost's LDAP database definition
# Copyright (c) 2013-2014 Guilhem Moulin <guilhem@fripost.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

dn: cn=config
objectClass: olcGlobal
cn: config
olcArgsFile: /var/run/slapd/slapd.args
olcPidFile: /var/run/slapd/slapd.pid
olcLogLevel: none
olcToolThreads: 1
{% if ansible_processor_vcpus > 4 %}
olcThreads: {{ 2 * ansible_processor_vcpus }}
{% else %}
olcThreads: 8
{% endif %}
{% if 'LDAP-provider' in group_names %}
olcTLSCertificateFile: /etc/ldap/ssl/ldap.fripost.org.pem
olcTLSCertificateKeyFile: /etc/ldap/ssl/ldap.fripost.org.key
# If we are being offered a client cert, it has to be trusted (in which
# case we map the X.509 subject to a DN in our namespace), or we
# terminate the connection.  Not providing a certificate is fine for
# TLS-protected simple binds, though.
olcTLSVerifyClient: try
olcTLSCACertificateFile: /etc/ldap/ssl/clients.pem
olcAuthzRegexp: "^(cn=[^,]+,ou=syncRepl),ou=LDAP,ou=SSLcerts,o=Fripost$"
                "dn.exact:$1,dc=fripost,dc=org"
olcSaslSecProps: minssf=128,noanonymous,noplain,nodict
olcTLSCipherSuite: PFS:%LATEST_RECORD_VERSION:!CIPHER-ALL:+AES-128-GCM:+AES-256-GCM:!VERS-SSL3.0:!VERS-TLS1.0:!VERS-TLS1.1
{% endif %}
olcLocalSSF: 128
# /!\ This is not portable! But we only use glibc's crypt(3), which
# supports (salted, streched) SHA512
olcPasswordHash: {CRYPT}
olcPasswordCryptSaltFormat: $6$%s


dn: olcDatabase=monitor,cn=config
objectClass: olcDatabaseConfig
objectClass: olcMonitorConfig
olcRootDN: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
olcAccess: to dn.subtree="cn=monitor"
    by dn.exact="username=munin,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://" read
    by * =0


dn: olcDatabase=mdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcMdbConfig
olcDbDirectory: /var/lib/ldap
olcSuffix: dc=fripost,dc=org
{% if 'LDAP-provider' not in group_names and 'MX' in group_names %}
olcReadOnly: TRUE
{% endif %}
{% if 'LDAP-provider' in group_names %}
olcLastMod: TRUE
olcDbCheckpoint: 512 15
{% else %}
olcLastMod: FALSE
{% endif %}
# The root user has all rights on the whole database (when SASL-binding
# on a UNIX socket).
olcRootDN: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
# Ensure that all DIT access is made according to the LDAPv3 protocol,
# and must use 1/ authentication, and 2/ SASL or TLS.  (Local clients
# should use ldapi:// and SASL/EXERNAL, while remote clients should use
# TLS.)
olcRequires: none LDAPv3 authc strong
olcSecurity: simple_bind=128 ssf=128 update_ssf=128
#
#
########################################################################
# Performance considerations
#
# To reindex an existing database, you have to
#  * Stop slapd     sudo service slapd stop
#  * Reindex        sudo -u openldap slapindex -b 'dc=fripost,dc=org'
#  * Restart slapd  sudo service slapd start
#
olcDbIndex: objectClass eq
# Let us make Postfix's life easier.
{% if 'LDAP-provider' in group_names %}
olcDbIndex: fvd,fvl eq,sub
olcDbIndex: fripostIsStatusActive eq
{% elif 'MX' in group_names or 'MDA' in group_names %}
olcDbIndex: fripostIsStatusActive,fvd,fvl eq
{% endif %}
{% if 'LDAP-provider' in group_names %}
olcDbIndex: fripostOptionalMaildrop,fripostMaildrop eq,sub
olcDbIndex: fripostCanAddDomain,fripostCanAddAlias,fripostCanAddList,fripostOwner,fripostPostmaster,fripostListManager eq
{% elif 'MX' in group_names %}
olcDbIndex: fripostOptionalMaildrop pres
{% endif %}
{% if 'LDAP-provider' in group_names %}
olcDbIndex: member,cn eq
{% endif %}
{% if ('LDAP-provider' not in group_names and 'MX' in group_names) or
      ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
# SyncProv/SyncRepl specific indexing.
olcDbIndex: entryCSN,entryUUID eq
{% endif%}
#
#
# References
# - https://wiki.zimbra.com/wiki/OpenLDAP_Performance_Tuning_5.0
# - http://www.openldap.org/doc/admin24/tuning.html
# - http://www.openldap.org/faq/data/cache/42.html
# - http://www.openldap.org/faq/data/cache/136.html
# - http://www.zytrax.com/books/ldap/apa/indeces.html
#
#
########################################################################
# Sync Replication
#
# References:
# - http://www.openldap.org/doc/admin24/replication.html#Syncrepl
# - http://www.zytrax.com/books/ldap/ch7/#ol-syncrepl-rap
#
{% if 'LDAP-provider' in group_names %}
olcLimits: dn.onelevel="ou=syncRepl,dc=fripost,dc=org"
  time.soft=unlimited
  time.hard=unlimited
  size.soft=unlimited
  size.hard=unlimited
{% endif %}
{% if 'MX' in group_names and 'LDAP-provider' not in group_names %}
# Test it:
#   LDAPSASL_MECH=external LDAPTLS_CACERT=/etc/ldap/ssl/ldap.fripost.org.pem LDAPTLS_CERT=/etc/ldap/ssl/mx.pem LDAPTLS_KEY=/etc/ldap/ssl/mx.key sudo -u openldap ldapwhoami -H ldaps://ldap.fripost.org/
#   LDAPSASL_MECH=external LDAPTLS_CACERT=/etc/ldap/ssl/ldap.fripost.org.pem LDAPTLS_CERT=/etc/ldap/ssl/mx.pem LDAPTLS_KEY=/etc/ldap/ssl/mx.key sudo -u openldap ldapsearch -H ldaps://ldap.fripost.org/ -b ou=virtual,dc=fripost,dc=org
olcSyncrepl: rid=000
  provider=ldaps://ldap.fripost.org
  type=refreshAndPersist
  retry="10 30 300 +"
  searchbase="ou=virtual,dc=fripost,dc=org"
  attrs=objectClass,fvd,fvl,fripostIsStatusActive,fripostMaildrop,fripostOptionalMaildrop,fripostPostmaster,fripostOwner,fripostUseContentFilter,fripostListManager
  scope=sub
  sizelimit=unlimited
  schemachecking=off
  bindmethod=sasl
  saslmech=external
  tls_cert=/etc/ldap/ssl/mx.pem
  tls_key=/etc/ldap/ssl/mx.key
  tls_cacert=/etc/ldap/ssl/ldap.fripost.org.pem
  tls_reqcert=hard
{% endif %}
#
#
########################################################################
# Access control
# /!\ WARN: All modification to the ACL should be reflected to the test
# /!\ suite as well!
olcAddContentAcl: TRUE
#
# Overview:
# - Strong authentication is required prior to any DIT operation (see
#   'olcRequires').
# - We force a Security Strength Factor of 128 or above for all operations (see
#   'olcSecurity'), meaning one must use either a local connection (eg,
#   ldapi://, possible since we set the 'olcLocalSSF' to 128), or TLS with at
#   least 128 bits of security.
# - Services should support SASL binds and use SASL/EXTERNAL on a
#   ldapi:// socket.
# - For (partial) remote replicates should use SASL/EXTERNAL on a
#   ldaps:// socket, and their identity should be derived from the
#   Subject of the client certificate (the cert should be added to
#   'olcTLSCACertificateFile', and 'olcAuthzRegexp' should map the X.509
#   subject to the LDAP DN).
# - Admins have restrictions similar to that of the services.
# - User access is only restricted by our global 'olcSecurity' attribute.
#
#
# References:
# - http://www.openldap.org/doc/admin24/access-control.html
# - http://www.openldap.org/faq/data/cache/189.html
# - http://www.openldap.org/faq/data/cache/1140.html
# - http://www.openldap.org/faq/data/cache/1133.html
# - man 5 slapd.access
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# User Passwords:
#
# * Anonymous users are allowed to simple bind through TLS-protected
#   connections.
# * Anonymous users are allowed to simple bind when connecting to a
#   local ldapi:// socket (when using auth_binds, Dovecot delegates
#   authentication to the LDAP server).
# * Authenticated users are allowed to change (ie replace) their
#   password through TLS-protected connections, but read access is not
#   granted.
# * Domain postmasters are allowed to change (ie replace) their users'
#   password through TLS-protected connections, but read access is not
#   granted.
# * The same goes for general admins.
# * The same goes for local admins.
olcAccess: to dn.regex="^fvl=[^,]+,(fvd=[^,]+,ou=virtual,dc=fripost,dc=org)$"
        filter=(objectClass=FripostVirtualUser)
        attrs=userPassword
    by realanonymous                                                tls_ssf=128               =xd
    by realanonymous                                                sockurl.regex="^ldapi://" =xd
    by realself                                                     tls_ssf=128               =w
    by group/FripostVirtualDomain/fripostPostmaster.expand="$1"     tls_ssf=128               =w
    by dn.onelevel="ou=admins,dc=fripost,dc=org"                    tls_ssf=128               =w
    by group.exact="cn=admin,ou=groups,dc=fripost,dc=org"                                     =w
#
# * Services can authenticate
{% if 'LDAP-provider' in group_names -%}
olcAccess: to dn.onelevel="ou=services,dc=fripost,dc=org"
        filter=(objectClass=simpleSecurityObject)
        attrs=userPassword
    by realanonymous                                                tls_ssf=128               =xd
{% endif -%}
#
# * Catch-all: no one else may access the passwords (including for
#   simple bind).
olcAccess: to dn.subtree="dc=fripost,dc=org"
        attrs=userPassword
    by * =0
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Base
#
# * Only SyncRepl replicates may access operational attributes in the
#   subtree, when using a TLS-protected connection.
{% if 'LDAP-provider' in group_names -%}
olcAccess: to dn.subtree="ou=virtual,dc=fripost,dc=org"
        attrs=entryCSN,structuralObjectClass,hasSubordinates,subschemaSubentry
    by dn.onelevel="ou=syncRepl,dc=fripost,dc=org" tls_ssf=128 =rsd
    by *                                                       =0
#
# * They may also read entries (ie, the attributes they have access to
#   as per the ACL below) in that subtree, when using a TLS-protected
#   connection.  Listing entries (their DN) is required to replicate
#   deletions properly.
olcAccess: to dn.subtree="ou=virtual,dc=fripost,dc=org"
        attrs=entry,objectClass
    by dn.onelevel="ou=syncRepl,dc=fripost,dc=org" tls_ssf=128 =rsd
    by group.exact="cn=admin,ou=groups,dc=fripost,dc=org"      =wrsd
    by users                                                   =0   break
olcAccess: to dn.children="ou=virtual,dc=fripost,dc=org"
    by group.exact="cn=admin,ou=groups,dc=fripost,dc=org"      =wrsd
    by users                                                   =0   break
{% endif -%}
#
# * Postfix may use the base as a searchBase on the MX:es, when
#   connecting a local ldapi:// socket from the 'private' directory in
#   one of the non-default instance's chroot.
# * So may Dovecot on the MDA (needed for the iterate filter), when
#   SASL-binding using the EXTERNAL mechanism and connecting to a local
#   ldapi:// socket.
# * So may Nextcloud on the LDAP provider
olcAccess: to dn.exact="ou=virtual,dc=fripost,dc=org"
        attrs=entry,objectClass
        filter=(objectClass=FripostVirtual)
    {% if 'MDA' in group_names -%}
    by dn.exact="username=dovecot,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://"                                                    =sd
    {% endif -%}
    {% if 'MX' in group_names or 'MSA' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =sd
    {% endif -%}
    {% if 'LDAP-provider' in group_names -%}
    by dn.exact="cn=nextcloud,ou=services,dc=fripost,dc=org"       tls_ssf=128                                                                  =sd
    {% endif -%}
    by users                                                                                                                                    =0 break
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Domain entries
#
# * The SyncRepl replicates have read access to the entry itself, when
#   using a TLS-protected connection.
# * So has Postfix, when connecting a local ldapi:// socket from the
#   'private' directory in one of the non-default instance's chroot.
# * So has Dovecot on the MDA (for the iterate filter), when
#   SASL-binding using the EXTERNAL mechanism and connecting to a local
#   ldapi:// socket.
# * Amavis may use the entry as searchBase (required to look for the
#   per-user preferences) but doesn't have read access to the entry.
# * The 'nobody' UNIX user has read access on the MX:es, when using
#   SASL-binding using the EXTERNAL mechanism and connecting to a local
#   ldapi:// socket.  This is required for the 'reserved-alias.pl'
#   script.
olcAccess: to dn.regex="^fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,objectClass,fvd
        filter=(&(objectClass=FripostVirtualDomain)(!(objectClass=FripostPendingEntry)))
    {% if 'LDAP-provider' in group_names -%}
    {% if groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"              tls_ssf=128                                                                  =rsd
    {% endif -%}
    {% endif -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% if 'MDA' in group_names -%}
    by dn.exact="username=dovecot,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://"                                                    =rsd
    by dn.exact="username=amavis,cn=peercred,cn=external,cn=auth"  sockurl.regex="^ldapi://"                                                    =sd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=nobody,cn=peercred,cn=external,cn=auth"  sockurl.regex="^ldapi://"                                                    =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
#
# * The SyncRepl MX replicates can check whether a virtual domain is
#   active, and read the destination address for catch-alls, when using
#   a TLS-protected connection.
# * So can Postfix on the MX:es, when connecting a local ldapi:// socket
#   from the 'private' directory in one of the non-default instance's
#   chroot.
{% if 'MX' in group_names or ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
olcAccess: to dn.regex="^fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=fripostIsStatusActive,fripostOptionalMaildrop
        filter=(&(objectClass=FripostVirtualDomain)(!(objectClass=FripostPendingEntry)))
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"              tls_ssf=128                                                                  =rsd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
{% endif %}
#
# * The 'nobody' UNIX user can list the domain owners and postmasters on
#   the MX:es, when SASL-binding using the EXTERNAL mechanism and
#   connecting to a local ldapi:// socket.  This is required for the
#   'reserved-alias.pl' script.
olcAccess: to dn.regex="^fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=fripostOwner,fripostPostmaster
        filter=(&(objectClass=FripostVirtualDomain)(!(objectClass=FripostPendingEntry)))
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"             tls_ssf=128               =rsd
    {% endif -%}
    {% if 'MX' in group_names %}
    by dn.exact="username=nobody,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://" =rsd
    {% endif -%}
    by users                                                                                =0 break
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Alias domain entries
#
# * The SyncRepl MX replicates have read access to the entry itself and
#   the destination domain it aliases to, when using a TLS-protected
#   connection.
# * So has Postfix on the MX:es, when connecting a local ldapi:// socket
#   from the 'private' directory in one of the non-default instance's
#   chroot.
{% if 'MX' in group_names or ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
olcAccess: to dn.regex="^fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,fripostMaildrop
        filter=(&(objectClass=FripostVirtualAliasDomain)(!(objectClass=FripostPendingEntry)))
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"              tls_ssf=128                                                                  =rsd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
{% endif %}
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# User entries
#
# * The SyncRepl replicates have read access to the entry itself, when
#   using a TLS-protected connection.
# * So has Postfix, when connecting a local ldapi:// socket from the
#   'private' directory in one of the non-default instance's chroot.
# * So has Dovecot on the MDA (for the iterate filter), when
#   SASL-binding using the EXTERNAL mechanism and connecting to a local
#   ldapi:// socket.
# * So has Amavis on the MDA, when SASL-binding using the EXTERNAL
#   mechanism and connecting to a local ldapi:// socket.
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,objectClass,fvl
        filter=(objectClass=FripostVirtualUser)
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"                      tls_ssf=128                                                                  =rsd
    {% endif -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth"         sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% if 'MDA' in group_names -%}
    by dn.exact="username=dovecot,cn=peercred,cn=external,cn=auth"         sockurl.regex="^ldapi://"                                                    =rsd
    by dn.exact="username=amavis,cn=peercred,cn=external,cn=auth"          sockurl.regex="^ldapi://"                                                    =rsd
    {% endif -%}
    by users                                                                                                                                            =0 break
#
# * The SyncRepl MX replicates can check whether a virtual user is
#   active, when using a TLS-protected connection.
# * So can Postfix on the MX:es, when connecting a local ldapi:// socket
#   from the 'private' directory in one of the non-default instance's
#   chroot.
{% if 'MX' in group_names or ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=fripostIsStatusActive,fripostUseContentFilter
        filter=(objectClass=FripostVirtualUser)
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"      tls_ssf=128                                                                          =rsd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
{% endif %}
{% if 'MDA' in group_names %}
#
# * Amavis can look for per-user configuration options, when
#   SASL-binding using the EXTERNAL mechanism and connecting to a local
#   ldapi:// socket.
# TODO: only allow it to read the configuration options users are allowed
#       to set and modify.
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=@AmavisAccount
        filter=(&(objectClass=FripostVirtualUser)(objectClass=AmavisAccount)(fripostIsStatusActive=TRUE)(fripostUseContentFilter=TRUE))
    by dn.exact="username=amavis,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://" =rsd
    by users                                                                                =0 break
#
# * Dovecot can look for user quotas, when SASL-binding using the
#   EXTERNAL mechanism and connecting to a local ldapi:// socket.
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=fripostUserQuota
        filter=(objectClass=FripostVirtualUser)
    by dn.exact="username=dovecot,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://" =rsd
    by users                                                                                 =0 break
{% endif %}
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Alias entries
#
# * The SyncRepl MX replicates can read the entry itelf, whether it
#   is active, and the address(es) it aliases to, when using a
#   TLS-protected connection.
# * So can Postfix on the MX:es, when connecting a local ldapi:// socket
#   from the 'private' directory in one of the non-default instance's
#   chroot.
{% if 'MX' in group_names or ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,objectClass,fvl,fripostMaildrop,fripostIsStatusActive
        filter=(objectClass=FripostVirtualAlias)
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"              tls_ssf=128                                                                  =rsd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
{% endif %}
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# List entries
#
# * The SyncRepl replicates can read the entry itelf and the list manager, when
#   using a TLS-protected connection.
# * So can Postfix on the MX:es, when connecting a local ldapi:// socket
#   from the 'private' directory in one of the non-default instance's chroot.
{% if 'MX' in group_names or ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,objectClass,fvl,fripostListManager
        filter=(&(objectClass=FripostVirtualList)(!(objectClass=FripostPendingEntry)))
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"              tls_ssf=128                                                                  =rsd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
{% endif %}
#
# * The SyncRepl MX replicates can check whether a virtual list is
#   active when using a TLS-protected connection.
# * So can Postfix on the MX:es, when connecting a local ldapi:// socket
#   from the 'private' directory in one of the non-default instance's
#   chroot.
{% if 'MX' in group_names or ('LDAP-provider' in group_names and groups.MX | difference([inventory_hostname])) %}
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=fripostIsStatusActive
        filter=(&(objectClass=FripostVirtualList)(!(objectClass=FripostPendingEntry)))
    {% if 'LDAP-provider' in group_names and groups.MX | difference([inventory_hostname]) -%}
    by dn.exact="cn=mX,ou=syncRepl,dc=fripost,dc=org"              tls_ssf=128                                                                  =rsd
    {% endif -%}
    {% if 'MX' in group_names -%}
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    {% endif -%}
    by users                                                                                                                                    =0 break
{% endif %}
#
# * The MSA's postfix user can read entry ownership to dermine the SASL
#   login name(s) owning a given sender address
{% if 'MSA' in group_names %}
olcAccess: to dn.regex="^fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=fripostOwner,fripostPostmaster
        filter=(|(objectClass=FripostVirtualAliasDomain)(objectClass=FripostVirtualDomain))
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    by users                                                                                                                                    =0 break
olcAccess: to dn.regex="^fvl=[^,]+,fvd=[^,]+,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,objectClass,fvl,fripostOwner
        filter=(|(objectClass=FripostVirtualAlias)(objectClass=FripostVirtualList)(objectClass=FripostVirtualUser))
    by dn.exact="username=postfix,cn=peercred,cn=external,cn=auth" sockurl.regex="^ldapi://%2Fvar%2Fspool%2Fpostfix-[-[:alnum:]]+%2Fprivate%2F" =rsd
    by users                                                                                                                                    =0 break
{% endif %}
{% if 'LDAP-provider' in group_names %}
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Export Fripost members to Nextcloud
olcAccess: to dn.exact="fvd=fripost.org,ou=virtual,dc=fripost,dc=org"
        attrs=entry,objectClass,fvd
        filter=(&(objectClass=FripostVirtualDomain)(!(objectClass=FripostPendingEntry)))
    by dn.exact="cn=nextcloud,ou=services,dc=fripost,dc=org" tls_ssf=128 =rsd
    by users                                                             =0 break
olcAccess: to dn.regex="^fvl=[^,]+,fvd=fripost.org,ou=virtual,dc=fripost,dc=org$"
        attrs=entry,entryDN,entryUUID,objectClass,fvl,fripostIsStatusActive
        filter=(&(objectClass=FripostVirtualUser)(!(objectClass=FripostPendingEntry))(fripostIsStatusActive=TRUE))
    by dn.exact="cn=nextcloud,ou=services,dc=fripost,dc=org" tls_ssf=128 =rsd
    by users                                                             =0 break
olcAccess: to dn.exact="ou=groups,dc=fripost,dc=org"
        attrs=entry,objectClass
    by dn.exact="cn=nextcloud,ou=services,dc=fripost,dc=org" tls_ssf=128 =rsd
    by users                                                             =0 break
olcAccess: to dn.exact="cn=medlemmar,ou=groups,dc=fripost,dc=org"
    by dn.exact="cn=nextcloud,ou=services,dc=fripost,dc=org" tls_ssf=128 =rsd
    by users                                                             =0 break
#
# TODO: allow users to edit their entry, etc
#
{% endif %}
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Catch-all
#
# * Catch all the breaks above.
# * Deny any access to everyone else.
olcAccess: to dn.subtree="dc=fripost,dc=org"
    by dn.children="ou=virtual,dc=fripost,dc=org" +0
    by *                                          =0

# vim: set filetype=ldif :