Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/mysql: add authentication option #68353

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion nixos/modules/services/databases/mysql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ in
Name of the user to ensure.
'';
};
authentication_option = mkOption {
type = types.str;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest a more specific type:

with types; enum ["socket" "password"]

default = "socket";
description = ''
Authentication option to use either socket or password. If password is used password_hash has to be set.
'';
};
password_hash = mkOption {
type = types.str;
default = "";
description = ''
Password hash to set for user, default is empty, which means no password.
'';
};
ensurePermissions = mkOption {
type = types.attrsOf types.str;
default = {};
Expand Down Expand Up @@ -406,7 +420,7 @@ in

${concatMapStrings (user:
''
( echo "CREATE USER IF NOT EXISTS '${user.name}'@'localhost' IDENTIFIED WITH ${if isMariaDB then "unix_socket" else "auth_socket"};"
( echo "CREATE USER IF NOT EXISTS '${user.name}'@'localhost' ${optionalString (user.authentication_option == "password") ''IDENTIFIED BY PASSWORD '${user.password_hash}' ''} ${optionalString (user.authentication_option == "socket") ''IDENTIFIED WITH ${if isMariaDB then "unix_socket" else "auth_socket"} ''};"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few issues:

  • line too long, should fit 100 columns
  • what happens when password is changed? As I understand it, user already exists so his password will silently remain the same. This is bad. Please do run ALTER USER to change password hash when it was changed in NixOS config
  • same for authentication_option

${concatStringsSep "\n" (mapAttrsToList (database: permission: ''
echo "GRANT ${permission} ON ${database} TO '${user.name}'@'localhost';"
'') user.ensurePermissions)}
Expand All @@ -423,3 +437,4 @@ in
};

}