2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
2024-04-12 16:38:15 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-12-15 21:26:51 +01:00
|
|
|
pkgs,
|
2024-10-18 14:35:52 +02:00
|
|
|
meta,
|
2024-04-12 16:38:15 +02:00
|
|
|
...
|
|
|
|
}:
|
2023-09-14 08:04:48 +02:00
|
|
|
|
|
|
|
let
|
2024-10-18 14:35:52 +02:00
|
|
|
inherit (lib)
|
|
|
|
attrValues
|
|
|
|
catAttrs
|
|
|
|
escapeRegex
|
|
|
|
concatStringsSep
|
|
|
|
mapAttrs'
|
|
|
|
nameValuePair
|
|
|
|
;
|
2024-04-12 16:38:15 +02:00
|
|
|
|
2024-10-12 22:11:34 +02:00
|
|
|
domain = "sso.dgnum.eu";
|
2024-10-12 19:30:36 +02:00
|
|
|
port = 8443;
|
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-10-18 14:35:52 +02:00
|
|
|
|
|
|
|
usernameFor = member: meta.organization.members.${member}.username;
|
2024-02-02 10:51:31 +01:00
|
|
|
in
|
|
|
|
{
|
2024-12-15 21:26:51 +01:00
|
|
|
nixpkgs.config.permittedInsecurePackages = [ "kanidm-1.3.3" ];
|
|
|
|
|
2023-09-14 08:04:48 +02:00
|
|
|
services.kanidm = {
|
|
|
|
enableServer = true;
|
|
|
|
|
2024-12-17 00:11:05 +01:00
|
|
|
package = pkgs.kanidm_1_4;
|
2024-02-22 12:47:18 +01:00
|
|
|
|
2023-09-14 08:04:48 +02:00
|
|
|
serverSettings = {
|
|
|
|
inherit domain;
|
|
|
|
|
|
|
|
origin = "https://${domain}";
|
|
|
|
|
2024-10-12 22:11:34 +02:00
|
|
|
bindaddress = "127.0.0.1:${builtins.toString port}";
|
2023-09-14 08:04:48 +02:00
|
|
|
ldapbindaddress = "0.0.0.0:636";
|
|
|
|
|
|
|
|
trust_x_forward_for = true;
|
|
|
|
|
|
|
|
tls_chain = "${cert.directory}/fullchain.pem";
|
|
|
|
tls_key = "${cert.directory}/key.pem";
|
|
|
|
};
|
2024-10-18 14:35:52 +02:00
|
|
|
|
|
|
|
provision = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
persons = mapAttrs' (
|
|
|
|
_:
|
|
|
|
{
|
|
|
|
email,
|
|
|
|
name,
|
|
|
|
username,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
nameValuePair username {
|
|
|
|
displayName = name;
|
|
|
|
mailAddresses = [ email ];
|
|
|
|
}
|
|
|
|
) meta.organization.members;
|
|
|
|
|
|
|
|
groups =
|
|
|
|
{
|
|
|
|
grp_active.members = catAttrs "username" (attrValues meta.organization.members);
|
|
|
|
}
|
|
|
|
// (mapAttrs' (
|
|
|
|
name: members: nameValuePair "grp_${name}" { members = builtins.map usernameFor members; }
|
|
|
|
) meta.organization.groups);
|
|
|
|
|
|
|
|
# INFO: The authentication resources declared here can only be for internal services,
|
|
|
|
# as regular members cannot be statically known.
|
|
|
|
systems.oauth2 = {
|
|
|
|
dgn_grafana = {
|
|
|
|
displayName = "Grafana [Analysis]";
|
|
|
|
originLanding = "https://grafana.dgnum.eu";
|
2024-12-17 00:11:05 +01:00
|
|
|
originUrl = "https://grafana.dgnum.eu/login/generic_oauth";
|
2024-10-18 14:35:52 +02:00
|
|
|
preferShortUsername = true;
|
|
|
|
|
|
|
|
scopeMaps.grp_active = [
|
|
|
|
"openid"
|
|
|
|
"profile"
|
|
|
|
"email"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
dgn_librenms = {
|
|
|
|
allowInsecureClientDisablePkce = true;
|
|
|
|
displayName = "LibreNMS [Network]";
|
|
|
|
enableLegacyCrypto = true;
|
|
|
|
originLanding = "https://nms.dgnum.eu";
|
2024-12-17 00:11:05 +01:00
|
|
|
originUrl = "https://nms.dgnum.eu/auth/kanidm/callback";
|
2024-10-18 14:35:52 +02:00
|
|
|
preferShortUsername = true;
|
|
|
|
|
|
|
|
scopeMaps.grp_active = [
|
|
|
|
"openid"
|
|
|
|
"profile"
|
|
|
|
"email"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
dgn_netbird = {
|
|
|
|
displayName = "Netbird [VPN]";
|
|
|
|
enableLocalhostRedirects = true;
|
|
|
|
originLanding = "https://netbird.dgnum.eu";
|
2024-12-17 00:11:05 +01:00
|
|
|
originUrl = "https://netbird.dgnum.eu/index";
|
2024-10-18 14:35:52 +02:00
|
|
|
preferShortUsername = true;
|
|
|
|
public = true;
|
|
|
|
|
|
|
|
scopeMaps.grp_active = [
|
|
|
|
"openid"
|
|
|
|
"profile"
|
|
|
|
"email"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
dgn_netbox = {
|
|
|
|
allowInsecureClientDisablePkce = true;
|
|
|
|
displayName = "Netbox [Inventory]";
|
|
|
|
enableLegacyCrypto = true;
|
|
|
|
originLanding = "https://netbox.dgnum.eu";
|
2024-12-17 00:11:05 +01:00
|
|
|
originUrl = "https://netbox.dgnum.eu/oauth/complete/oidc/";
|
2024-10-18 14:35:52 +02:00
|
|
|
preferShortUsername = true;
|
|
|
|
|
|
|
|
scopeMaps.grp_active = [
|
|
|
|
"openid"
|
|
|
|
"profile"
|
|
|
|
"email"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
dgn_outline = {
|
|
|
|
displayName = "Outline [Docs]";
|
2024-12-17 00:11:05 +01:00
|
|
|
originUrl = "https://docs.dgnum.eu/auth/oidc.callback";
|
2024-10-18 14:35:52 +02:00
|
|
|
originLanding = "https://docs.dgnum.eu";
|
|
|
|
preferShortUsername = true;
|
2024-12-17 00:11:05 +01:00
|
|
|
allowInsecureClientDisablePkce = true;
|
2024-10-18 14:35:52 +02:00
|
|
|
|
|
|
|
scopeMaps.grp_active = [
|
|
|
|
"openid"
|
|
|
|
"profile"
|
|
|
|
"email"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-09-14 08:04:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
users.users.kanidm.extraGroups = [ cert.group ];
|
|
|
|
|
2024-10-12 22:11:34 +02:00
|
|
|
dgn-web.internalPorts.kanidm = port;
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
virtualHosts.${domain} = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "https://127.0.0.1:${builtins.toString port}";
|
|
|
|
|
|
|
|
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
|
|
|
}
|