fruitbasket/modules/ldap/default.nix

124 lines
3.1 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2022-12-17 17:42:10 +01:00
let
2022-12-17 19:21:16 +01:00
domain = "auth.${config.fsr.domain}";
2023-07-07 17:13:17 +02:00
seed = {
groups = [
{
name = "admins";
long_name = "Portunus Admin";
members = [ "admin" ];
permissions.portunus.is_admin = true;
}
{
name = "search";
long_name = "LDAP search group";
members = [ "search" ];
permissions.ldap.can_read = true;
}
{
name = "fsr";
long_name = "Mitglieder des iFSR";
}
];
users = [
{
login_name = "admin";
given_name = "admin";
family_name = "admin";
password.from_command = [
"${pkgs.coreutils}/bin/cat"
config.sops.secrets."portunus/admin-password".path
];
}
{
login_name = "search";
given_name = "search";
family_name = "search";
password.from_command = [
"${pkgs.coreutils}/bin/cat"
config.sops.secrets."portunus/search-password".path
];
}
];
};
2022-12-17 17:42:10 +01:00
in
{
sops.secrets = {
"portunus/admin-password".owner = config.services.portunus.user;
"portunus/search-password".owner = config.services.portunus.user;
"dex/environment".owner = config.systemd.services.dex.serviceConfig.User;
nslcd_ldap_search = {
key = "portunus/search-password";
owner = config.systemd.services.nslcd.serviceConfig.User;
};
};
services.portunus = {
enable = true;
2023-07-04 17:06:18 +02:00
package = pkgs.portunus.overrideAttrs (old: {
patches = [
./0001-update-user-validation-regex.patch
./0002-both-ldap-and-ldaps.patch
];
2023-07-04 17:06:18 +02:00
});
inherit domain;
port = 8681;
dex.enable = true;
2023-07-07 17:13:17 +02:00
seedPath = pkgs.writeText "portunus-seed.json" (builtins.toJSON seed);
ldap = {
2022-12-17 19:21:16 +01:00
suffix = "dc=ifsr,dc=de";
searchUserName = "search";
# normally disables port 389 (but not with our patch), use 636 with tls
# `portunus.domain` resolves to localhost
tls = true;
};
};
services.dex.settings.oauth2.skipApprovalScreen = true;
systemd.services.dex.serviceConfig = {
DynamicUser = lib.mkForce false;
EnvironmentFile = config.sops.secrets."dex/environment".path;
StateDirectory = "dex";
User = "dex";
};
users = {
users.dex = {
group = "dex";
isSystemUser = true;
};
groups.dex = { };
ldap =
2023-08-22 15:25:33 +02:00
let portunus = config.services.portunus; in
rec {
enable = true;
server = "ldap://localhost";
2023-08-25 15:01:52 +02:00
base = "${portunus.ldap.suffix}";
bind = {
2023-08-25 15:01:52 +02:00
distinguishedName = "uid=${portunus.ldap.searchUserName},ou=users,${base}";
passwordFile = config.sops.secrets.nslcd_ldap_search.path;
};
daemon.enable = true;
};
};
2023-02-03 15:40:42 +01:00
2023-08-22 15:25:33 +02:00
security.pam.services.sshd.makeHomeDir = true;
services.nginx = {
enable = true;
virtualHosts."${config.services.portunus.domain}" = {
forceSSL = true;
enableACME = true;
locations = {
"/".proxyPass = "http://localhost:${toString config.services.portunus.port}";
"/dex".proxyPass = "http://localhost:${toString config.services.portunus.dex.port}";
};
};
};
}