Add a WAF
This commit is contained in:
parent
a2453054fd
commit
96c3ae2de0
10 changed files with 84 additions and 16 deletions
|
|
@ -16,6 +16,6 @@
|
||||||
group = "caddy";
|
group = "caddy";
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${domain}".extraConfig = "reverse_proxy unix/${socket}";
|
caddy.wafHosts."${domain}".extraConfig = "reverse_proxy unix/${socket}";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,6 @@ in {
|
||||||
bridgeOrigin = "https://${domain}";
|
bridgeOrigin = "https://${domain}";
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${domain}".extraConfig = "reverse_proxy 127.0.0.1:8081";
|
caddy.wafHosts."${domain}".extraConfig = "reverse_proxy 127.0.0.1:8081";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,54 @@
|
||||||
{pkgs, ...}: {
|
{
|
||||||
networking.firewall.allowedTCPPorts = [443];
|
config,
|
||||||
services.caddy = {
|
pkgs,
|
||||||
enable = true;
|
lib,
|
||||||
email = "henry@henryhiles.com";
|
...
|
||||||
|
}: {
|
||||||
|
config = {
|
||||||
|
networking.firewall.allowedTCPPorts = [443];
|
||||||
|
services.caddy = {
|
||||||
|
enable = true;
|
||||||
|
email = "henry@henryhiles.com";
|
||||||
|
|
||||||
package = pkgs.caddy.withPlugins {
|
globalConfig = "order coraza_waf first";
|
||||||
plugins = ["github.com/ggicci/caddy-jwt@v1.1.0"];
|
|
||||||
hash = "sha256-sdhX/dAQ7lIxBo/ZW6XYX8SRuacLO9HobtIVKD/cw0o=";
|
virtualHosts = lib.mapAttrs (_: hostCfg:
|
||||||
|
hostCfg
|
||||||
|
// {
|
||||||
|
extraConfig = ''
|
||||||
|
route {
|
||||||
|
coraza_waf {
|
||||||
|
load_owasp_crs
|
||||||
|
directives `
|
||||||
|
Include @coraza.conf-recommended
|
||||||
|
Include @crs-setup.conf.example
|
||||||
|
Include @owasp_crs/*.conf
|
||||||
|
|
||||||
|
SecRuleRemoveById 920420
|
||||||
|
SecRuleRemoveById 911100
|
||||||
|
SecRuleEngine On
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
${hostCfg.extraConfig or ""}
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
config.services.caddy.wafHosts;
|
||||||
|
|
||||||
|
package = pkgs.caddy.withPlugins {
|
||||||
|
plugins = ["github.com/ggicci/caddy-jwt@v1.1.0" "github.com/corazawaf/coraza-caddy/v2@v2.1.0"];
|
||||||
|
hash = "sha256-1TmIs8CWMlNHF4NRqj7/W/pqRUIpcOFbJGALqPINVtk=";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
options.services.caddy.wafHosts = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (lib.types.submodule {
|
||||||
|
options.extraConfig = lib.mkOption {
|
||||||
|
type = lib.types.lines;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
keyFile = config.services.livekit.keyFile;
|
keyFile = config.services.livekit.keyFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${domain}".extraConfig = ''
|
caddy.wafHosts."${domain}".extraConfig = ''
|
||||||
root * ${pkgs.element-call}
|
root * ${pkgs.element-call}
|
||||||
route {
|
route {
|
||||||
respond /config.json `${builtins.toJSON {
|
respond /config.json `${builtins.toJSON {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
nginx = null;
|
nginx = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${domain}".extraConfig = ''
|
caddy.wafHosts."${domain}".extraConfig = ''
|
||||||
encode zstd gzip
|
encode zstd gzip
|
||||||
header {
|
header {
|
||||||
-Server
|
-Server
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${domain}".extraConfig = ''
|
caddy.wafHosts."${domain}".extraConfig = ''
|
||||||
respond /robots.txt <<EOF
|
respond /robots.txt <<EOF
|
||||||
User-agent: *
|
User-agent: *
|
||||||
Disallow: /*/*/archive/
|
Disallow: /*/*/archive/
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${subdomain}".extraConfig = "reverse_proxy 127.0.0.3:6167";
|
caddy.wafHosts."${subdomain}".extraConfig = "reverse_proxy 127.0.0.3:6167";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
clients/quadraticserver/mailserver.nix
Normal file
26
clients/quadraticserver/mailserver.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
# service = let
|
||||||
|
# domain = "federated.nexus";
|
||||||
|
# in {
|
||||||
|
# stalwart-mail = {
|
||||||
|
# enable = true;
|
||||||
|
# openFirewall = true;
|
||||||
|
|
||||||
|
# settings = {};
|
||||||
|
# };
|
||||||
|
# caddy = {
|
||||||
|
# enable = true;
|
||||||
|
# wafHosts = {
|
||||||
|
# "mail.example.org" = {
|
||||||
|
# extraConfig = "reverse_proxy http://127.0.0.1:8080";
|
||||||
|
# serverAliases = [
|
||||||
|
# "mta-sts.${domain}"
|
||||||
|
# "autoconfig.${domain}"
|
||||||
|
# "autodiscover.${domain}"
|
||||||
|
# "webadmin.${domain}"
|
||||||
|
# ];
|
||||||
|
# };
|
||||||
|
# };
|
||||||
|
# };
|
||||||
|
# };
|
||||||
|
}
|
||||||
|
|
@ -107,7 +107,7 @@
|
||||||
|
|
||||||
caddy = {
|
caddy = {
|
||||||
environmentFile = config.age.secrets."oidcJwtSecretEnv.age".path;
|
environmentFile = config.age.secrets."oidcJwtSecretEnv.age".path;
|
||||||
virtualHosts."${domain}".extraConfig = let
|
wafHosts."${domain}".extraConfig = let
|
||||||
auth = "https://auth.federated.nexus";
|
auth = "https://auth.federated.nexus";
|
||||||
in ''
|
in ''
|
||||||
handle_errors 401 {
|
handle_errors 401 {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
caddy.virtualHosts."${domain}".extraConfig = "reverse_proxy 127.0.0.2:8000";
|
caddy.wafHosts."${domain}".extraConfig = "reverse_proxy 127.0.0.2:8000";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue