update
authorJulien Moutinho <julm@autogeree.net>
Mon, 17 Sep 2018 01:37:18 +0000 (03:37 +0200)
committerJulien Moutinho <julm@autogeree.net>
Mon, 17 Sep 2018 01:46:10 +0000 (03:46 +0200)
install/logical/friot.nix
install/logical/friot/dovecot.nix
install/logical/friot/nginx/gitweb.nix
install/logical/friot/nsd.nix
install/logical/friot/nsd/commonsoft.coop.nix
install/logical/friot/openldap.nix [new file with mode: 0644]
install/logical/friot/rmilter.nix
install/physical/virtualbox.nix

index fcb335b2ee37b1edef5dade5dfaab501fb5dcd26..2eb04b7028ef13da789dbca68e008f2b9004c127 100644 (file)
@@ -14,9 +14,16 @@ imports = [
   friot/postgrey.nix
   friot/rmilter.nix
   friot/shorewall.nix
+  friot/openldap.nix
+  #friot/discourse.nix
 ];
 options = {
   enable = lib.mkEnableOption "friot";
+  networking.baseName = lib.mkOption {
+    type        = types.str;
+    description = "Base network name.";
+    example     = "example";
+  };
   networking.zones = lib.mkOption {
     type = types.attrsOf (types.submodule ({zone, ...}: {
       options = {
@@ -41,7 +48,8 @@ options = {
 };
 config = {
   networking = {
-    domain = "commonsoft.coop";
+    baseName = "commonsoft";
+    domain   = "${config.networking.baseName}.coop";
   };
   users.mutableUsers = false;
   users.users = {
@@ -74,23 +82,12 @@ config = {
     openssh = {
       enable = true;
     };
-    openldap = {
-      enable = true;
-      #declarativeContents = ''
-      #    dn: dc=example,dc=org
-      #    objectClass: domain
-      #    dc: example
-      #
-      #    dn: ou=users,dc=example,dc=org
-      #    objectClass = organizationalUnit
-      #    ou: users
-      #
-      #    # ...
-      #'';
-    };
     gitea = {
       enable = false;
     };
+    sssd = {
+      enable = false;
+    };
     dovecot2 = {
       #debug = true;
     };
@@ -160,7 +157,12 @@ config = {
       inetutils
       cgit
       ncdu
-      #mailutils
+      mailutils
+      #sssd
+      docker
+      #nss_ldap
+      nss_pam_ldapd
+      socat
     ];
   };
 };
index fbbf085b196dc2e5b7f5dcaec5ac737fbcce666f..498a7461a728cf483984a93ebeb598e584169882 100644 (file)
@@ -35,14 +35,14 @@ config = {
                 <!-- <displayShortName></displayShortName> -->
                 <domain>%EMAILDOMAIN%</domain>
                 <incomingServer type="imap">
-                  <hostname>imap.%EMAILDOMAIN%</hostname>
+                  <hostname>mail.%EMAILDOMAIN%</hostname>
                   <port>993</port>
                   <socketType>SSL</socketType>
                   <username>%EMAILADDRESS%</username>
                   <authentication>password-cleartext</authentication>
                 </incomingServer>
                 <incomingServer type="pop3">
-                  <hostname>pop.%EMAILDOMAIN%</hostname>
+                  <hostname>mail.%EMAILDOMAIN%</hostname>
                   <port>995</port>
                   <socketType>SSL</socketType>
                   <username>%EMAILADDRESS%</username>
@@ -53,7 +53,7 @@ config = {
                   </pop3>
                 </incomingServer>
                 <outgoingServer type="smtp">
-                  <hostname>smtp.%EMAILDOMAIN%</hostname>
+                  <hostname>mail.%EMAILDOMAIN%</hostname>
                   <port>465</port>
                   <socketType>SSL</socketType> <!-- see above -->
                   <username>%EMAILADDRESS%</username> <!-- if smtp-auth -->
index c8eb85038d266c1ccca9a26b25ed99d0c50ef0ef..f7c4cb8a815902de0a2ba4cc6f477cc42ca4248c 100644 (file)
@@ -16,9 +16,6 @@ in
         #];
         #default = true;
         locations = {
-          "/static/" = {
-            alias = "${pkgs.gitweb}/static/";
-          };
           "/" = {
             extraConfig = ''
               include ${pkgs.nginx}/conf/fastcgi_params;
@@ -28,6 +25,9 @@ in
               fastcgi_pass unix:${gitwebSocket};
             '';
           };
+          "/static/" = {
+            alias = "${pkgs.gitweb}/static/";
+          };
         };
       };
     };
@@ -52,7 +52,9 @@ in
       projectroot = "${gitolite.dataDir}/repositories";
       extraConfig = ''
         use utf8;
-        $home_link_str = "repos";
+        my $s = $cgi->https() ? "s"  : "";
+        @extra_breadcrumbs = (["commonsoft" => "http''${s}://commonsoft.coop"]);
+        $home_link_str = "git";
         $projects_list = "${gitolite.dataDir}/projects.list";
         $projects_list_group_categories = 1;
         $default_projects_order = "age";
index 3d65628d3fb214df116106c835385799e0c17b5e..da7c671905f573308d259622ccec61f44058a4fc 100644 (file)
@@ -2,6 +2,9 @@
 let inherit (config.services) nsd;
 in
 {
+  imports = [
+    nsd/commonsoft.coop.nix
+  ];
   config = {
     services.nsd = {
       enable = true;
@@ -18,7 +21,6 @@ in
         config.networking.zones.lan.ipv4
         config.networking.zones.net.ipv4
       ];
-      zones = import nsd/commonsoft.coop.nix { inherit pkgs lib config; };
     };
   };
 }
index ebf57cbc2a0f6db2deca1c9a36bfb070610974a6..288919d11bc63e44615b302a3258ec242a1751c0 100644 (file)
@@ -18,45 +18,51 @@ let inherit (builtins) toString toPath readFile;
     domain = "commonsoft.coop";
 in
 {
-"${domain}" = {
-  data = ''
-    $ORIGIN ${domain}.
-    $TTL    86400
-    
-    ; SOA (Start Of Authority)
-    @ SOA ns admin (
-      ${serial domain} ; Serial number
-      1d      ; Refresh
-      15m     ; Retry
-      2592000 ; Expire
-      1d      ; TTL (Time To Live) minimum
-    )
-    
-    ; A (DNS -> IPv4)
-    @                   A ${ipv4}
-    autoconfig          A ${ipv4}
-    git                 A ${ipv4}
-    imap                A ${ipv4}
-    mail                A ${ipv4}
-    ns                  A ${ipv4}
-    pop                 A ${ipv4}
-    smtp                A ${ipv4}
-    submission          A ${ipv4}
-    www                 A ${ipv4}
-    
-    ; SPF (Sender Policy Framework)
-    @ 3600 IN SPF "v=spf1 mx ip4:${ipv4} -all"
-    @ 3600 IN TXT "v=spf1 mx ip4:${ipv4} -all"
-    
-    ; NS (Name Server)
-    @ NS ns
-    ;@ NS ns6.gandi.net.
-    
-    ; MX (Mail eXchange)
-    @ 180 MX 5 ${ipv4}
-    
-    ; SRV (SeRVice)
-    _git._tcp.git 18000 IN SRV 0 0 9418 git
-  '';
+  config = {
+    services.nsd = {
+      zones = {
+        "${domain}" = {
+          data = ''
+            $ORIGIN ${domain}.
+            $TTL    86400
+
+            ; SOA (Start Of Authority)
+            @ SOA ns admin (
+              ${serial domain} ; Serial number
+              1d      ; Refresh
+              15m     ; Retry
+              2592000 ; Expire
+              1d      ; TTL (Time To Live) minimum
+            )
+
+            ; A (DNS -> IPv4)
+            @                   A ${ipv4}
+            autoconfig          A ${ipv4}
+            git                 A ${ipv4}
+            imap                A ${ipv4}
+            mail                A ${ipv4}
+            ns                  A ${ipv4}
+            pop                 A ${ipv4}
+            smtp                A ${ipv4}
+            submission          A ${ipv4}
+            www                 A ${ipv4}
+
+            ; SPF (Sender Policy Framework)
+            @ 3600 IN SPF "v=spf1 mx ip4:${ipv4} -all"
+            @ 3600 IN TXT "v=spf1 mx ip4:${ipv4} -all"
+
+            ; NS (Name Server)
+            @ NS ns
+            ;@ NS ns6.gandi.net.
+
+            ; MX (Mail eXchange)
+            @ 180 MX 5 ${ipv4}
+
+            ; SRV (SeRVice)
+            _git._tcp.git 18000 IN SRV 0 0 9418 git
+          '';
+          };
+      };
+    };
   };
 }
diff --git a/install/logical/friot/openldap.nix b/install/logical/friot/openldap.nix
new file mode 100644 (file)
index 0000000..d4664ce
--- /dev/null
@@ -0,0 +1,216 @@
+{pkgs, lib, config, ...}:
+let inherit (config.services) openldap;
+    inherit (config.users) ldap;
+    cnConfigLDIF = pkgs.writeText "cn=config.ldif" ''
+      dn: cn=config
+      cn: config
+      objectClass: olcGlobal
+      #olcPidFile: /run/slapd/slapd.pid
+      # List of arguments that were passed to the server
+      #olcArgsFile: /run/slapd/slapd.args
+      # Read slapd-config(5) for possible values
+      olcLogLevel: none
+      # The tool-threads parameter sets the actual amount of cpu's that is used
+      # for indexing.
+      olcToolThreads: 1
+      
+      dn: olcDatabase={-1}frontend,cn=config
+      olcDatabase: {-1}frontend
+      objectClass: olcDatabaseConfig
+      objectClass: olcFrontendConfig
+      # The maximum number of entries that is returned for a search operation
+      olcSizeLimit: 500
+      # Allow unlimited access to local connection from the local root user
+      olcAccess: to *
+        by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage
+        by * break
+      # Allow unauthenticated read access for schema and base DN autodiscovery
+      olcAccess: to dn.exact=""
+        by * read
+      olcAccess: to dn.base="cn=Subschema"
+        by * read
+      
+      dn: olcDatabase=config,cn=config
+      olcDatabase: config
+      objectClass: olcDatabaseConfig
+      olcRootDN: cn=admin,cn=config
+      # Access to cn=config, system root can be manager
+      # with SASL mechanism (-Y EXTERNAL) over unix socket (-H ldapi://)
+      olcAccess: to *
+        by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
+        by * break
+      
+      dn: cn=schema,cn=config
+      cn: schema
+      objectClass: olcSchemaConfig
+      
+      include: file://${pkgs.openldap}/etc/schema/core.ldif
+      include: file://${pkgs.openldap}/etc/schema/cosine.ldif
+      include: file://${pkgs.openldap}/etc/schema/nis.ldif
+      include: file://${pkgs.openldap}/etc/schema/inetorgperson.ldif
+      
+      dn: cn=module{0},cn=config
+      cn: module{0}
+      objectClass: olcModuleList
+      # Where the dynamically loaded modules are stored
+      #olcModulePath: /usr/lib/ldap
+      olcModuleLoad: back_mdb
+      
+      dn: olcBackend={1}mdb,cn=config
+      olcBackend: {1}mdb
+      objectClass: olcBackendConfig
+
+      include: file://${mdb1Config}
+    '';
+    mdb1Suffix = "dc=${config.networking.baseName}";
+    mdb1Config = pkgs.writeText "${mdb1Suffix}.config.ldif" ''
+      # sudo ldapsearch -LLL -D cn=admin,cn=config -Y EXTERNAL -b 'olcDatabase={1}mdb,cn=config' -s sub
+      dn: olcDatabase={1}mdb,cn=config
+      olcDatabase: {1}mdb
+      objectClass: olcDatabaseConfig
+      objectClass: olcMdbConfig
+      # Checkpoint the database periodically in case of system
+      # failure and to speed slapd shutdown.
+      olcDbCheckpoint: 512 30
+      # Database max size is 1G
+      olcDbMaxSize: 1073741824
+      olcLastMod: TRUE
+      olcSuffix: ${mdb1Suffix}
+      olcDbDirectory: ${openldap.dataDir}
+      # Database superuser. Needed for syncrepl.
+      olcRootDN: cn=admin,${mdb1Suffix}
+      # superuser password, generated with slappasswd -s SECRET
+      # olcRootPW: {SSHA}VUlLVeNl3IKltfX50f/PokMRnlhRsSDI
+      olcDbIndex: objectClass eq
+      olcDbIndex: cn,uid eq
+      olcDbIndex: uidNumber,gidNumber eq
+      olcDbIndex: member,memberUid eq
+      olcAccess: to attrs=userPassword
+        by self write
+        by anonymous auth
+        by * none
+      olcAccess: to attrs=shadowLastChange
+        by self write
+        by * none
+      olcAccess: to dn.sub="ou=posix,${mdb1Suffix}"
+        by dn="gidNumber=${toString config.users.groups.nslcd.gid}+uidNumber=${toString config.users.users.nslcd.uid},cn=peercred,cn=external,cn=auth" manage
+      olcAccess: to *
+        by self read
+        by * none
+    '';
+    mdb1LDIF = pkgs.writeText "${mdb1Suffix}.ldif" ''
+      dn: ${mdb1Suffix}
+      dc: ${config.networking.baseName}
+      objectClass: top
+      objectClass: dcObject
+      objectClass: organization
+      o: Commonsoft
+      
+      dn: cn=admin,${mdb1Suffix}
+      cn: admin
+      objectClass: simpleSecurityObject
+      objectClass: organizationalRole
+      description: ${config.networking.baseName} LDAP administrator
+      roleOccupant: ${mdb1Suffix}
+      userPassword:
+      
+      dn: ou=posix,${mdb1Suffix}
+      ou: posix
+      objectClass: top
+      objectClass: organizationalUnit
+      
+      dn: ou=accounts,ou=posix,${mdb1Suffix}
+      ou: accounts
+      objectClass: top
+      objectClass: organizationalUnit
+      
+      dn: ou=groups,ou=posix,${mdb1Suffix}
+      ou: groups
+      objectClass: top
+      objectClass: organizationalUnit
+      
+      dn: cn=users,ou=groups,ou=posix,${mdb1Suffix}
+      cn: users
+      objectclass: top
+      objectclass: posixGroup
+      gidnumber: 10000
+      memberuid: julm
+      memberuid: sevy
+      
+      dn: uid=julm,ou=accounts,ou=posix,${mdb1Suffix}
+      uid: julm
+      objectClass: account
+      objectClass: posixAccount
+      cn: Julien M.
+      uidNumber: 10000
+      gidNumber: 10000
+      homeDirectory: /home/julm
+      loginShell: /run/current-system/sw/bin/bash
+      userPassword: {SSHA}144Rfau9KJ14U0U4KdLNB7OrtpiEc3E3
+      
+      dn: uid=sevy,ou=accounts,ou=posix,${mdb1Suffix}
+      uid: sevy
+      objectClass: account
+      objectClass: posixAccount
+      cn: Séverine P.
+      uidNumber: 10001
+      gidNumber: 10000
+      homeDirectory: /home/sevy
+      loginShell: /run/current-system/sw/bin/bash
+      userPassword: {SSHA}dwqaKo5nmId8Bym5PghloK+UEndwrVTN
+    '';
+in
+{
+  config = {
+    users.ldap = {
+      enable = true;
+      # FIXME: even with the correct LD_LIBRARY_PATH to libnss_ldap.so,
+      #        passwd still does not work on LDAP accounts.
+      daemon = {
+        enable = true;
+        extraConfig = ''
+          sasl_mech EXTERNAL
+        '';
+      };
+      server = "ldapi:///";
+      base = "ou=posix,${mdb1Suffix}";
+      bind = {
+        #distinguishedName = "cn=admin,${mdb1Suffix}";
+      };
+    };
+    services.openldap = {
+      enable    = true;
+      dataDir   = "/var/db/ldap";
+      configDir = "/var/db/slapd";
+      urlList   = [ "ldapi:///" ]; # UNIX socket
+    };
+    systemd.services.openldap = {
+      preStart = ''
+        # NOTE: the config is always re-initialized.
+        rm -rf "${openldap.configDir}"/cn=config \
+               "${openldap.configDir}"/cn=config.ldif
+        umask 0077
+        install -D -d -m 0700 \
+         -o "${openldap.user}" \
+         -g "${openldap.group}" \
+         "${openldap.dataDir}" \
+         "${openldap.configDir}"
+        
+        # NOTE: slapd is stopped in preStart, slap* commands can therefore be used.
+        ${pkgs.openldap}/bin/slapadd -n 0 -F "${openldap.configDir}" -l ${cnConfigLDIF}
+        # NOTE: slapadd(8): To populate the config database slapd-config(5),
+        #                   use -n 0 as it is always the first database.
+        #                   It must physically exist on the filesystem prior to this, however.
+        
+        # NOTE: the data are only initialized, never re-initialized.
+        if test ! -e "${openldap.dataDir}"/data.mdb
+         then
+          ${pkgs.openldap}/bin/slapadd -F "${openldap.configDir}" -l ${mdb1LDIF}
+         fi
+        chown -R "${openldap.user}:${openldap.group}" \
+         "${openldap.dataDir}" \
+         "${openldap.configDir}"
+      '';
+    };
+  };
+}
index 6cef2e8b72707c829546882b933120c2efe8f4dc..7fc52a35c5f5c23578a686f1307c79b57308c2a1 100644 (file)
@@ -25,7 +25,7 @@ options.services.dkim = lib.mkOption {
     options = {
       keyDir = lib.mkOption {
         type        = types.path;
-        default     = "/var/dkim";
+        default     = "/var/lib/dkim";
         description = ''
         '';
       };
@@ -70,9 +70,11 @@ config = {
         auth_only = yes;
       };
     '';
-    bindSocket.type = "inet";
+    bindSocket.type = "unix";
+    bindSocket.path = "/run/rmilter.sock";
+      # NOTE: fix default which is in wiped out directory /run/rmilter/rmilter.sock
   };
-  #systemd.sockets.rmilter.socketConfig.Accept = true;
+  #systemd.sockets.rmilter.socketConfig.Accept = false;
   systemd.services.rmilter = {
     requires = [ "rmilter.socket" ];
     after    = [ "rmilter.socket" ];
index bcec974f39335b5814d80ea6b048bcc32259585e..a3a117a8b245a2503c853484997841c6305abd39 100644 (file)
@@ -46,3 +46,14 @@ in
   };
 };
 }
+
+#{
+#  vbox =
+#    { deployment.targetEnv = "virtualbox"; };
+#
+#  machine =
+#    { resources, ... }:
+#    { deployment.targetEnv = "container";
+#      deployment.container.host = resources.machines.vbox;
+#    };
+#}