]> Git — Sourcephile - sourcephile-nix.git/blob - servers/mermet/openldap.nix
openldap: use PR#79286
[sourcephile-nix.git] / servers / mermet / openldap.nix
1 { pkgs, lib, config, ... }:
2 let
3 inherit (builtins) baseNameOf readFile;
4 inherit (lib) types;
5 inherit (pkgs.lib) unlinesAttrs;
6 inherit (config) networking;
7 inherit (config.services) openldap;
8 inherit (config.users) ldap;
9 domainSuffix = "dc=" + lib.concatStringsSep ",dc=" (lib.splitString "." networking.domain);
10 in
11 {
12 imports = [
13 openldap/sourcephile.fr.nix
14 ];
15 config = {
16 users.ldap = {
17 enable = true;
18 server = "ldapi:///";
19 base = "ou=posix,${domainSuffix}";
20 bind = {
21 #distinguishedName = "cn=admin,${domainSuffix}";
22 };
23 daemon = {
24 enable = true;
25 extraConfig = ''
26 log syslog debug
27
28 sasl_mech EXTERNAL
29 # NOTE: nslcd cannot use SASL to bind to rootpwmoddn
30 # which is the DN used by nslcd when passwd is run by root
31 # to change the userPassword of an LDAP user.
32 # SEE: https://www.reddit.com/r/linuxadmin/comments/53sxpl/how_do_i_configure_nslcd_to_use_a_sasl_external/d7w9awd/
33 # Thus, use: ldappasswd -H ldapi:// -Y EXTERNAL uid=$user,ou=accounts,ou=posix,dc=sourcephile,dc=fr
34 '';
35 };
36 };
37 services.openldap = {
38 enable = true;
39 dataDir = "/var/db/ldap";
40 configDir = "/var/db/slapd";
41 urlList = [ "ldapi:///" ]; # UNIX socket
42 # sudo ldapsearch -LLL -H ldapi:// -D cn=admin,cn=config -Y EXTERNAL -b "" -s base supportedControl
43 cnConfig = ''
44 dn: cn=config
45 objectClass: olcGlobal
46 olcLogLevel: none
47 # The tool-threads parameter sets the actual amount of CPU's
48 # that is used for indexing.
49 olcToolThreads: ${toString config.nix.maxJobs}
50
51 dn: cn={0}module,cn=config
52 objectClass: olcModuleList
53 olcModulePath: ${pkgs.openldap}/lib/modules
54 olcModuleLoad: pw-sha2
55 olcModuleLoad: pw-pbkdf2
56 olcModuleLoad: back_mdb
57
58 # The first database is the special frontend database
59 # whose settings are applied globally to all the other databases.
60 # Beware that cn={0}module,cn=config must appear before
61 # for enabling password schemes provided by the modules in olcPasswordHash.
62 # ldapsearch -LLL -H ldapi:// -D cn=admin,cn=config -Y EXTERNAL -b 'olcDatabase={-1}frontend,cn=config' -s sub '*'
63 dn: olcDatabase={-1}frontend,cn=config
64 objectClass: olcDatabaseConfig
65 objectClass: olcFrontendConfig
66 # The maximum number of entries that is returned for a search operation
67 olcSizeLimit: 500
68 # Allow unlimited access to local connection from the local root user
69 olcAccess: to *
70 by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage
71 by * break
72 # Allow unauthenticated read access for schema and base DN autodiscovery
73 olcAccess: to dn.exact=""
74 by * read
75 olcAccess: to dn.base="cn=Subschema"
76 by * read
77 # Hash algorithm to be used by LDAP Password Modify Extended Operation or the ppolicy overlay
78 olcPasswordHash: {PBKDF2-SHA256}
79
80 dn: olcDatabase={0}config,cn=config
81 objectClass: olcDatabaseConfig
82 olcRootDN: cn=admin,cn=config
83 # Access to cn=config, system root can be manager
84 # with SASL mechanism (-Y EXTERNAL) over unix socket (-H ldapi://)
85 olcAccess: to *
86 by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
87 by * break
88
89 dn: cn=schema,cn=config
90 objectClass: olcSchemaConfig
91
92 include: file://${pkgs.openldap}/etc/schema/core.ldif
93 include: file://${pkgs.openldap}/etc/schema/cosine.ldif
94 include: file://${pkgs.openldap}/etc/schema/nis.ldif
95 include: file://${pkgs.openldap}/etc/schema/inetorgperson.ldif
96 include: file://${openldap/schema/postfix-book.ldif}
97 '';
98 };
99 };
100 }