mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
feat: switch proxt host
This commit is contained in:
parent
5d27d18f85
commit
0cb34c98cb
61 changed files with 1147 additions and 736 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{ self, lib, pkgs, config, globals, ... }:
|
||||
let
|
||||
certsSopsFile = self + /secrets/repo/certs.yaml;
|
||||
clientSopsFile = "${config.node.secretsDir}/secrets.yaml";
|
||||
clientSopsFile = config.node.secretsDir + "/secrets.yaml";
|
||||
|
||||
inherit (config.repo.secrets.common.network) wlan1 mobile1 vpn1-location vpn1-cipher vpn1-address eduroam-anon;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
config = lib.mkIf config.swarselmodules.security {
|
||||
|
||||
security = {
|
||||
# pki.certificateFiles = [
|
||||
# config.sops.secrets.harica-root-ca.path
|
||||
# ];
|
||||
pam.services = lib.mkIf (!minimal) {
|
||||
login.u2fAuth = true;
|
||||
sudo.u2fAuth = true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ config, lib, ... }:
|
||||
{ self, config, lib, ... }:
|
||||
{
|
||||
options.swarselmodules.sops = lib.mkEnableOption "sops config";
|
||||
config = lib.mkIf config.swarselmodules.sops {
|
||||
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
# age.sshKeyPaths = lib.swarselsystems.mkIfElseList config.swarselsystems.isBtrfs [ "/persist/.ssh/sops" "/persist/.ssh/ssh_host_ed25519_key" ] [ "${config.swarselsystems.homeDir}/.ssh/sops" "/etc/ssh/sops" "/etc/ssh/ssh_host_ed25519_key" ];
|
||||
age.sshKeyPaths = [ "${if config.swarselsystems.isImpermanence then "/persist" else ""}/etc/ssh/ssh_host_ed25519_key" ];
|
||||
defaultSopsFile = "${if config.swarselsystems.isImpermanence then "/persist" else ""}${config.swarselsystems.flakePath}/secrets/repo/common.yaml";
|
||||
# defaultSopsFile = "${if config.swarselsystems.isImpermanence then "/persist" else ""}${config.swarselsystems.flakePath}/secrets/repo/common.yaml";
|
||||
defaultSopsFile = self + "/secrets/repo/common.yaml";
|
||||
|
||||
validateSopsFiles = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
useDHCP = lib.mkForce false;
|
||||
useNetworkd = true;
|
||||
dhcpcd.enable = false;
|
||||
renameInterfacesByMac = lib.mapAttrs (_: v: v.mac) (
|
||||
renameInterfacesByMac = lib.mapAttrs (_: v: if (v ? mac) then v.mac else "") (
|
||||
config.repo.secrets.local.networking.networks or { }
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ in
|
|||
"ip=${localIp}::${gatewayIp}:${subnetMask}:${config.networking.hostName}::none"
|
||||
];
|
||||
initrd = {
|
||||
secrets."${hostKeyPathBase}" = lib.mkIf (!minimal) hostKeyPathBase;
|
||||
availableKernelModules = config.swarselsystems.networkKernelModules;
|
||||
network = {
|
||||
enable = true;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = true;
|
||||
|
|
|
|||
|
|
@ -140,7 +140,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = true;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = false;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ in
|
|||
|
||||
services = {
|
||||
${serviceName} = {
|
||||
package = pkgs.kanidmWithSecretProvisioning_1_7;
|
||||
package = pkgs.kanidmWithSecretProvisioning_1_8;
|
||||
enableServer = true;
|
||||
serverSettings = {
|
||||
domain = serviceDomain;
|
||||
|
|
@ -390,7 +390,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -303,7 +303,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
listen = [
|
||||
|
|
|
|||
|
|
@ -115,7 +115,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ let
|
|||
|
||||
inherit (config.swarselsystems) sopsFile;
|
||||
|
||||
sopsFile2 = "${config.node.secretsDir}/secrets2.yaml";
|
||||
# sopsFile2 = config.node.secretsDir + "/secrets2.yaml";
|
||||
in
|
||||
{
|
||||
options.swarselmodules.server.${serviceName} = lib.mkEnableOption "enable ${serviceName} on server";
|
||||
|
|
@ -27,7 +27,8 @@ in
|
|||
grafana-admin-pw = { inherit sopsFile; owner = serviceUser; group = serviceGroup; mode = "0440"; };
|
||||
prometheus-admin-pw = { inherit sopsFile; owner = serviceUser; group = serviceGroup; mode = "0440"; };
|
||||
kanidm-grafana-client = { inherit sopsFile; owner = serviceUser; group = serviceGroup; mode = "0440"; };
|
||||
prometheus-admin-hash = { sopsFile = sopsFile2; owner = prometheusUser; group = prometheusGroup; mode = "0440"; };
|
||||
# prometheus-admin-hash = { sopsFile = sopsFile2; owner = prometheusUser; group = prometheusGroup; mode = "0440"; };
|
||||
prometheus-admin-hash = { inherit sopsFile; owner = prometheusUser; group = prometheusGroup; mode = "0440"; };
|
||||
|
||||
};
|
||||
templates = {
|
||||
|
|
@ -226,7 +227,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = true;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
let
|
||||
netConfig = config.repo.secrets.local.networking;
|
||||
netPrefix = "${if config.swarselsystems.isCloud then config.node.name else "home"}";
|
||||
netName = "${netPrefix}-${config.swarselsystems.server.localNetwork}";
|
||||
# netName = "${netPrefix}-${config.swarselsystems.server.localNetwork}";
|
||||
in
|
||||
{
|
||||
options = {
|
||||
|
|
@ -14,7 +14,7 @@ in
|
|||
};
|
||||
netConfigName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = netName;
|
||||
default = "${netPrefix}-${config.swarselsystems.server.localNetwork}";
|
||||
readOnly = true;
|
||||
};
|
||||
netConfigPrefix = lib.mkOption {
|
||||
|
|
@ -28,10 +28,21 @@ in
|
|||
|
||||
swarselsystems.server.localNetwork = netConfig.localNetwork or "";
|
||||
|
||||
globals.networks.${netName}.hosts.${config.node.name} = {
|
||||
inherit (netConfig.networks.${netConfig.localNetwork}) id;
|
||||
mac = netConfig.networks.${netConfig.localNetwork}.mac or null;
|
||||
};
|
||||
# globals.networks.${netName}.hosts.${config.node.name} = {
|
||||
# inherit (netConfig.networks.${netConfig.localNetwork}) id;
|
||||
# mac = netConfig.networks.${netConfig.localNetwork}.mac or null;
|
||||
# };
|
||||
|
||||
globals.networks = lib.mapAttrs'
|
||||
(netName: _:
|
||||
lib.nameValuePair "${netPrefix}-${netName}" {
|
||||
hosts.${config.node.name} = {
|
||||
inherit (netConfig.networks.${netName}) id;
|
||||
mac = netConfig.networks.${netName}.mac or null;
|
||||
};
|
||||
}
|
||||
)
|
||||
netConfig.networks;
|
||||
|
||||
globals.hosts.${config.node.name} = {
|
||||
inherit (config.repo.secrets.local.networking) defaultGateway4;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{ pkgs, lib, config, ... }:
|
||||
{ pkgs, lib, config, globals, ... }:
|
||||
let
|
||||
inherit (config.repo.secrets.common) dnsProvider dnsBase;
|
||||
inherit (config.repo.secrets.common.mail) address3;
|
||||
inherit (config.repo.secrets.common) dnsProvider dnsBase dnsMail;
|
||||
|
||||
serviceUser = "nginx";
|
||||
serviceGroup = serviceUser;
|
||||
|
|
@ -18,42 +17,66 @@ in
|
|||
options.swarselmodules.server.nginx = lib.mkEnableOption "enable nginx on server";
|
||||
options.services.nginx = {
|
||||
recommendedSecurityHeaders = lib.mkEnableOption "additional security headers by default in each location block.";
|
||||
defaultStapling = lib.mkEnableOption "add ssl stapling in each location block..";
|
||||
virtualHosts = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule {
|
||||
options.locations = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (submod: {
|
||||
options = {
|
||||
recommendedSecurityHeaders = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = config.services.nginx.recommendedSecurityHeaders;
|
||||
description = "Whether to add additional security headers to this location.";
|
||||
lib.types.submodule (topmod: {
|
||||
options = {
|
||||
defaultStapling = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = config.services.nginx.defaultStapling;
|
||||
description = "Whether to add ssl stapling to this location.";
|
||||
};
|
||||
locations = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (submod: {
|
||||
options = {
|
||||
recommendedSecurityHeaders = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = config.services.nginx.recommendedSecurityHeaders;
|
||||
description = "Whether to add additional security headers to this location.";
|
||||
};
|
||||
|
||||
X-Frame-Options = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "DENY";
|
||||
description = "The value to use for X-Frame-Options";
|
||||
};
|
||||
};
|
||||
|
||||
X-Frame-Options = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "DENY";
|
||||
description = "The value to use for X-Frame-Options";
|
||||
config = {
|
||||
extraConfig = lib.mkIf submod.config.recommendedSecurityHeaders (lib.mkBefore ''
|
||||
# Hide upstream's versions
|
||||
proxy_hide_header Strict-Transport-Security;
|
||||
proxy_hide_header Referrer-Policy;
|
||||
proxy_hide_header X-Content-Type-Options;
|
||||
proxy_hide_header X-Frame-Options;
|
||||
|
||||
# Enable HTTP Strict Transport Security (HSTS)
|
||||
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
|
||||
|
||||
# Minimize information leaked to other domains
|
||||
add_header Referrer-Policy "origin-when-cross-origin";
|
||||
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Frame-Options "${submod.config.X-Frame-Options}";
|
||||
add_header X-Content-Type-Options "nosniff";
|
||||
''
|
||||
);
|
||||
};
|
||||
};
|
||||
config = lib.mkIf submod.config.recommendedSecurityHeaders {
|
||||
extraConfig = lib.mkBefore ''
|
||||
# Enable HTTP Strict Transport Security (HSTS)
|
||||
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
|
||||
|
||||
# Minimize information leaked to other domains
|
||||
add_header Referrer-Policy "origin-when-cross-origin";
|
||||
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Frame-Options "${submod.config.X-Frame-Options}";
|
||||
add_header X-Content-Type-Options "nosniff";
|
||||
'';
|
||||
};
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
config = {
|
||||
extraConfig = lib.mkIf topmod.config.defaultStapling (lib.mkAfter ''
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
resolver 1.1.1.1 8.8.8.8 valid=300s;
|
||||
resolver_timeout 5s;
|
||||
'');
|
||||
};
|
||||
})
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
@ -62,27 +85,30 @@ in
|
|||
lego
|
||||
];
|
||||
|
||||
sops = {
|
||||
sops = lib.mkIf (config.node.name == config.swarselsystems.proxyHost) {
|
||||
secrets = {
|
||||
acme-dns-token = { inherit (config.swarselsystems) sopsFile; };
|
||||
acme-creds = { format = "json"; key = ""; group = "acme"; sopsFile = config.node.secretsDir + "/acme.json"; mode = "0660"; };
|
||||
};
|
||||
templates."certs.secret".content = ''
|
||||
ACME_DNS_API_BASE=${dnsBase}
|
||||
ACME_DNS_STORAGE_PATH=${config.sops.placeholder.acme-dns-token}
|
||||
ACME_DNS_API_BASE = ${dnsBase}
|
||||
ACME_DNS_STORAGE_PATH=${config.sops.secrets.acme-creds.path}
|
||||
'';
|
||||
};
|
||||
|
||||
users.groups.acme.members = [ "nginx" ];
|
||||
|
||||
security.acme = {
|
||||
security.acme = lib.mkIf (config.node.name == config.swarselsystems.proxyHost) {
|
||||
acceptTerms = true;
|
||||
defaults = {
|
||||
inherit dnsProvider;
|
||||
email = address3;
|
||||
email = dnsMail;
|
||||
environmentFile = "${config.sops.templates."certs.secret".path}";
|
||||
reloadServices = [ "nginx" ];
|
||||
dnsPropagationCheck = true;
|
||||
};
|
||||
certs."${globals.domains.main}" = {
|
||||
domain = "*.${globals.domains.main}";
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
||||
|
|
@ -103,6 +129,7 @@ in
|
|||
recommendedGzipSettings = true;
|
||||
recommendedBrotliSettings = true;
|
||||
recommendedSecurityHeaders = true;
|
||||
defaultStapling = true;
|
||||
sslCiphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:!aNULL";
|
||||
sslDhparam = dhParamsPathBase;
|
||||
virtualHosts.fallback = {
|
||||
|
|
@ -129,11 +156,11 @@ in
|
|||
${if config.swarselsystems.isImpermanence then "${pkgs.coreutils}/bin/install -d -m 0755 /persist${sslBasePath}" else ""}
|
||||
|
||||
if [ ! -f "${dhParamsPath}" ]; then
|
||||
${pkgs.openssl}/bin/openssl dhparam -out "${dhParamsPath}" 4096
|
||||
chmod 0644 "${dhParamsPath}"
|
||||
chown ${serviceUser}:${serviceGroup} "${dhParamsPath}"
|
||||
${pkgs.openssl}/bin/openssl dhparam -out "${dhParamsPath}" 4096
|
||||
chmod 0644 "${dhParamsPath}"
|
||||
chown ${serviceUser}:${serviceGroup} "${dhParamsPath}"
|
||||
else
|
||||
echo 'Already generated DHParams'
|
||||
echo 'Already generated DHParams'
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ with dns.lib.combinators; {
|
|||
SOA = {
|
||||
nameServer = "soa";
|
||||
adminEmail = "admin@${globals.domains.main}"; # this option is not parsed as domain (we cannot just write "admin")
|
||||
serial = 2025120203; # update this on changes for secondary dns
|
||||
serial = 2025120501; # update this on changes for secondary dns
|
||||
};
|
||||
|
||||
useOrigin = false;
|
||||
|
|
@ -13,6 +13,7 @@ with dns.lib.combinators; {
|
|||
"srv"
|
||||
] ++ globals.domains.externalDns;
|
||||
|
||||
CAA = letsEncrypt config.repo.secrets.common.dnsMail;
|
||||
|
||||
A = [ config.repo.secrets.local.dns.homepage-ip ];
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
sops
|
||||
swarsel-deploy
|
||||
tmux
|
||||
busybox
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
{ lib, config, globals, dns, confLib, ... }:
|
||||
let
|
||||
inherit (confLib.gen { name = "radicale"; port = 8000; }) servicePort serviceName serviceUser serviceGroup serviceDomain serviceAddress serviceProxy proxyAddress4 proxyAddress6;
|
||||
sopsFile = "${config.node.secretsDir}/secrets2.yaml";
|
||||
# sopsFile = config.node.secretsDir + "/secrets2.yaml";
|
||||
inherit (config.swarselsystems) sopsFile;
|
||||
|
||||
cfg = config.services.${serviceName};
|
||||
in
|
||||
|
|
@ -100,7 +101,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = false;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = true;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
{ lib, config, globals, dns, confLib, ... }:
|
||||
let
|
||||
inherit (confLib.gen { name = "snipeit"; port = 80; }) servicePort serviceName serviceUser serviceGroup serviceDomain serviceAddress serviceProxy proxyAddress4 proxyAddress6;
|
||||
sopsFile = "${config.node.secretsDir}/secrets2.yaml";
|
||||
# sopsFile = config.node.secretsDir + "/secrets2.yaml";
|
||||
inherit (config.swarselsystems) sopsFile;
|
||||
|
||||
serviceDB = "snipeit";
|
||||
|
||||
|
|
@ -55,7 +56,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
oauth2.enable = false;
|
||||
|
|
|
|||
|
|
@ -125,7 +125,8 @@ in
|
|||
};
|
||||
virtualHosts = {
|
||||
"${serviceDomain}" = {
|
||||
enableACME = true;
|
||||
useACMEHost = globals.domains.main;
|
||||
|
||||
forceSSL = true;
|
||||
acmeRoot = null;
|
||||
locations = {
|
||||
|
|
|
|||
|
|
@ -1,94 +1,144 @@
|
|||
{ self, lib, config, confLib, globals, ... }:
|
||||
{ self, lib, pkgs, config, confLib, nodes, globals, ... }:
|
||||
let
|
||||
wgInterface = "wg0";
|
||||
inherit (confLib.gen { name = "wireguard"; port = 52829; user = "systemd-network"; group = "systemd-network"; }) servicePort serviceName serviceUser serviceGroup;
|
||||
|
||||
inherit (config.swarselsystems) sopsFile;
|
||||
inherit (config.swarselsystems.server.wireguard) peers isClient isServer;
|
||||
wgSopsFile = self + "/secrets/repo/wg.yaml";
|
||||
inherit (config.swarselsystems.server.wireguard) peers isClient isServer serverName serverNetConfigPrefix ifName;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
swarselmodules.${serviceName} = lib.mkEnableOption "enable ${serviceName} settings";
|
||||
swarselmodules.server.${serviceName} = lib.mkEnableOption "enable ${serviceName} settings";
|
||||
swarselsystems.server.wireguard = {
|
||||
isServer = lib.mkEnableOption "set this as a wireguard server";
|
||||
isClient = lib.mkEnableOption "set this as a wireguard client";
|
||||
serverName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
};
|
||||
serverNetConfigPrefix = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "${if nodes.${serverName}.config.swarselsystems.isCloud then nodes.${serverName}.config.node.name else "home"}";
|
||||
readOnly = true;
|
||||
};
|
||||
ifName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = wgInterface;
|
||||
};
|
||||
peers = lib.mkOption {
|
||||
type = lib.types.listOf (lib.types.submodule {
|
||||
freeformType = lib.types.attrs;
|
||||
options = { };
|
||||
});
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
description = "Wireguard peer submodules as expected by systemd.network.netdevs.<name>.wireguardPeers";
|
||||
description = "Wireguard peer config names";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
config = lib.mkIf config.swarselmodules.${serviceName} {
|
||||
config = lib.mkIf config.swarselmodules.server.${serviceName} {
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
wireguard-tools
|
||||
];
|
||||
|
||||
sops = {
|
||||
secrets = {
|
||||
wireguard-private-key = { inherit sopsFile; owner = serviceUser; group = serviceGroup; mode = "0600"; };
|
||||
wireguard-home-preshared-key = { inherit sopsFile; owner = serviceUser; group = serviceGroup; mode = "0600"; };
|
||||
};
|
||||
# create this secret only if this is a simple client with only one peer (the server)
|
||||
"wireguard-${serverName}-${config.node.name}-presharedKey" = lib.mkIf (isClient && peers == [ ]) { sopsFile = wgSopsFile; owner = serviceUser; group = serviceGroup; mode = "0600"; };
|
||||
}
|
||||
# create these secrets only if this host has multiple peers
|
||||
// lib.optionalAttrs (peers != [ ]) (builtins.listToAttrs (map
|
||||
(clientName: {
|
||||
name = "wireguard-${config.node.name}-${clientName}-presharedKey";
|
||||
value = { sopsFile = wgSopsFile; owner = serviceUser; group = serviceGroup; mode = "0600"; };
|
||||
})
|
||||
peers));
|
||||
};
|
||||
|
||||
networking = {
|
||||
firewall.checkReversePath = lib.mkIf isClient "loose";
|
||||
firewall.allowedUDPPorts = [ servicePort ];
|
||||
nat = {
|
||||
enable = true;
|
||||
enableIPv6 = true;
|
||||
externalInterface = "ens6";
|
||||
internalInterfaces = [ wgInterface ];
|
||||
};
|
||||
# nat = lib.mkIf (config.swarselsystems.isCloud && isServer) {
|
||||
# enable = true;
|
||||
# enableIPv6 = true;
|
||||
# externalInterface = "enp0s6";
|
||||
# internalInterfaces = [ ifName ];
|
||||
# };
|
||||
# interfaces.${ifName}.mtu = 1280; # the default (1420) is not enough!
|
||||
};
|
||||
|
||||
systemd.network = {
|
||||
enable = true;
|
||||
|
||||
networks."50-${wgInterface}" = {
|
||||
matchConfig.Name = wgInterface;
|
||||
|
||||
networkConfig = {
|
||||
IPv4Forwarding = true;
|
||||
IPv6Forwarding = true;
|
||||
networks."50-${ifName}" = {
|
||||
matchConfig.Name = ifName;
|
||||
linkConfig = {
|
||||
MTUBytes = 1408; # TODO: figure out where we lose those 12 bits (8 from pppoe maybe + ???)
|
||||
};
|
||||
|
||||
address = [
|
||||
"${globals.networks."${config.swarselsystems.server.netConfigPrefix}-wg".hosts.${config.node.name}.cidrv4}"
|
||||
"${globals.networks."${config.swarselsystems.server.netConfigPrefix}-wg".hosts.${config.node.name}.cidrv6}"
|
||||
];
|
||||
# networkConfig = lib.mkIf (config.swarselsystems.isCloud && isServer) {
|
||||
# IPv4Forwarding = true;
|
||||
# IPv6Forwarding = true;
|
||||
# };
|
||||
|
||||
address =
|
||||
if isServer then [
|
||||
globals.networks."${config.swarselsystems.server.netConfigPrefix}-wg".hosts.${config.node.name}.cidrv4
|
||||
globals.networks."${config.swarselsystems.server.netConfigPrefix}-wg".hosts.${config.node.name}.cidrv6
|
||||
] else [
|
||||
globals.networks."${serverNetConfigPrefix}-wg".hosts.${config.node.name}.cidrv4
|
||||
globals.networks."${serverNetConfigPrefix}-wg".hosts.${config.node.name}.cidrv6
|
||||
];
|
||||
};
|
||||
|
||||
netdevs."50-wg0" = {
|
||||
netdevs."50-${ifName}" = {
|
||||
netdevConfig = {
|
||||
Kind = "wireguard";
|
||||
Name = wgInterface;
|
||||
Name = ifName;
|
||||
};
|
||||
|
||||
wireguardConfig = {
|
||||
ListenPort = lib.mkIf isServer servicePort;
|
||||
|
||||
# ensure file is readable by `systemd-network` user
|
||||
PrivateKeyFile = config.age.secrets.wg-key-vps.path;
|
||||
PrivateKeyFile = config.sops.secrets.wireguard-private-key.path;
|
||||
|
||||
# To automatically create routes for everything in AllowedIPs,
|
||||
# add RouteTable=main
|
||||
# RouteTable = "main";
|
||||
RouteTable = lib.mkIf isClient "main";
|
||||
|
||||
# FirewallMark marks all packets send and received by wg0
|
||||
# with the number 42, which can be used to define policy rules on these packets.
|
||||
# FirewallMark = 42;
|
||||
};
|
||||
wireguardPeers = peers ++ lib.optionals isClient [
|
||||
wireguardPeers = lib.optionals isClient [
|
||||
{
|
||||
PublicKey = builtins.readFile "${self}/secrets/public/wg/${config.node.name}.pub";
|
||||
PresharedKeyFile = config.sops.secrets."${config.node.name}-presharedKey".path;
|
||||
Endpoint = "${globals.hosts.${config.node.name}.wanAddress4}:${toString servicePort}";
|
||||
PublicKey = builtins.readFile "${self}/secrets/public/wg/${serverName}.pub";
|
||||
PresharedKeyFile = config.sops.secrets."wireguard-${serverName}-${config.node.name}-presharedKey".path;
|
||||
Endpoint = "server.${serverName}.${globals.domains.main}:${toString servicePort}";
|
||||
# Access to the whole network is routed through our entry node.
|
||||
# AllowedIPs =
|
||||
# (optional (networkCfg.cidrv4 != null) networkCfg.cidrv4)
|
||||
# ++ (optional (networkCfg.cidrv6 != null) networkCfg.cidrv6);
|
||||
# PersistentKeepalive = 25;
|
||||
AllowedIPs =
|
||||
let
|
||||
wgNetwork = globals.networks."${serverNetConfigPrefix}-wg";
|
||||
in
|
||||
(lib.optional (wgNetwork.cidrv4 != null) wgNetwork.cidrv4)
|
||||
++ (lib.optional (wgNetwork.cidrv6 != null) wgNetwork.cidrv6);
|
||||
}
|
||||
];
|
||||
] ++ lib.optionals isServer (map
|
||||
(clientName: {
|
||||
PublicKey = builtins.readFile "${self}/secrets/public/wg/${clientName}.pub";
|
||||
PresharedKeyFile = config.sops.secrets."wireguard-${config.node.name}-${clientName}-presharedKey".path;
|
||||
# PersistentKeepalive = 25;
|
||||
AllowedIPs =
|
||||
let
|
||||
clientInWgNetwork = globals.networks."${config.swarselsystems.server.netConfigPrefix}-wg".hosts.${clientName};
|
||||
in
|
||||
(lib.optional (clientInWgNetwork.ipv4 != null) (lib.net.cidr.make 32 clientInWgNetwork.ipv4))
|
||||
++ (lib.optional (clientInWgNetwork.ipv6 != null) (lib.net.cidr.make 128 clientInWgNetwork.ipv6));
|
||||
})
|
||||
peers);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue