nixos/mongodb: replace option initialRootPassword with initialRootPasswordFile

Niklas Korz 2f8af3ea 3f8a2242

Changed files
+18 -7
nixos
doc
manual
release-notes
modules
services
databases
+2
nixos/doc/manual/release-notes/rl-2505.section.md
···
- `racket_7_9` has been removed, as it is insecure. It is recommended to use Racket 8 instead.
+
- `services.mongodb.initialRootPassword` has been replaced with the more secure option [`services.mongodb.initialRootPasswordFile`](#opt-services.mongodb.initialRootPasswordFile)
+
- `rofi` has been updated from 1.7.5 to 1.7.6 which introduces some breaking changes to binary plugins, and also contains a lot of new features and bug fixes. This is highlighted because the patch version bump does not indicate the volume of changes by itself. See the [upstream release notes](https://github.com/davatorium/rofi/releases/tag/1.7.6) for the full list of changes.
- `ente-auth` now uses the name `enteauth` for its binary. The previous name was `ente_auth`.
+16 -7
nixos/modules/services/databases/mongodb.nix
···
in
{
+
imports = [
+
(lib.mkRemovedOptionModule [
+
"services"
+
"mongodb"
+
"initialRootPassword"
+
] "Use services.mongodb.initialRootPasswordFile to securely provide the initial root password.")
+
];
###### interface
···
description = "Enable client authentication. Creates a default superuser with username root!";
};
-
initialRootPassword = lib.mkOption {
-
type = lib.types.nullOr lib.types.str;
+
initialRootPasswordFile = lib.mkOption {
+
type = lib.types.nullOr lib.types.path;
default = null;
-
description = "Password for the root user if auth is enabled.";
+
description = "Path to the file containing the password for the root user if auth is enabled.";
};
dbpath = lib.mkOption {
···
config = lib.mkIf config.services.mongodb.enable {
assertions = [
{
-
assertion = !cfg.enableAuth || cfg.initialRootPassword != null;
-
message = "`enableAuth` requires `initialRootPassword` to be set.";
+
assertion = !cfg.enableAuth || cfg.initialRootPasswordFile != null;
+
message = "`enableAuth` requires `initialRootPasswordFile` to be set.";
}
];
···
# wait for mongodb
while ! ${mongoshExe} --eval "db.version()" > /dev/null 2>&1; do sleep 0.1; done
+
initialRootPassword=$(<${cfg.initialRootPasswordFile})
${mongoshExe} <<EOF
use admin;
db.createUser(
{
user: "root",
-
pwd: "${cfg.initialRootPassword}",
+
pwd: "$initialRootPassword",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "dbAdminAnyDatabase", db: "admin" },
···
postStart = ''
if test -e "${cfg.dbpath}/.first_startup"; then
${lib.optionalString (cfg.initialScript != null) ''
-
${mongoshExe} ${lib.optionalString (cfg.enableAuth) "-u root -p ${cfg.initialRootPassword}"} admin "${cfg.initialScript}"
+
initialRootPassword=$(<${cfg.initialRootPasswordFile})
+
${mongoshExe} ${lib.optionalString (cfg.enableAuth) "-u root -p $initialRootPassword"} admin "${cfg.initialScript}"
''}
rm -f "${cfg.dbpath}/.first_startup"
fi