From 258060c37d1f4b973aa6293485ad3594a9e88233 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 20 Jul 2022 23:06:06 +0200 Subject: [PATCH] nixos/confluence: store crowd SSO password securely Basically the same as the JIRA change[1], but I figured that we can actually implement that in a backwards compatible manner. [1] https://github.com/NixOS/nixpkgs/pull/181715 --- .../web-apps/atlassian/confluence.nix | 57 ++++++++++++++----- pkgs/servers/atlassian/confluence.nix | 13 ++++- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/nixos/modules/services/web-apps/atlassian/confluence.nix b/nixos/modules/services/web-apps/atlassian/confluence.nix index 28491fb3a4ee..4aad307731ab 100644 --- a/nixos/modules/services/web-apps/atlassian/confluence.nix +++ b/nixos/modules/services/web-apps/atlassian/confluence.nix @@ -8,21 +8,22 @@ let pkg = cfg.package.override (optionalAttrs cfg.sso.enable { enableSSO = cfg.sso.enable; - crowdProperties = '' - application.name ${cfg.sso.applicationName} - application.password ${cfg.sso.applicationPassword} - application.login.url ${cfg.sso.crowd}/console/ - - crowd.server.url ${cfg.sso.crowd}/services/ - crowd.base.url ${cfg.sso.crowd}/ - - session.isauthenticated session.isauthenticated - session.tokenkey session.tokenkey - session.validationinterval ${toString cfg.sso.validationInterval} - session.lastvalidation session.lastvalidation - ''; }); + crowdProperties = pkgs.writeText "crowd.properties" '' + application.name ${cfg.sso.applicationName} + application.password ${if cfg.sso.applicationPassword != null then cfg.sso.applicationPassword else "@NIXOS_CONFLUENCE_CROWD_SSO_PWD@"} + application.login.url ${cfg.sso.crowd}/console/ + + crowd.server.url ${cfg.sso.crowd}/services/ + crowd.base.url ${cfg.sso.crowd}/ + + session.isauthenticated session.isauthenticated + session.tokenkey session.tokenkey + session.validationinterval ${toString cfg.sso.validationInterval} + session.lastvalidation session.lastvalidation + ''; + in { @@ -107,10 +108,17 @@ in }; applicationPassword = mkOption { - type = types.str; + type = types.nullOr types.str; + default = null; description = "Application password of this Confluence instance in Crowd"; }; + applicationPasswordFile = mkOption { + type = types.nullOr types.str; + default = null; + description = "Path to the application password for Crowd of Confluence."; + }; + validationInterval = mkOption { type = types.int; default = 2; @@ -147,6 +155,16 @@ in group = cfg.group; }; + assertions = [ + { assertion = cfg.sso.enable -> ((cfg.sso.applicationPassword == null) != (cfg.sso.applicationPasswordFile)); + message = "Please set either applicationPassword or applicationPasswordFile"; + } + ]; + + warnings = mkIf (cfg.sso.enable && cfg.sso.applicationPassword != null) [ + "Using `services.confluence.sso.applicationPassword` is deprecated! Use `applicationPasswordFile` instead!" + ]; + users.groups.${cfg.group} = {}; systemd.tmpfiles.rules = [ @@ -173,6 +191,7 @@ in CONF_USER = cfg.user; JAVA_HOME = "${cfg.jrePackage}"; CATALINA_OPTS = concatStringsSep " " cfg.catalinaOptions; + JAVA_OPTS = mkIf cfg.sso.enable "-Dcrowd.properties=${cfg.home}/crowd.properties"; }; preStart = '' @@ -183,6 +202,16 @@ in -e 's,protocol="org.apache.coyote.http11.Http11NioProtocol",protocol="org.apache.coyote.http11.Http11NioProtocol" proxyName="${cfg.proxy.name}" proxyPort="${toString cfg.proxy.port}" scheme="${cfg.proxy.scheme}",' \ '') + '' ${pkg}/conf/server.xml.dist > ${cfg.home}/server.xml + + ${optionalString cfg.sso.enable '' + install -m660 ${crowdProperties} ${cfg.home}/crowd.properties + ${optionalString (cfg.sso.applicationPasswordFile != null) '' + ${pkgs.replace-secret}/bin/replace-secret \ + '@NIXOS_CONFLUENCE_CROWD_SSO_PWD@' \ + ${cfg.sso.applicationPasswordFile} \ + ${cfg.home}/crowd.properties + ''} + ''} ''; serviceConfig = { diff --git a/pkgs/servers/atlassian/confluence.nix b/pkgs/servers/atlassian/confluence.nix index ed8447accf86..03d78aeeefe2 100644 --- a/pkgs/servers/atlassian/confluence.nix +++ b/pkgs/servers/atlassian/confluence.nix @@ -6,7 +6,14 @@ assert withMysql -> (mysql_jdbc != null); -stdenvNoCC.mkDerivation rec { +let + optionalWarning = cond: msg: + if cond then lib.warn msg + else lib.id; +in + +optionalWarning (crowdProperties != null) "Using `crowdProperties` is deprecated!" +(stdenvNoCC.mkDerivation rec { pname = "atlassian-confluence"; version = "7.18.1"; @@ -45,6 +52,6 @@ stdenvNoCC.mkDerivation rec { homepage = "https://www.atlassian.com/software/confluence"; sourceProvenance = with sourceTypes; [ binaryBytecode ]; license = licenses.unfree; - maintainers = with maintainers; [ fpletz globin willibutz ciil techknowlogick ]; + maintainers = with maintainers; [ fpletz globin willibutz ciil techknowlogick ma27 ]; }; -} +})