2021-12-12 16:49:47 -08:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
hostname = config.instance.hostname;
|
2021-12-18 12:10:42 -08:00
|
|
|
domain-name = config.fudo.services.auth.domain;
|
2021-12-12 16:49:47 -08:00
|
|
|
domain = config.fudo.domains.${domain-name};
|
|
|
|
|
|
|
|
ldap-server = elem hostname domain.ldap-servers;
|
|
|
|
|
|
|
|
kerberos-master = hostname == domain.kerberos-master;
|
|
|
|
kerberos-slave = elem hostname domain.kerberos-slaves;
|
|
|
|
|
|
|
|
kerberized-domain = domain.kerberos-master != null;
|
|
|
|
|
2021-12-18 12:10:42 -08:00
|
|
|
optionalOrNull = pred: val: if pred then val else null;
|
|
|
|
|
|
|
|
cfg = config.fudo.services.auth;
|
|
|
|
|
2021-12-12 16:49:47 -08:00
|
|
|
in {
|
|
|
|
options.fudo.services.auth = with types; {
|
2021-12-18 12:10:42 -08:00
|
|
|
domain = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Domain for which authentication server will operate.";
|
|
|
|
default = config.fudo.hosts.${hostname}.domain;
|
|
|
|
};
|
|
|
|
|
2021-12-12 16:49:47 -08:00
|
|
|
ldap = {
|
|
|
|
hostname = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Fully-qualified (and public-addressable) domain name of this host.";
|
|
|
|
default = config.instance.host-fqdn;
|
|
|
|
};
|
|
|
|
|
|
|
|
state-directory = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Directory at which to store peristent ldap-related data.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
kerberos = {
|
|
|
|
hostname = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Fully-qualified (and public-addressable) domain name of this host.";
|
|
|
|
default = config.instance.host-fqdn;
|
|
|
|
};
|
|
|
|
|
|
|
|
state-directory = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Directory at which to store peristent KDC-related data.";
|
|
|
|
};
|
|
|
|
|
|
|
|
master-key-file = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Path (on the build server) to the KDC master key file.";
|
|
|
|
};
|
2021-12-18 12:10:42 -08:00
|
|
|
|
|
|
|
ipropd-keytab = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "ipropd keytab for kerberos database propagation.";
|
|
|
|
};
|
2021-12-12 16:49:47 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config.fudo = {
|
|
|
|
acme.host-domains.${hostname} = mkIf (ldap-server) {
|
2021-12-18 12:10:42 -08:00
|
|
|
${cfg.ldap.hostname}.local-copies.openldap = {
|
2021-12-12 16:49:47 -08:00
|
|
|
user = config.services.openldap.user;
|
|
|
|
part-of = [ config.fudo.auth.ldap-server.systemd-target ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
auth = {
|
|
|
|
ldap-server = mkIf (ldap-server)
|
|
|
|
(let
|
|
|
|
ldap-cert-copy =
|
2021-12-18 12:10:42 -08:00
|
|
|
config.fudo.acme.host-domains.${hostname}.${cfg.ldap.hostname}.local-copies.openldap;
|
2021-12-12 16:49:47 -08:00
|
|
|
in {
|
|
|
|
enable = ldap-server;
|
|
|
|
base = "dc=fudo,dc=org";
|
|
|
|
organization = "Fudo";
|
|
|
|
listen-uris = [ "ldap:///" "ldaps:///" ];
|
|
|
|
required-services = [ ldap-cert-copy.service ];
|
|
|
|
|
|
|
|
# TODO: Maybe filter to Fudo-only?
|
|
|
|
users = config.fudo.users;
|
|
|
|
groups = config.fudo.groups;
|
|
|
|
system-users = config.fudo.system-users;
|
|
|
|
|
2021-12-18 12:10:42 -08:00
|
|
|
state-directory = "${cfg.ldap.state-directory}";
|
2021-12-12 16:49:47 -08:00
|
|
|
|
|
|
|
ssl-chain = ldap-cert-copy.chain;
|
|
|
|
ssl-certificate = ldap-cert-copy.certificate;
|
|
|
|
ssl-private-key = ldap-cert-copy.private-key;
|
|
|
|
ssl-ca-certificate = "${pkgs.letsencrypt-ca}";
|
|
|
|
});
|
|
|
|
|
|
|
|
kdc = mkIf (kerberos-master || kerberos-slave) {
|
|
|
|
enable = true;
|
|
|
|
realm = domain.gssapi-realm;
|
|
|
|
bind-addresses =
|
|
|
|
(pkgs.lib.network.host-ips config hostname) ++
|
|
|
|
[ "127.0.0.1" ] ++ (optional config.networking.enableIPv6 "::1");
|
2021-12-18 12:10:42 -08:00
|
|
|
state-directory = cfg.kerberos.state-directory;
|
|
|
|
master-key-file = cfg.kerberos.master-key-file;
|
2021-12-12 16:49:47 -08:00
|
|
|
master-config = mkIf (kerberos-master) {
|
|
|
|
acl = let
|
2021-12-18 12:10:42 -08:00
|
|
|
admin-entries = genAttrs config.instance.local-admins
|
2021-12-12 16:49:47 -08:00
|
|
|
(admin: {
|
|
|
|
perms = [ "add" "change-password" "list" ];
|
|
|
|
});
|
|
|
|
in admin-entries // {
|
|
|
|
"*/root".perms = [ "all" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
slave-config = mkIf (kerberos-slave) {
|
|
|
|
master-host = domain.kerberos-master;
|
2021-12-18 12:10:42 -08:00
|
|
|
ipropd-keytab = cfg.kerberos.ipropd-keytab;
|
2021-12-12 16:49:47 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
dns.domains.${domain-name} = let
|
|
|
|
make-srv-record = port: hostname: {
|
|
|
|
port = port;
|
|
|
|
host = hostname;
|
|
|
|
};
|
|
|
|
|
|
|
|
get-fqdn = host:
|
|
|
|
"${host}.${config.fudo.hosts.${host}.domain}";
|
|
|
|
|
|
|
|
kerberos-masters = optional (kerberized-domain)
|
|
|
|
domain.kerberos-master;
|
|
|
|
|
|
|
|
kerberos-servers = map get-fqdn
|
|
|
|
(kerberos-masters ++ domain.kerberos-slaves);
|
|
|
|
|
|
|
|
master-servers = map get-fqdn kerberos-masters;
|
|
|
|
|
|
|
|
ldap-servers = map get-fqdn domain.ldap-servers;
|
|
|
|
in {
|
|
|
|
zone-definition.srv-records = {
|
|
|
|
tcp = {
|
2021-12-18 12:10:42 -08:00
|
|
|
kerberos = map (make-srv-record 88) kerberos-servers;
|
|
|
|
kerberos-adm = map (make-srv-record 749) kerberos-masters;
|
|
|
|
ldap = map (make-srv-record 389) ldap-servers;
|
|
|
|
ldaps = map (make-srv-record 636) ldap-servers;
|
2021-12-12 16:49:47 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
udp = {
|
2021-12-18 12:10:42 -08:00
|
|
|
kerberos = map (make-srv-record 88) kerberos-servers;
|
|
|
|
kerberos-master = map (make-srv-record 88) kerberos-masters;
|
|
|
|
kpasswd = map (make-srv-record 464) kerberos-masters;
|
2021-12-12 16:49:47 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|