2022-07-29 15:23:44 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.users.mysql;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
users.mysql = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Authentication against a MySQL/MariaDB database");
|
2022-07-29 15:23:44 +00:00
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "localhost";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The hostname of the MySQL/MariaDB server";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
database = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "auth";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The name of the database containing the users";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "nss-user";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The username to use when connecting to the database";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
example = "/run/secrets/mysql-auth-db-passwd";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The path to the file containing the password for the user";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
pam = mkOption {
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "Settings for `pam_mysql`";
|
2022-07-29 15:23:44 +00:00
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
table = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "users";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The name of table that maps unique login names to the passwords.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
updateTable = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "users_updates";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the table used for password alteration. If not defined, the value
|
2022-08-28 19:18:44 +00:00
|
|
|
of the `table` option will be used instead.
|
2022-07-29 15:23:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
userColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "username";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The name of the column that contains a unix login name.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
passwordColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "password";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The name of the column that contains a (encrypted) password string.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
statusColumn = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "status";
|
2022-08-29 21:34:22 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column or an SQL expression that indicates the status of
|
|
|
|
the user. The status is expressed by the combination of two bitfields
|
|
|
|
shown below:
|
|
|
|
|
2022-08-29 21:34:22 +00:00
|
|
|
- `bit 0 (0x01)`:
|
|
|
|
if flagged, `pam_mysql` deems the account to be expired and
|
|
|
|
returns `PAM_ACCT_EXPIRED`. That is, the account is supposed
|
|
|
|
to no longer be available. Note this doesn't mean that `pam_mysql`
|
|
|
|
rejects further authentication operations.
|
|
|
|
- `bit 1 (0x02)`:
|
|
|
|
if flagged, `pam_mysql` deems the authentication token
|
|
|
|
(password) to be expired and returns `PAM_NEW_AUTHTOK_REQD`.
|
|
|
|
This ends up requiring that the user enter a new password.
|
2022-07-29 15:23:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
passwordCrypt = mkOption {
|
|
|
|
example = "2";
|
|
|
|
type = types.enum [
|
|
|
|
"0" "plain"
|
|
|
|
"1" "Y"
|
|
|
|
"2" "mysql"
|
|
|
|
"3" "md5"
|
|
|
|
"4" "sha1"
|
|
|
|
"5" "drupal7"
|
|
|
|
"6" "joomla15"
|
|
|
|
"7" "ssha"
|
|
|
|
"8" "sha512"
|
|
|
|
"9" "sha256"
|
|
|
|
];
|
2022-08-29 21:34:22 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The method to encrypt the user's password:
|
|
|
|
|
2022-08-29 21:34:22 +00:00
|
|
|
- `0` (or `"plain"`):
|
|
|
|
No encryption. Passwords are stored in plaintext. HIGHLY DISCOURAGED.
|
|
|
|
- `1` (or `"Y"`):
|
|
|
|
Use crypt(3) function.
|
|
|
|
- `2` (or `"mysql"`):
|
|
|
|
Use the MySQL PASSWORD() function. It is possible that the encryption function used
|
|
|
|
by `pam_mysql` is different from that of the MySQL server, as
|
|
|
|
`pam_mysql` uses the function defined in MySQL's C-client API
|
|
|
|
instead of using PASSWORD() SQL function in the query.
|
|
|
|
- `3` (or `"md5"`):
|
|
|
|
Use plain hex MD5.
|
|
|
|
- `4` (or `"sha1"`):
|
|
|
|
Use plain hex SHA1.
|
|
|
|
- `5` (or `"drupal7"`):
|
|
|
|
Use Drupal7 salted passwords.
|
|
|
|
- `6` (or `"joomla15"`):
|
|
|
|
Use Joomla15 salted passwords.
|
|
|
|
- `7` (or `"ssha"`):
|
|
|
|
Use ssha hashed passwords.
|
|
|
|
- `8` (or `"sha512"`):
|
|
|
|
Use sha512 hashed passwords.
|
|
|
|
- `9` (or `"sha256"`):
|
|
|
|
Use sha256 hashed passwords.
|
2022-07-29 15:23:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
cryptDefault = mkOption {
|
|
|
|
type = types.nullOr (types.enum [ "md5" "sha256" "sha512" "blowfish" ]);
|
|
|
|
default = null;
|
|
|
|
example = "blowfish";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The default encryption method to use for `passwordCrypt = 1`.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
where = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "host.name='web' AND user.active=1";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "Additional criteria for the query.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
verbose = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
If enabled, produces logs with detailed messages that describes what
|
2022-08-28 19:18:44 +00:00
|
|
|
`pam_mysql` is doing. May be useful for debugging.
|
2022-07-29 15:23:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
disconnectEveryOperation = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
By default, `pam_mysql` keeps the connection to the MySQL
|
2022-07-29 15:23:44 +00:00
|
|
|
database until the session is closed. If this option is set to true it
|
|
|
|
disconnects every time the PAM operation has finished. This option may
|
|
|
|
be useful in case the session lasts quite long.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
logging = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "Enables logging of authentication attempts in the MySQL database.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
table = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "logs";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc "The name of the table to which logs are written.";
|
2022-07-29 15:23:44 +00:00
|
|
|
};
|
|
|
|
msgColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "msg";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column in the log table to which the description
|
|
|
|
of the performed operation is stored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
userColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "user";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column in the log table to which the name of the
|
|
|
|
user being authenticated is stored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
pidColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "pid";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column in the log table to which the pid of the
|
2023-01-21 10:06:46 +00:00
|
|
|
process utilising the `pam_mysql` authentication
|
2022-07-29 15:23:44 +00:00
|
|
|
service is stored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
hostColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "host";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column in the log table to which the name of the user
|
|
|
|
being authenticated is stored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
rHostColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "rhost";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column in the log table to which the name of the remote
|
|
|
|
host that initiates the session is stored. The value is supposed to be
|
2022-08-28 19:18:44 +00:00
|
|
|
set by the PAM-aware application with `pam_set_item(PAM_RHOST)`.
|
2022-07-29 15:23:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
timeColumn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "timestamp";
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-29 15:23:44 +00:00
|
|
|
The name of the column in the log table to which the timestamp of the
|
|
|
|
log entry is stored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
nss = mkOption {
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Settings for `libnss-mysql`.
|
2022-07-29 15:23:44 +00:00
|
|
|
|
2022-08-28 19:18:44 +00:00
|
|
|
All examples are from the [minimal example](https://github.com/saknopper/libnss-mysql/tree/master/sample/minimal)
|
|
|
|
of `libnss-mysql`, but they are modified with NixOS paths for bash.
|
2022-07-29 15:23:44 +00:00
|
|
|
'';
|
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
getpwnam = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT username,'x',uid,'5000','MySQL User', CONCAT('/home/',username),'/run/sw/current-system/bin/bash' \
|
|
|
|
FROM users \
|
|
|
|
WHERE username='%1$s' \
|
|
|
|
LIMIT 1
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getpwnam](https://man7.org/linux/man-pages/man3/getpwnam.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getpwuid = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT username,'x',uid,'5000','MySQL User', CONCAT('/home/',username),'/run/sw/current-system/bin/bash' \
|
|
|
|
FROM users \
|
|
|
|
WHERE uid='%1$u' \
|
|
|
|
LIMIT 1
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getpwuid](https://man7.org/linux/man-pages/man3/getpwuid.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getspnam = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT username,password,'1','0','99999','0','0','-1','0' \
|
|
|
|
FROM users \
|
|
|
|
WHERE username='%1$s' \
|
|
|
|
LIMIT 1
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getspnam](https://man7.org/linux/man-pages/man3/getspnam.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getpwent = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT username,'x',uid,'5000','MySQL User', CONCAT('/home/',username),'/run/sw/current-system/bin/bash' FROM users
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getpwent](https://man7.org/linux/man-pages/man3/getpwent.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getspent = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT username,password,'1','0','99999','0','0','-1','0' FROM users
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getspent](https://man7.org/linux/man-pages/man3/getspent.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getgrnam = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT name,password,gid FROM groups WHERE name='%1$s' LIMIT 1
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getgrnam](https://man7.org/linux/man-pages/man3/getgrnam.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getgrgid = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT name,password,gid FROM groups WHERE gid='%1$u' LIMIT 1
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getgrgid](https://man7.org/linux/man-pages/man3/getgrgid.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
getgrent = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT name,password,gid FROM groups
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [getgrent](https://man7.org/linux/man-pages/man3/getgrent.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
memsbygid = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT username FROM grouplist WHERE gid='%1$u'
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [memsbygid](https://man7.org/linux/man-pages/man3/memsbygid.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
gidsbymem = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression ''
|
|
|
|
SELECT gid FROM grouplist WHERE username='%1$s'
|
|
|
|
'';
|
2022-08-28 19:18:44 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
SQL query for the [gidsbymem](https://man7.org/linux/man-pages/man3/gidsbymem.3.html)
|
2022-07-29 15:23:44 +00:00
|
|
|
syscall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
system.nssModules = [ pkgs.libnss-mysql ];
|
|
|
|
system.nssDatabases.shadow = [ "mysql" ];
|
|
|
|
system.nssDatabases.group = [ "mysql" ];
|
|
|
|
system.nssDatabases.passwd = [ "mysql" ];
|
|
|
|
|
|
|
|
environment.etc."security/pam_mysql.conf" = {
|
|
|
|
user = "root";
|
|
|
|
group = "root";
|
|
|
|
mode = "0600";
|
|
|
|
# password will be added from password file in activation script
|
|
|
|
text = ''
|
|
|
|
users.host=${cfg.host}
|
|
|
|
users.db_user=${cfg.user}
|
|
|
|
users.database=${cfg.database}
|
|
|
|
users.table=${cfg.pam.table}
|
|
|
|
users.user_column=${cfg.pam.userColumn}
|
|
|
|
users.password_column=${cfg.pam.passwordColumn}
|
|
|
|
users.password_crypt=${cfg.pam.passwordCrypt}
|
|
|
|
users.disconnect_every_operation=${if cfg.pam.disconnectEveryOperation then "1" else "0"}
|
|
|
|
verbose=${if cfg.pam.verbose then "1" else "0"}
|
|
|
|
'' + optionalString (cfg.pam.cryptDefault != null) ''
|
|
|
|
users.use_${cfg.pam.cryptDefault}=1
|
|
|
|
'' + optionalString (cfg.pam.where != null) ''
|
|
|
|
users.where_clause=${cfg.pam.where}
|
|
|
|
'' + optionalString (cfg.pam.statusColumn != null) ''
|
|
|
|
users.status_column=${cfg.pam.statusColumn}
|
|
|
|
'' + optionalString (cfg.pam.updateTable != null) ''
|
|
|
|
users.update_table=${cfg.pam.updateTable}
|
|
|
|
'' + optionalString cfg.pam.logging.enable ''
|
|
|
|
log.enabled=true
|
|
|
|
log.table=${cfg.pam.logging.table}
|
|
|
|
log.message_column=${cfg.pam.logging.msgColumn}
|
|
|
|
log.pid_column=${cfg.pam.logging.pidColumn}
|
|
|
|
log.user_column=${cfg.pam.logging.userColumn}
|
|
|
|
log.host_column=${cfg.pam.logging.hostColumn}
|
|
|
|
log.rhost_column=${cfg.pam.logging.rHostColumn}
|
|
|
|
log.time_column=${cfg.pam.logging.timeColumn}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."libnss-mysql.cfg" = {
|
|
|
|
mode = "0600";
|
|
|
|
user = config.services.nscd.user;
|
|
|
|
group = config.services.nscd.group;
|
|
|
|
text = optionalString (cfg.nss.getpwnam != null) ''
|
|
|
|
getpwnam ${cfg.nss.getpwnam}
|
|
|
|
'' + optionalString (cfg.nss.getpwuid != null) ''
|
|
|
|
getpwuid ${cfg.nss.getpwuid}
|
|
|
|
'' + optionalString (cfg.nss.getspnam != null) ''
|
|
|
|
getspnam ${cfg.nss.getspnam}
|
|
|
|
'' + optionalString (cfg.nss.getpwent != null) ''
|
|
|
|
getpwent ${cfg.nss.getpwent}
|
|
|
|
'' + optionalString (cfg.nss.getspent != null) ''
|
|
|
|
getspent ${cfg.nss.getspent}
|
|
|
|
'' + optionalString (cfg.nss.getgrnam != null) ''
|
|
|
|
getgrnam ${cfg.nss.getgrnam}
|
|
|
|
'' + optionalString (cfg.nss.getgrgid != null) ''
|
|
|
|
getgrgid ${cfg.nss.getgrgid}
|
|
|
|
'' + optionalString (cfg.nss.getgrent != null) ''
|
|
|
|
getgrent ${cfg.nss.getgrent}
|
|
|
|
'' + optionalString (cfg.nss.memsbygid != null) ''
|
|
|
|
memsbygid ${cfg.nss.memsbygid}
|
|
|
|
'' + optionalString (cfg.nss.gidsbymem != null) ''
|
|
|
|
gidsbymem ${cfg.nss.gidsbymem}
|
|
|
|
'' + ''
|
|
|
|
host ${cfg.host}
|
|
|
|
database ${cfg.database}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."libnss-mysql-root.cfg" = {
|
|
|
|
mode = "0600";
|
|
|
|
user = config.services.nscd.user;
|
|
|
|
group = config.services.nscd.group;
|
|
|
|
# password will be added from password file in activation script
|
|
|
|
text = ''
|
|
|
|
username ${cfg.user}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# Activation script to append the password from the password file
|
|
|
|
# to the configuration files. It also fixes the owner of the
|
|
|
|
# libnss-mysql-root.cfg because it is changed to root after the
|
|
|
|
# password is appended.
|
|
|
|
system.activationScripts.mysql-auth-passwords = ''
|
|
|
|
if [[ -r ${cfg.passwordFile} ]]; then
|
|
|
|
org_umask=$(umask)
|
|
|
|
umask 0077
|
|
|
|
|
|
|
|
conf_nss="$(mktemp)"
|
|
|
|
cp /etc/libnss-mysql-root.cfg $conf_nss
|
|
|
|
printf 'password %s\n' "$(cat ${cfg.passwordFile})" >> $conf_nss
|
|
|
|
mv -fT "$conf_nss" /etc/libnss-mysql-root.cfg
|
|
|
|
chown ${config.services.nscd.user}:${config.services.nscd.group} /etc/libnss-mysql-root.cfg
|
|
|
|
|
|
|
|
conf_pam="$(mktemp)"
|
|
|
|
cp /etc/security/pam_mysql.conf $conf_pam
|
|
|
|
printf 'users.db_passwd=%s\n' "$(cat ${cfg.passwordFile})" >> $conf_pam
|
|
|
|
mv -fT "$conf_pam" /etc/security/pam_mysql.conf
|
|
|
|
|
|
|
|
umask $org_umask
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|