From 43465c94d4d30c5c977b78ae12f4e1a47a3760ea Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 18 May 2023 13:45:29 +0000 Subject: nixos/mailman: randomly generate REST API token --- nixos/doc/manual/release-notes/rl-2305.section.md | 2 ++ nixos/modules/services/mail/mailman.nix | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'nixos') diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md index c5a29ed9f202b..5c9005674bb32 100644 --- a/nixos/doc/manual/release-notes/rl-2305.section.md +++ b/nixos/doc/manual/release-notes/rl-2305.section.md @@ -199,6 +199,8 @@ In addition to numerous new and upgraded packages, this release has the followin - The EC2 image module no longer fetches instance metadata in stage-1. This results in a significantly smaller initramfs, since network drivers no longer need to be included, and faster boots, since metadata fetching can happen in parallel with startup of other services. This breaks services which rely on metadata being present by the time stage-2 is entered. Anything which reads EC2 metadata from `/etc/ec2-metadata` should now have an `after` dependency on `fetch-ec2-metadata.service` +- The mailman service now defaults to using a randomly generated REST API password instead of a hardcoded one. + - `minio` removed support for its legacy filesystem backend in [RELEASE.2022-10-29T06-21-33Z](https://github.com/minio/minio/releases/tag/RELEASE.2022-10-29T06-21-33Z). This means if your storage was created with the old format, minio will no longer start. Unfortunately minio doesn't provide a an automatic migration, they only provide [instructions how to manually convert the node](https://min.io/docs/minio/windows/operations/install-deploy-manage/migrate-fs-gateway.html). To facilitate this migration we keep around the last version that still supports the old filesystem backend as `minio_legacy_fs`. Use it via `services.minio.package = minio_legacy_fs;` to export your data before switching to the new version. See the corresponding [issue](https://github.com/NixOS/nixpkgs/issues/199318) for more details. - `services.sourcehut.dispatch` and the corresponding package (`sourcehut.dispatchsrht`) have been removed due to [upstream deprecation](https://sourcehut.org/blog/2022-08-01-dispatch-deprecation-plans/). diff --git a/nixos/modules/services/mail/mailman.nix b/nixos/modules/services/mail/mailman.nix index 9273f71db7d56..ded30736440e2 100644 --- a/nixos/modules/services/mail/mailman.nix +++ b/nixos/modules/services/mail/mailman.nix @@ -44,11 +44,9 @@ let transport_file_type: hash ''; - mailmanCfg = lib.generators.toINI {} - (recursiveUpdate cfg.settings - ((optionalAttrs (cfg.restApiPassFile != null) { - webservice.admin_pass = "#NIXOS_MAILMAN_REST_API_PASS_SECRET#"; - }))); + mailmanCfg = lib.generators.toINI {} (recursiveUpdate cfg.settings { + webservice.admin_pass = "#NIXOS_MAILMAN_REST_API_PASS_SECRET#"; + }); mailmanCfgFile = pkgs.writeText "mailman-raw.cfg" mailmanCfg; @@ -388,6 +386,7 @@ in { environment.etc."mailman3/settings.py".text = '' import os + from configparser import ConfigParser # Required by mailman_web.settings, but will be overridden when # settings_local.json is loaded. @@ -404,10 +403,10 @@ in { with open('/var/lib/mailman-web/settings_local.json') as f: globals().update(json.load(f)) - ${optionalString (cfg.restApiPassFile != null) '' - with open('${cfg.restApiPassFile}') as f: - MAILMAN_REST_API_PASS = f.read().rstrip('\n') - ''} + with open('/etc/mailman.cfg') as f: + config = ConfigParser() + config.read_file(f) + MAILMAN_REST_API_PASS = config['webservice']['admin_pass'] ${optionalString (cfg.ldap.enable) '' import ldap @@ -507,7 +506,10 @@ in { serviceConfig.Type = "oneshot"; script = '' install -m0750 -o mailman -g mailman ${mailmanCfgFile} /etc/mailman.cfg - ${optionalString (cfg.restApiPassFile != null) '' + ${if cfg.restApiPassFile == null then '' + sed -i "s/#NIXOS_MAILMAN_REST_API_PASS_SECRET#/$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 64)/g" \ + /etc/mailman.cfg + '' else '' ${pkgs.replace-secret}/bin/replace-secret \ '#NIXOS_MAILMAN_REST_API_PASS_SECRET#' \ ${cfg.restApiPassFile} \ -- cgit 1.4.1