2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.sssd;
|
|
|
|
nscd = config.services.nscd;
|
2022-08-21 13:32:41 +00:00
|
|
|
|
|
|
|
dataDir = "/var/lib/sssd";
|
|
|
|
settingsFile = "${dataDir}/sssd.conf";
|
|
|
|
settingsFileUnsubstituted = pkgs.writeText "${dataDir}/sssd-unsubstituted.conf" cfg.config;
|
2020-04-24 23:36:52 +00:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.sssd = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "the System Security Services Daemon";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Contents of {file}`sssd.conf`.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = ''
|
|
|
|
[sssd]
|
|
|
|
config_file_version = 2
|
|
|
|
services = nss, pam
|
|
|
|
domains = shadowutils
|
|
|
|
|
|
|
|
[nss]
|
|
|
|
|
|
|
|
[pam]
|
|
|
|
|
|
|
|
[domain/shadowutils]
|
|
|
|
id_provider = proxy
|
|
|
|
proxy_lib_name = files
|
|
|
|
auth_provider = proxy
|
|
|
|
proxy_pam_target = sssd-shadowutils
|
|
|
|
proxy_fast_alias = True
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sshAuthorizedKeysIntegration = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to make sshd look up authorized keys from SSS.
|
2022-08-12 12:06:08 +00:00
|
|
|
For this to work, the `ssh` SSS service must be enabled in the sssd configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
kcm = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Whether to use SSS as a Kerberos Cache Manager (KCM).
|
|
|
|
Kerberos will be configured to cache credentials in SSS.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2022-08-21 13:32:41 +00:00
|
|
|
environmentFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
Environment file as defined in {manpage}`systemd.exec(5)`.
|
2022-08-21 13:32:41 +00:00
|
|
|
|
|
|
|
Secrets may be passed to the service without adding them to the world-readable
|
|
|
|
Nix store, by specifying placeholder variables as the option value in Nix and
|
|
|
|
setting these variables accordingly in the environment file.
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2022-08-21 13:32:41 +00:00
|
|
|
# snippet of sssd-related config
|
|
|
|
[domain/LDAP]
|
|
|
|
ldap_default_authtok = $SSSD_LDAP_DEFAULT_AUTHTOK
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2022-08-21 13:32:41 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2022-08-21 13:32:41 +00:00
|
|
|
# contents of the environment file
|
|
|
|
SSSD_LDAP_DEFAULT_AUTHTOK=verysecretpassword
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2022-08-21 13:32:41 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkMerge [
|
|
|
|
(mkIf cfg.enable {
|
2023-03-24 00:07:29 +00:00
|
|
|
# For `sssctl` to work.
|
|
|
|
environment.etc."sssd/sssd.conf".source = settingsFile;
|
|
|
|
environment.etc."sssd/conf.d".source = "${dataDir}/conf.d";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.sssd = {
|
|
|
|
description = "System Security Services Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
before = [ "systemd-user-sessions.service" "nss-user-lookup.target" ];
|
|
|
|
after = [ "network-online.target" "nscd.service" ];
|
|
|
|
requires = [ "network-online.target" "nscd.service" ];
|
|
|
|
wants = [ "nss-user-lookup.target" ];
|
|
|
|
restartTriggers = [
|
|
|
|
config.environment.etc."nscd.conf".source
|
2022-08-21 13:32:41 +00:00
|
|
|
settingsFileUnsubstituted
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
script = ''
|
|
|
|
export LDB_MODULES_PATH+="''${LDB_MODULES_PATH+:}${pkgs.ldb}/modules/ldb:${pkgs.sssd}/modules/ldb"
|
|
|
|
mkdir -p /var/lib/sss/{pubconf,db,mc,pipes,gpo_cache,secrets} /var/lib/sss/pipes/private /var/lib/sss/pubconf/krb5.include.d
|
2022-08-21 13:32:41 +00:00
|
|
|
${pkgs.sssd}/bin/sssd -D -c ${settingsFile}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
PIDFile = "/run/sssd.pid";
|
2022-08-21 13:32:41 +00:00
|
|
|
StateDirectory = baseNameOf dataDir;
|
|
|
|
# We cannot use LoadCredential here because it's not available in ExecStartPre
|
|
|
|
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-08-21 13:32:41 +00:00
|
|
|
preStart = ''
|
2023-03-24 00:07:29 +00:00
|
|
|
mkdir -p "${dataDir}/conf.d"
|
2022-08-21 13:32:41 +00:00
|
|
|
[ -f ${settingsFile} ] && rm -f ${settingsFile}
|
|
|
|
old_umask=$(umask)
|
|
|
|
umask 0177
|
|
|
|
${pkgs.envsubst}/bin/envsubst \
|
|
|
|
-o ${settingsFile} \
|
|
|
|
-i ${settingsFileUnsubstituted}
|
|
|
|
umask $old_umask
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
system.nssModules = [ pkgs.sssd ];
|
2020-05-03 17:38:23 +00:00
|
|
|
system.nssDatabases = {
|
2020-05-15 21:57:56 +00:00
|
|
|
group = [ "sss" ];
|
2020-05-03 17:38:23 +00:00
|
|
|
passwd = [ "sss" ];
|
|
|
|
services = [ "sss" ];
|
2020-05-15 21:57:56 +00:00
|
|
|
shadow = [ "sss" ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
services.dbus.packages = [ pkgs.sssd ];
|
|
|
|
})
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
(mkIf cfg.kcm {
|
|
|
|
systemd.services.sssd-kcm = {
|
|
|
|
description = "SSSD Kerberos Cache Manager";
|
|
|
|
requires = [ "sssd-kcm.socket" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStartPre = "-${pkgs.sssd}/bin/sssd --genconf-section=kcm";
|
|
|
|
ExecStart = "${pkgs.sssd}/libexec/sssd/sssd_kcm --uid 0 --gid 0";
|
|
|
|
};
|
|
|
|
restartTriggers = [
|
2023-08-04 22:07:22 +00:00
|
|
|
settingsFileUnsubstituted
|
2022-08-12 12:06:08 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
systemd.sockets.sssd-kcm = {
|
|
|
|
description = "SSSD Kerberos Cache Manager responder socket";
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
# Matches the default in MIT krb5 and Heimdal:
|
|
|
|
# https://github.com/krb5/krb5/blob/krb5-1.19.3-final/src/include/kcm.h#L43
|
|
|
|
listenStreams = [ "/var/run/.heim_org.h5l.kcm-socket" ];
|
|
|
|
};
|
|
|
|
krb5.libdefaults.default_ccache_name = "KCM:";
|
|
|
|
})
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
(mkIf cfg.sshAuthorizedKeysIntegration {
|
|
|
|
# Ugly: sshd refuses to start if a store path is given because /nix/store is group-writable.
|
|
|
|
# So indirect by a symlink.
|
|
|
|
environment.etc."ssh/authorized_keys_command" = {
|
|
|
|
mode = "0755";
|
|
|
|
text = ''
|
|
|
|
#!/bin/sh
|
|
|
|
exec ${pkgs.sssd}/bin/sss_ssh_authorizedkeys "$@"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
services.openssh.authorizedKeysCommand = "/etc/ssh/authorized_keys_command";
|
|
|
|
services.openssh.authorizedKeysCommandUser = "nobody";
|
|
|
|
})];
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ bbigras ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|