From 50abe6fce134066851479a0df09a1db0a7219df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 2 Jan 2021 10:59:09 +0100 Subject: Use templated secrets to avoid having password in the store --- modules/private/websites/tools/cloud/default.nix | 2 +- modules/secrets.nix | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/private/websites/tools/cloud/default.nix b/modules/private/websites/tools/cloud/default.nix index da6ac2f..1a42296 100644 --- a/modules/private/websites/tools/cloud/default.nix +++ b/modules/private/websites/tools/cloud/default.nix @@ -84,7 +84,7 @@ in { include('${nextcloud}/version.php'); $CONFIG = array ( // FIXME: change this value when nextcloud starts getting slow - 'instanceid' => '${env.instance_id}1', + 'instanceid' => '${env.instance_id}', 'datadirectory' => '/var/lib/nextcloud/', 'passwordsalt' => '${env.password_salt}', 'debug' => false, diff --git a/modules/secrets.nix b/modules/secrets.nix index a149f02..ecc1ebc 100644 --- a/modules/secrets.nix +++ b/modules/secrets.nix @@ -25,11 +25,12 @@ location = config.secrets.location; keys = config.secrets.keys; empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done"; + fpath = v: "secrets/${v.dest}${lib.optionalString (v.isTemplated or true) ".gucci.tpl"}"; dumpKey = v: '' mkdir -p secrets/$(dirname ${v.dest}) - echo -n ${lib.strings.escapeShellArg v.text} > secrets/${v.dest} + echo -n ${lib.strings.escapeShellArg v.text} > ${fpath v} cat >> mods < $TMP/currentSecrets + if [ -f /run/keys/vars.yml ]; then + find $TMP -name "*.gucci.tpl" -exec \ + /bin/sh -c 'f="{}"; ${pkgs.gucci}/bin/gucci -f /run/keys/vars.yml "$f" > "''${f%.gucci.tpl}"; touch --reference "$f" ''${f%.gucci.tpl} ; chmod --reference="$f" ''${f%.gucci.tpl} ; chown --reference="$f" ''${f%.gucci.tpl}' \; + sha512sum /run/keys/secrets.tar /run/keys/vars.yml > $TMP/currentSecrets + else + sha512sum /run/keys/secrets.tar > $TMP/currentSecrets + fi find $TMP -type d -exec chown root:keys {} \; -exec chmod o-rx {} \; - ${pkgs.rsync}/bin/rsync -O -c -av --delete $TMP/ ${location} + ${pkgs.rsync}/bin/rsync --exclude="*.gucci.tpl" -O -c -av --delete $TMP/ ${location} rm -rf $TMP fi fi fi ''; }; + system.extraDependencies = [ secrets ]; + deployment.secrets."secret_vars.yml" = { + source = builtins.toString ; + destination = "/run/keys/vars.yml"; + owner.user = "root"; + owner.group = "root"; + permissions = "0400"; + }; deployment.secrets."secrets.tar" = { source = "${secrets}"; destination = "/run/keys/secrets.tar"; -- cgit v1.2.3