2024-04-12 16:38:15 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
nixpkgs,
|
|
|
|
...
|
|
|
|
}:
|
2023-09-14 08:04:48 +02:00
|
|
|
|
|
|
|
let
|
2024-04-12 16:38:15 +02:00
|
|
|
inherit (lib) escapeRegex concatStringsSep;
|
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
host = "sso.dgnum.eu";
|
|
|
|
port = 8443;
|
|
|
|
domain = host;
|
2023-09-14 08:04:48 +02:00
|
|
|
|
|
|
|
cert = config.security.acme.certs.${domain};
|
|
|
|
|
2024-04-12 16:38:15 +02:00
|
|
|
allowedDomains = builtins.map escapeRegex (
|
|
|
|
(builtins.map (s: "${s}.dgnum.eu") [
|
|
|
|
# DGNum subdomains
|
|
|
|
"cloud"
|
|
|
|
"git"
|
|
|
|
"videos"
|
|
|
|
"social"
|
|
|
|
"demarches"
|
|
|
|
"netbird"
|
|
|
|
])
|
|
|
|
++ [
|
|
|
|
# Extra domains
|
|
|
|
"netbird-beta.hubrecht.ovh"
|
|
|
|
]
|
|
|
|
);
|
2024-02-02 10:51:31 +01:00
|
|
|
in
|
|
|
|
{
|
2023-09-14 08:04:48 +02:00
|
|
|
services.kanidm = {
|
|
|
|
enableServer = true;
|
|
|
|
|
2024-04-03 21:21:04 +02:00
|
|
|
package = nixpkgs.unstable.kanidm;
|
2024-02-22 12:47:18 +01:00
|
|
|
|
2023-09-14 08:04:48 +02:00
|
|
|
serverSettings = {
|
|
|
|
inherit domain;
|
|
|
|
|
|
|
|
origin = "https://${domain}";
|
|
|
|
|
|
|
|
bindaddress = "127.0.0.1:8443";
|
|
|
|
ldapbindaddress = "0.0.0.0:636";
|
|
|
|
|
|
|
|
trust_x_forward_for = true;
|
|
|
|
|
|
|
|
tls_chain = "${cert.directory}/fullchain.pem";
|
|
|
|
tls_key = "${cert.directory}/key.pem";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.kanidm.extraGroups = [ cert.group ];
|
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
dgn-web.simpleProxies.kanidm = {
|
|
|
|
inherit host port;
|
|
|
|
vhostConfig.locations."/".extraConfig = ''
|
|
|
|
if ( $request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|PATCH|DELETE)$ ) {
|
|
|
|
return 444;
|
|
|
|
}
|
|
|
|
|
|
|
|
set $origin $http_origin;
|
|
|
|
|
|
|
|
if ($origin !~ '^https?://(${concatStringsSep "|" allowedDomains})$') {
|
|
|
|
set $origin 'https://${domain}';
|
|
|
|
}
|
|
|
|
|
|
|
|
proxy_hide_header Access-Control-Allow-Origin;
|
|
|
|
|
|
|
|
if ($request_method = 'OPTIONS') {
|
|
|
|
add_header 'Access-Control-Allow-Origin' "$origin" always;
|
|
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, PUT, DELETE, OPTIONS' always;
|
|
|
|
add_header 'Access-Control-Allow-Headers' 'Content-Type, Accept, Authorization' always;
|
|
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
|
|
|
|
|
|
add_header Access-Control-Max-Age 1728000;
|
|
|
|
add_header Content-Type 'text/plain charset=UTF-8';
|
|
|
|
add_header Content-Length 0;
|
|
|
|
return 204;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request_method ~ '(GET|POST|PATCH|PUT|DELETE)') {
|
|
|
|
add_header Access-Control-Allow-Origin "$origin" always;
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, PATCH, PUT, DELETE, OPTIONS' always;
|
|
|
|
add_header Access-Control-Allow-Headers 'Content-Type, Accept, Authorization' always;
|
|
|
|
add_header Access-Control-Allow-Credentials true always;
|
|
|
|
}
|
|
|
|
'';
|
2023-09-14 08:04:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 636 ];
|
|
|
|
networking.firewall.allowedUDPPorts = [ 636 ];
|
2024-02-21 22:49:20 +01:00
|
|
|
|
|
|
|
dgn-backups.jobs.kanidm.settings.paths = [ "/var/lib/kanidm" ];
|
2023-09-14 08:04:48 +02:00
|
|
|
}
|