refactor: abstract vhost allow rules with new allowVPN, allowLAN, allowWAN options

This commit is contained in:
Giulio De Pasquale (aider) 2025-04-26 16:58:23 +01:00
parent 88990545ed
commit 87511fc1b8
12 changed files with 44 additions and 47 deletions

View File

@ -52,6 +52,24 @@ in
description = "IP address or CIDR block to allow."; description = "IP address or CIDR block to allow.";
}; };
allowVPN = mkOption {
type = types.bool;
default = false;
description = "If set to true, allow VPN traffic.";
};
allowLAN = mkOption {
type = types.bool;
default = false;
description = "If set to true, allow LAN traffic.";
};
allowWAN = mkOption {
type = types.bool;
default = false;
description = "If set to true, allow WAN traffic. If false, deny all WAN traffic.";
};
path = mkOption { path = mkOption {
type = types.str; type = types.str;
default = ""; default = "";
@ -62,12 +80,6 @@ in
default = true; default = true;
description = "Force the use of recommended proxy configuration."; description = "Force the use of recommended proxy configuration.";
}; };
allowWAN = mkOption {
type = types.bool;
default = false;
description = "If set to false, deny all WAN traffic.";
};
}; };
}); });
default = { }; default = { };
@ -92,7 +104,8 @@ in
recommendedProxySettings = location.recommendedProxySettings; recommendedProxySettings = location.recommendedProxySettings;
extraConfig = '' extraConfig = ''
${concatMapStringsSep "\n" (allowCIDR: "allow ${allowCIDR};") location.allow} ${concatMapStringsSep "\n" (allowCIDR: "allow ${allowCIDR};") location.allow}
${optionalString location.allowLan ''allow ${config.pepe.core.network.interfaces.${config.pepe.core.network.interfaceTypes.lan}.net};''} ${optionalString location.allowLAN ''allow ${config.pepe.core.network.interfaces.${config.pepe.core.network.interfaceTypes.lan}.net};''}
${optionalString location.allowVPN ''allow ${config.pepe.core.network.interfaces.${config.pepe.core.network.interfaceTypes.vpn}.net};''}
${optionalString (!location.allowWAN) "deny all;"} ${optionalString (!location.allowWAN) "deny all;"}
'' + location.extraConfig; '' + location.extraConfig;
}) })

View File

@ -26,10 +26,8 @@ in
dnsInterfaces = [ interfaceTypes.vpn ]; dnsInterfaces = [ interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = 6767; port = 6767;
allowLan = true; allowLAN = true;
allow = [ allowVPN = true;
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };

View File

@ -22,6 +22,8 @@ in
dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = config.services.gitea.settings.server.HTTP_PORT; port = config.services.gitea.settings.server.HTTP_PORT;
allowLAN = true;
allowVPN = true;
allowWAN = true; allowWAN = true;
}; };
}; };

View File

@ -27,9 +27,9 @@ in
locations."/" = { locations."/" = {
host = "[::1]"; host = "[::1]";
port = config.services.immich.port; port = config.services.immich.port;
allowLan = true; allowLAN = true;
allowVPN = true;
allowWAN = true; allowWAN = true;
allow = [ interfaces.${interfaceTypes.vpn}.net ];
proxyWebsockets = true; proxyWebsockets = true;
extraConfig = '' extraConfig = ''
# allow large file uploads # allow large file uploads

View File

@ -29,19 +29,15 @@ in
locations = { locations = {
"/" = { "/" = {
port = 8096; port = 8096;
allowLan = true; allowLAN = true;
allow = [ allowVPN = true;
interfaces.${interfaceTypes.vpn}.net
];
}; };
"/socket" = { "/socket" = {
port = 8096; port = 8096;
allowLan = true; allowLAN = true;
allowVPN = true;
proxyWebsockets = true; proxyWebsockets = true;
allow = [
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };
}; };

View File

@ -25,10 +25,8 @@ in
dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = config.services.jellyseerr.port; port = config.services.jellyseerr.port;
allowLan = true; allowLAN = true;
allow = [ allowVPN = true;
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };
}; };

View File

@ -26,10 +26,8 @@ in
dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = 8686; port = 8686;
allowLan = true; allowLAN = true;
allow = [ allowVPN = true;
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };

View File

@ -50,7 +50,8 @@ in
dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = 4533; port = 4533;
allowLan = true; allowLAN = true;
allowVPN = true;
allowWAN = true; allowWAN = true;
}; };
}; };

View File

@ -26,10 +26,8 @@ in
dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 6789; port = 6789;
allowLan = true; allowLAN = true;
allow = [ allowVPN = true;
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };

View File

@ -25,11 +25,9 @@ in
dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 9696; port = 9696;
allowLan = true; allowLAN = true;
allowVPN = true;
proxyWebsockets = true; proxyWebsockets = true;
allow = [
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };

View File

@ -25,11 +25,8 @@ in
dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 7878; port = 7878;
allowLan = true; allowLAN = true;
allowVPN = true;
allow = [
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };

View File

@ -25,10 +25,8 @@ in
dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 8989; port = 8989;
allowLan = true; allowLAN = true;
allow = [ allowVPN = true;
interfaces.${interfaceTypes.vpn}.net
];
}; };
}; };