2023-03-10 16:15:53 +01:00
|
|
|
{ config, pkgs, ... }:
|
2022-12-17 17:42:10 +01:00
|
|
|
let
|
2022-12-17 19:21:16 +01:00
|
|
|
domain = "auth.${config.fsr.domain}";
|
2022-12-17 13:58:06 +01:00
|
|
|
|
|
|
|
portunusUser = "portunus";
|
|
|
|
portunusGroup = "portunus";
|
|
|
|
|
|
|
|
ldapUser = "openldap";
|
|
|
|
ldapGroup = "openldap";
|
2022-12-17 17:42:10 +01:00
|
|
|
in
|
|
|
|
{
|
2023-02-15 11:29:47 +01:00
|
|
|
sops.secrets.unix_ldap_search = {
|
|
|
|
key = "portunus_search";
|
|
|
|
owner = config.systemd.services.nslcd.serviceConfig.User;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-12-17 13:58:06 +01:00
|
|
|
users.users."${portunusUser}" = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "${portunusGroup}";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups."${portunusGroup}" = {
|
|
|
|
name = "${portunusGroup}";
|
2022-12-17 17:42:10 +01:00
|
|
|
members = [ "${portunusUser}" ];
|
2022-12-17 13:58:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
users.users."${ldapUser}" = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "${ldapGroup}";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups."${ldapGroup}" = {
|
|
|
|
name = "${ldapGroup}";
|
2022-12-17 17:42:10 +01:00
|
|
|
members = [ "${ldapUser}" ];
|
2022-12-17 13:58:06 +01:00
|
|
|
};
|
|
|
|
|
2023-01-18 14:12:03 +01:00
|
|
|
sops.secrets = {
|
|
|
|
"portunus_admin" = {
|
|
|
|
owner = "${portunusUser}";
|
|
|
|
group = "${portunusGroup}";
|
|
|
|
};
|
|
|
|
"portunus_search" = {
|
|
|
|
owner = "${portunusUser}";
|
|
|
|
group = "${portunusGroup}";
|
|
|
|
};
|
2022-12-02 14:25:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.portunus = {
|
|
|
|
enable = true;
|
2023-07-04 17:06:18 +02:00
|
|
|
package = pkgs.portunus.overrideAttrs (old: {
|
|
|
|
patches = [ ./0001-update-user-validation-regex.patch ];
|
|
|
|
});
|
2022-12-17 13:58:06 +01:00
|
|
|
user = "${portunusUser}";
|
|
|
|
group = "${portunusGroup}";
|
2022-12-02 14:25:55 +01:00
|
|
|
domain = "${domain}";
|
2022-12-17 21:03:54 +01:00
|
|
|
port = 8081;
|
2023-01-18 14:12:03 +01:00
|
|
|
|
2022-12-02 14:25:55 +01:00
|
|
|
ldap = {
|
2022-12-17 13:58:06 +01:00
|
|
|
user = "${ldapUser}";
|
|
|
|
group = "${ldapGroup}";
|
2023-01-18 14:12:03 +01:00
|
|
|
|
2022-12-17 19:21:16 +01:00
|
|
|
suffix = "dc=ifsr,dc=de";
|
2023-01-18 14:12:03 +01:00
|
|
|
searchUserName = "search";
|
|
|
|
|
|
|
|
# disables port 389, use 636 with tls
|
|
|
|
# `portunus.domain` resolves to localhost
|
2023-02-15 11:29:47 +01:00
|
|
|
#tls = true;
|
2022-12-02 14:25:55 +01:00
|
|
|
};
|
|
|
|
|
2023-07-04 15:10:00 +02:00
|
|
|
seedPath = ../../config/portunus_seeds.json;
|
2022-12-02 14:25:55 +01:00
|
|
|
};
|
|
|
|
|
2023-02-15 11:29:47 +01:00
|
|
|
#users.ldap = {
|
2023-02-15 13:20:23 +01:00
|
|
|
#enable = true;
|
|
|
|
#server = "ldap://localhost";
|
|
|
|
#base = "${config.services.portunus.ldap.suffix}";
|
2023-02-15 11:29:47 +01:00
|
|
|
#};
|
2023-02-15 13:20:23 +01:00
|
|
|
users.ldap =
|
|
|
|
let
|
|
|
|
portunus = config.services.portunus;
|
|
|
|
base = "ou=users,${portunus.ldap.suffix}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
server = "ldap://localhost";
|
|
|
|
base = base;
|
|
|
|
bind = {
|
|
|
|
distinguishedName = "uid=${portunus.ldap.searchUserName},${base}";
|
|
|
|
passwordFile = config.sops.secrets.unix_ldap_search.path;
|
|
|
|
};
|
|
|
|
daemon.enable = true;
|
2023-02-15 11:29:47 +01:00
|
|
|
};
|
2023-02-03 15:40:42 +01:00
|
|
|
|
2023-03-10 16:38:57 +01:00
|
|
|
security.pam.services.sshd.text = ''
|
2023-03-10 16:15:53 +01:00
|
|
|
# Account management.
|
|
|
|
account sufficient ${pkgs.nss_pam_ldapd}/lib/security/pam_ldap.so
|
|
|
|
account required pam_unix.so
|
|
|
|
|
|
|
|
# Authentication management.
|
2023-03-10 16:38:57 +01:00
|
|
|
auth sufficient pam_unix.so likeauth try_first_pass
|
2023-03-10 16:15:53 +01:00
|
|
|
auth sufficient ${pkgs.nss_pam_ldapd}/lib/security/pam_ldap.so use_first_pass
|
|
|
|
auth required pam_deny.so
|
|
|
|
|
|
|
|
# Password management.
|
|
|
|
password sufficient pam_unix.so nullok sha512
|
|
|
|
password sufficient ${pkgs.nss_pam_ldapd}/lib/security/pam_ldap.so
|
|
|
|
|
|
|
|
# Session management.
|
|
|
|
session required pam_env.so conffile=/etc/pam/environment readenv=0
|
|
|
|
session required pam_unix.so
|
|
|
|
session required pam_loginuid.so
|
|
|
|
session optional pam_mkhomedir.so
|
|
|
|
session optional ${pkgs.nss_pam_ldapd}/lib/security/pam_ldap.so
|
|
|
|
session optional ${pkgs.systemd}/lib/security/pam_systemd.so
|
|
|
|
|
|
|
|
'';
|
2023-02-15 11:29:47 +01:00
|
|
|
|
2022-12-17 13:58:06 +01:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."${config.services.portunus.domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations = {
|
|
|
|
"/".proxyPass = "http://localhost:${toString config.services.portunus.port}";
|
|
|
|
};
|
|
|
|
};
|
2022-12-02 14:25:55 +01:00
|
|
|
};
|
|
|
|
}
|