Skip to content

Commit 977b320

Browse files
basvandijkqknight
authored andcommittedMay 5, 2017
wordpress: replace the dbPassword option with dbPasswordFile
We shouldn't force users to store passwords in the world-readable Nix store.
1 parent 8283cc8 commit 977b320

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed
 

‎nixos/modules/services/web-servers/apache-httpd/wordpress.nix

+28-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let
99
<?php
1010
define('DB_NAME', '${config.dbName}');
1111
define('DB_USER', '${config.dbUser}');
12-
define('DB_PASSWORD', '${config.dbPassword}');
12+
define('DB_PASSWORD', file_get_contents('${config.dbPasswordFile}'));
1313
define('DB_HOST', '${config.dbHost}');
1414
define('DB_CHARSET', 'utf8');
1515
$table_prefix = '${config.tablePrefix}';
@@ -137,9 +137,34 @@ in
137137
};
138138
dbPassword = mkOption {
139139
default = "wordpress";
140-
description = "The mysql password to the respective dbUser.";
140+
description = ''
141+
The mysql password to the respective dbUser.
142+
143+
Warning: this password is stored in the world-readable Nix store. It's
144+
recommended to use the $dbPasswordFile option since that gives you control over
145+
the security of the password. $dbPasswordFile also takes precedence over $dbPassword.
146+
'';
141147
example = "wordpress";
142148
};
149+
dbPasswordFile = mkOption {
150+
type = types.str;
151+
default = toString (pkgs.writeTextFile {
152+
name = "wordpress-dbpassword";
153+
text = config.dbPassword;
154+
});
155+
example = "/run/keys/wordpress-dbpassword";
156+
description = ''
157+
Path to a file that contains the mysql password to the respective dbUser.
158+
The file should be readable by the user: config.services.httpd.user.
159+
160+
$dbPasswordFile takes precedence over the $dbPassword option.
161+
162+
This defaults to a file in the world-readable Nix store that contains the value
163+
of the $dbPassword option. It's recommended to override this with a path not in
164+
the Nix store. Tip: use nixops key management:
165+
<link xlink:href='https://nixos.org/nixops/manual/#idm140737318306400'/>
166+
'';
167+
};
143168
tablePrefix = mkOption {
144169
default = "wp_";
145170
description = ''
@@ -251,7 +276,7 @@ in
251276
sleep 1
252277
done
253278
${pkgs.mysql}/bin/mysql -e 'CREATE DATABASE ${config.dbName};'
254-
${pkgs.mysql}/bin/mysql -e 'GRANT ALL ON ${config.dbName}.* TO ${config.dbUser}@localhost IDENTIFIED BY "${config.dbPassword}";'
279+
${pkgs.mysql}/bin/mysql -e "GRANT ALL ON ${config.dbName}.* TO ${config.dbUser}@localhost IDENTIFIED BY \"$(cat ${config.dbPasswordFile})\";"
255280
else
256281
echo "Good, no need to do anything database related."
257282
fi

0 commit comments

Comments
 (0)
Please sign in to comment.