NixOS configuration for HPC cluster https://docs.hpc.informatik.hs-fulda.de/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. { pkgs, lib, config, inputs, mkCert, ... }:
  2. with lib;
  3. let
  4. ldap-sync =
  5. let
  6. wrapped = pkgs.callPackage inputs.ldap-sync { };
  7. env = pkgs.runCommand "ldap-sync-env" { } ''
  8. mkdir -p $out
  9. ln -s ${config.sops.secrets."ldap/sync/config".path} $out/ldap-sync.properties
  10. '';
  11. in
  12. pkgs.runCommand "ldap-sync-wrapper"
  13. {
  14. nativeBuildInputs = [ pkgs.makeWrapper ];
  15. } ''
  16. mkdir -p $out/bin
  17. makeWrapper "${wrapped}/bin/ldap-sync" $out/bin/ldap-sync \
  18. --chdir "${env}"
  19. '';
  20. baseDN = concatMapStringsSep ","
  21. (part: "dc=${part}")
  22. (splitString "." config.networking.domain);
  23. cert = mkCert "ldap.${config.networking.domain}";
  24. cyrus_sasl = pkgs.cyrus_sasl.override {
  25. enableLdap = true;
  26. };
  27. in
  28. {
  29. services.openldap = {
  30. enable = true;
  31. package = (pkgs.openldap.overrideAttrs (final: prev: {
  32. configureFlags = prev.configureFlags ++ [
  33. "--enable-overlays"
  34. "--enable-remoteauth"
  35. "--enable-spasswd"
  36. "--with-cyrus-sasl"
  37. ];
  38. })).override {
  39. inherit cyrus_sasl;
  40. };
  41. urlList = [ "ldap:///" "ldaps:///" ];
  42. settings = {
  43. attrs = {
  44. olcLogLevel = "config ACL stats stats2 trace";
  45. olcTLSCACertificateFile = "${cert}/ca.pem";
  46. olcTLSCertificateFile = "${cert}/cert.pem";
  47. olcTLSCertificateKeyFile = "${cert}/key.pem";
  48. olcTLSCRLCheck = "none";
  49. olcTLSVerifyClient = "never";
  50. olcTLSProtocolMin = "3.1";
  51. #olcSecurity = "tls=1";
  52. olcSaslHost = "localhost";
  53. olcSaslSecProps = "none";
  54. };
  55. children = {
  56. "cn=schema".includes = [
  57. "${config.services.openldap.package}/etc/schema/core.ldif"
  58. "${config.services.openldap.package}/etc/schema/cosine.ldif"
  59. "${config.services.openldap.package}/etc/schema/inetorgperson.ldif"
  60. "${config.services.openldap.package}/etc/schema/nis.ldif"
  61. ];
  62. "olcDatabase={1}mdb" = {
  63. attrs = {
  64. objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
  65. olcDatabase = "{1}mdb";
  66. olcDbDirectory = "/var/lib/openldap/db";
  67. olcSuffix = baseDN;
  68. olcRootDN = "cn=root,${baseDN}";
  69. olcRootPW.path = config.sops.secrets."ldap/root/password".path;
  70. olcDbIndex = [
  71. "uid,uidNumber pres,eq"
  72. "cn,sn pres,eq,sub"
  73. "objectClass eq"
  74. ];
  75. olcAccess = [
  76. # Custom access rules for userPassword attributes
  77. ''{0}to attrs=userPassword
  78. by self read
  79. by anonymous auth
  80. by * none
  81. ''
  82. # Synced is managed by sync
  83. ''{1}to dn.subtree="ou=synced,ou=users,dc=hpc,dc=informatik,dc=hs-fulda,dc=de"
  84. by dn.base="cn=sync,dc=hpc,dc=informatik,dc=hs-fulda,dc=de" manage
  85. by * break
  86. ''
  87. # Allow login to read users
  88. ''{2}to dn.subtree="ou=users,dc=hpc,dc=informatik,dc=hs-fulda,dc=de"
  89. by dn.base="cn=login,dc=hpc,dc=informatik,dc=hs-fulda,dc=de" read
  90. by self read
  91. by * break
  92. ''
  93. # Prevent access
  94. ''{3}to *
  95. by * none
  96. ''
  97. ];
  98. };
  99. children = {
  100. "olcOverlay={0}remoteauth" = {
  101. attrs = {
  102. objectClass = [ "olcOverlayConfig" "olcRemoteAuthCfg" ];
  103. olcOverlay = "{0}remoteauth";
  104. olcRemoteAuthTLS = "starttls=yes tls_cacert=\"/etc/ssl/certs/ca-certificates.crt\"";
  105. olcRemoteAuthDNAttribute = "seeAlso";
  106. olcRemoteAuthDomainAttribute = "associatedDomain";
  107. olcRemoteAuthDefaultDomain = "upstream";
  108. olcRemoteAuthDefaultRealm = "file://${config.sops.secrets."ldap/upstream/list".path}";
  109. olcRemoteAuthRetryCount = "3";
  110. olcRemoteAuthStore = "false";
  111. };
  112. };
  113. };
  114. };
  115. };
  116. };
  117. };
  118. systemd.services.openldap = {
  119. environment = {
  120. SASL_PATH = pkgs.writeTextFile {
  121. name = "openldap-sasl-path";
  122. destination = "/slapd.conf";
  123. text = ''
  124. pwcheck_method: saslauthd
  125. saslauthd_path: /var/run/saslauthd/mux
  126. mech_list: GSSAPI EXTERNAL PLAIN NTLM
  127. '';
  128. };
  129. };
  130. };
  131. systemd.services."ldap-sync" = {
  132. script = "${ldap-sync}/bin/ldap-sync";
  133. startAt = "hourly";
  134. # Flush caches
  135. postStop = ''
  136. ${config.services.nscd.package}/bin/nscd --invalidate=group
  137. ${config.services.nscd.package}/bin/nscd --invalidate=passwd
  138. '';
  139. };
  140. networking.firewall.allowedTCPPorts = [
  141. 389
  142. 636
  143. ];
  144. sops.secrets."ldap/root/password" = {
  145. owner = "openldap";
  146. };
  147. sops.secrets."ldap/sync/config" = {
  148. format = "binary";
  149. sopsFile = ./secrets/ldap-sync.conf;
  150. };
  151. sops.secrets."ldap/upstream/list" = {
  152. format = "binary";
  153. sopsFile = ./secrets/ldap-upstream.list;
  154. owner = "openldap";
  155. };
  156. hpc.hostFile.aliases = [
  157. "ldap.${config.networking.domain}"
  158. ];
  159. }