]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Move nextcloud passwords to secure location
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Apr 2019 13:32:34 +0000 (15:32 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Apr 2019 13:32:34 +0000 (15:32 +0200)
Related issue: https://git.immae.eu/mantisbt/view.php?id=122

nixops/modules/websites/tools/cloud/default.nix
nixops/modules/websites/tools/cloud/nextcloud.nix

index dc3dde2eae9309b4431bc77a8dc364f68795e24a..7dd37f5e52c9b144b18b0ae9fa42b993190e290a 100644 (file)
@@ -24,6 +24,7 @@ in {
       ];
     };
 
+    deployment.keys = nextcloud.keys;
     users.users.root.packages = let
       occ = pkgs.writeScriptBin "nextcloud-occ" ''
         #! ${pkgs.stdenv.shell}
index 59930fb0122587419fd92d6abfe9fa80e277e9a5..b339038b1496bfc766130f2b493bda7756aab117 100644 (file)
@@ -113,66 +113,62 @@ let
     };
   in rec {
     varDir = "/var/lib/nextcloud";
-    config_php = writeText "config.php" ''
-      <?php
-      $CONFIG = array (
-        // FIXME: change this value when nextcloud starts getting slow
-        'instanceid' => '${env.instance_id}1',
-        'datadirectory' => '/var/lib/nextcloud/',
-        'passwordsalt' => '${env.password_salt}',
-        'debug' => false,
-        'dbtype' => 'pgsql',
-        'version' => '15.0.0.10',
-        'dbname' => '${env.postgresql.database}',
-        'dbhost' => '${env.postgresql.socket}',
-        'dbtableprefix' => 'oc_',
-        'dbuser' => '${env.postgresql.user}',
-        'dbpassword' => '${env.postgresql.password}',
-        'installed' => true,
-        'maxZipInputSize' => 0,
-        'allowZipDownload' => true,
-        'forcessl' => true,
-        'theme' => ${"''"},
-        'maintenance' => false,
-        'trusted_domains' =>
-        array (
-          0 => 'cloud.immae.eu',
-        ),
-        'secret' => '${env.secret}',
-        'appstoreenabled' => false,
-        'appstore.experimental.enabled' => true,
-        'loglevel' => 2,
-        'trashbin_retention_obligation' => 'auto',
-        'htaccess.RewriteBase' => '/',
-        'mail_smtpmode' => 'sendmail',
-        'mail_smtphost' => '127.0.0.1',
-        'mail_smtpname' => ''',
-        'mail_smtppassword' => ''',
-        'mail_from_address' => 'nextcloud',
-        'mail_smtpauth' => false,
-        'mail_domain' => 'tools.immae.eu',
-        'memcache.local' => '\\OC\\Memcache\\APCu',
-        'memcache.locking' => '\\OC\\Memcache\\Redis',
-        'filelocking.enabled' => true,
-        'redis' =>
-        array (
-          'host' => '${env.redis.socket}',
-          'port' => 0,
-          'dbindex' => ${env.redis.db_index},
-        ),
-        'overwrite.cli.url' => 'https://cloud.immae.eu',
-        'ldapIgnoreNamingRules' => false,
-        'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
-      );
-      '';
-    config = stdenv.mkDerivation rec {
-      name = "nextcloud-config";
-      src = ./nextcloud-config;
-      phases = "installPhase";
-      installPhase = ''
-        mkdir -p $out
-        cp -r $src/* $out
-        cp ${config_php} $out/config.php
+    keys.tools-nextcloud = {
+      destDir = "/run/keys/webapps";
+      user = apache.user;
+      group = apache.group;
+      permissions = "0600";
+      text = ''
+        <?php
+        $CONFIG = array (
+          // FIXME: change this value when nextcloud starts getting slow
+          'instanceid' => '${env.instance_id}1',
+          'datadirectory' => '/var/lib/nextcloud/',
+          'passwordsalt' => '${env.password_salt}',
+          'debug' => false,
+          'dbtype' => 'pgsql',
+          'version' => '15.0.4.0',
+          'dbname' => '${env.postgresql.database}',
+          'dbhost' => '${env.postgresql.socket}',
+          'dbtableprefix' => 'oc_',
+          'dbuser' => '${env.postgresql.user}',
+          'dbpassword' => '${env.postgresql.password}',
+          'installed' => true,
+          'maxZipInputSize' => 0,
+          'allowZipDownload' => true,
+          'forcessl' => true,
+          'theme' => ${"''"},
+          'maintenance' => false,
+          'trusted_domains' => 
+          array (
+            0 => 'cloud.immae.eu',
+          ),
+          'secret' => '${env.secret}',
+          'appstoreenabled' => false,
+          'appstore.experimental.enabled' => true,
+          'loglevel' => 2,
+          'trashbin_retention_obligation' => 'auto',
+          'htaccess.RewriteBase' => '/',
+          'mail_smtpmode' => 'sendmail',
+          'mail_smtphost' => '127.0.0.1',
+          'mail_smtpname' => ''',
+          'mail_smtppassword' => ''',
+          'mail_from_address' => 'nextcloud',
+          'mail_smtpauth' => false,
+          'mail_domain' => 'tools.immae.eu',
+          'memcache.local' => '\\OC\\Memcache\\APCu',
+          'memcache.locking' => '\\OC\\Memcache\\Redis',
+          'filelocking.enabled' => true,
+          'redis' => 
+          array (
+            'host' => '${env.redis.socket}',
+            'port' => 0,
+            'dbindex' => ${env.redis.db_index},
+          ),
+          'overwrite.cli.url' => 'https://cloud.immae.eu',
+          'ldapIgnoreNamingRules' => false,
+          'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
+        );
       '';
     };
     webRoot = stdenv.mkDerivation rec {
@@ -207,11 +203,8 @@ let
       text = ''
         install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}
         install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
-        if [ ! -e ${varDir}/config ]; then
-          cp -a ${config} ${varDir}/config
-          chown -R ${apache.user}:${apache.group} ${varDir}/config
-          chmod -R u+w ${varDir}/config
-        fi
+        install -D -m 0644 -o ${apache.user} -g ${apache.group} ${./nextcloud-config}/* -t ${varDir}/config
+        install -D -m 0600 -o ${apache.user} -g ${apache.group} -T /run/keys/webapps/tools-nextcloud ${varDir}/config/config.php
       '';
     };
     apache = rec {
@@ -243,7 +236,7 @@ let
     };
     phpFpm = rec {
       basedir = builtins.concatStringsSep ":" (
-        [ webRoot varDir config ]
+        [ webRoot varDir ]
         ++ lib.attrsets.mapAttrsToList (name: value: value) apps);
       socket = "/var/run/phpfpm/nextcloud.sock";
       phpConfig = ''