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.

177 lines
4.8 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 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. olcAccess = [
  71. # Custom access rules for userPassword attributes
  72. ''{0}to attrs=userPassword
  73. by self read
  74. by anonymous auth
  75. by * none
  76. ''
  77. # Synced is managed by sync
  78. ''{1}to dn.subtree="ou=synced,ou=users,dc=hpc,dc=informatik,dc=hs-fulda,dc=de"
  79. by dn.base="cn=sync,dc=hpc,dc=informatik,dc=hs-fulda,dc=de" manage
  80. by * break
  81. ''
  82. # Allow login to read users
  83. ''{2}to dn.subtree="ou=users,dc=hpc,dc=informatik,dc=hs-fulda,dc=de"
  84. by dn.base="cn=login,dc=hpc,dc=informatik,dc=hs-fulda,dc=de" read
  85. by self read
  86. by * break
  87. ''
  88. # Prevent access
  89. ''{3}to *
  90. by * none
  91. ''
  92. ];
  93. };
  94. children = {
  95. "olcOverlay={0}remoteauth" = {
  96. attrs = {
  97. objectClass = [ "olcOverlayConfig" "olcRemoteAuthCfg" ];
  98. olcOverlay = "{0}remoteauth";
  99. olcRemoteAuthTLS = "starttls=yes tls_cacert=\"/etc/ssl/certs/ca-certificates.crt\"";
  100. olcRemoteAuthDNAttribute = "seeAlso";
  101. olcRemoteAuthDomainAttribute = "associatedDomain";
  102. olcRemoteAuthDefaultDomain = "upstream";
  103. olcRemoteAuthDefaultRealm = "file://${config.sops.secrets."ldap/upstream/list".path}";
  104. olcRemoteAuthRetryCount = "3";
  105. olcRemoteAuthStore = "false";
  106. };
  107. };
  108. };
  109. };
  110. };
  111. };
  112. };
  113. systemd.services.openldap = {
  114. environment = {
  115. SASL_PATH = pkgs.writeTextFile {
  116. name = "openldap-sasl-path";
  117. destination = "/slapd.conf";
  118. text = ''
  119. pwcheck_method: saslauthd
  120. saslauthd_path: /var/run/saslauthd/mux
  121. mech_list: GSSAPI EXTERNAL PLAIN NTLM
  122. '';
  123. };
  124. };
  125. };
  126. systemd.services."ldap-sync" = {
  127. script = "${ldap-sync}/bin/ldap-sync";
  128. startAt = "hourly";
  129. };
  130. networking.firewall.allowedTCPPorts = [
  131. 389
  132. 636
  133. ];
  134. sops.secrets."ldap/root/password" = {
  135. owner = "openldap";
  136. };
  137. sops.secrets."ldap/sync/config" = {
  138. format = "binary";
  139. sopsFile = ./secrets/ldap-sync.conf;
  140. };
  141. sops.secrets."ldap/upstream/list" = {
  142. format = "binary";
  143. sopsFile = ./secrets/ldap-upstream.list;
  144. owner = "openldap";
  145. };
  146. hpc.hostFile.aliases = [
  147. "ldap.${config.networking.domain}"
  148. ];
  149. }