From 9596e0e75c6a49083167ef6e2edca9cc448695e1 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Sat, 11 Feb 2023 19:14:07 -0600 Subject: env/users: implement mail client certificates --- env/users/default.nix | 21 +++++++++-- env/users/mailbox.nix | 96 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 105 insertions(+), 12 deletions(-) (limited to 'env') diff --git a/env/users/default.nix b/env/users/default.nix index 3602630..0e77e0d 100644 --- a/env/users/default.nix +++ b/env/users/default.nix @@ -8,7 +8,19 @@ in ./mailbox.nix ]; - options.local = with types; { + options.local = with types; let + mailOption = mkOption { + default = { }; + + type = submodule { + options.certs = mkOption { + type = listOf str; + default = [ ]; + }; + }; + }; + in + { sysadmin = mkOption { type = str; }; @@ -50,6 +62,8 @@ in type = listOf str; default = [ ]; }; + + mail = mailOption; }; config.groups = mkBefore (optional config.sysadmin "wheel"); @@ -83,8 +97,11 @@ in }; users = mkOption { - type = attrsOf (submodule { }); default = { }; + + type = attrsOf (submodule { + options.mail = mailOption; + }); }; }; diff --git a/env/users/mailbox.nix b/env/users/mailbox.nix index 9fe460e..8b2c4b2 100644 --- a/env/users/mailbox.nix +++ b/env/users/mailbox.nix @@ -56,19 +56,75 @@ in ${username}:::::::user=${canonical} nopassword userdb_user=${canonical} ''; - localEntries = concatStrings - (flatten (mapAttrsToList + localMailboxes = + pkgs.writeText "local-mailboxes" + (concatStrings + (flatten (mapAttrsToList + (canonical: user: + map (localEntry canonical) ([ canonical ] ++ user.hardAliases)) + cfg.users))); + + localCerts = + flatten (mapAttrsToList (canonical: user: - map (localEntry canonical) ([ canonical ] ++ user.hardAliases)) - cfg.users)); - - localMailboxes = pkgs.writeText "local-mailboxes" localEntries; + let + certNames = { + inherit canonical; + logins = [ canonical ] ++ user.hardAliases; + }; + in + map (flip nameValuePair certNames) user.mail.certs) + cfg.users); + + vmailCerts = + flatten (flatten (mapAttrsToList + (domain: virtual: mapAttrsToList + (username: user: + let + address = "${username}@${domain}"; + + certNames = { + canonical = address; + logins = [ address ]; + }; + in + map (flip nameValuePair certNames) user.mail.certs) + virtual.users) + cfg.virtual)); + + certLogins = + pkgs.writeText "cert-logins" + (concatStrings (flatten (mapAttrsToList + (uuid: names: map + (addr: '' + ${uuid}.mail-client@nodomain,${addr}:::::::user=${names.canonical} + '') + names.logins) + (listToAttrs (localCerts ++ vmailCerts))))); vmailPath = "/var/lib/vmail/%{if;%d;ne;;%Ld;${domain}}"; in '' auth_mechanisms = plain login external + #TODO: automatizar implantación de archivo de CA + + # Orden de concatenación de mail-fullchain-crl.crt: + # - Issuing CA cert + # - Issuing CA CRL + # - Intermediate CA cert + # - Intermediate CA CRL + # - Root CA cert + # - Root CA CRL + ssl_ca =