snowfield/machines/gustave/pages.nix

123 lines
3.2 KiB
Nix
Raw Normal View History

2024-08-21 15:50:46 +02:00
{
2024-10-13 12:32:43 +02:00
lib,
pkgs,
config,
...
}:
2024-12-07 01:03:20 +01:00
let
allowedUpstream = "2a01:e0a:de4:a0e1:4bb5:9275:6010:e9b5/128";
in
2024-10-13 12:32:43 +02:00
{
2024-10-26 04:06:52 +02:00
age.secrets."pages-settings-file".file = ../../secrets/pages-settings-file.age;
2024-10-13 12:32:43 +02:00
2024-10-26 04:06:52 +02:00
services.codeberg-pages = {
enable = true;
package = pkgs.unstable.codeberg-pages.overrideAttrs (_: {
src = pkgs.fetchFromGitea {
domain = "codeberg.org";
owner = "Codeberg";
repo = "pages-server";
rev = "044c684a47853af53c660e454328348a49277c9c";
hash = "sha256-FZmz4pSSa+d9UGUZuK6ROktsoDtYL8xBl0eRtr/BAD0=";
2024-10-16 22:05:27 +02:00
};
vendorHash = "sha256-Zs900VVd9jZIoeVFv2SqD97hbTqv2JqroDUz8G3XbY0=";
patches = [
./update-lego.patch
];
2024-10-26 04:06:52 +02:00
});
2024-08-21 15:50:46 +02:00
2024-10-26 04:06:52 +02:00
settings = {
ACME_ACCEPT_TERMS = "true";
ACME_EMAIL = "acme@malka.sh";
2024-10-26 04:06:52 +02:00
DNS_PROVIDER = "gandiv5";
ENABLE_HTTP_SERVER = "false";
GITEA_ROOT = "http://127.0.0.1:3000";
2024-10-26 04:06:52 +02:00
PORT = "8010";
PAGES_DOMAIN = "luj-static.page";
RAW_DOMAIN = "raw.luj-static.page";
PAGES_BRANCHES = "pages,main,master";
USE_PROXY_PROTOCOL = "true";
LOG_LEVEL = "trace";
2024-10-16 22:05:27 +02:00
};
2024-08-21 15:50:46 +02:00
2024-10-26 04:06:52 +02:00
settingsFile = config.age.secrets."pages-settings-file".path;
};
2024-10-13 12:32:43 +02:00
2024-12-07 01:03:20 +01:00
networking.nftables.enable = true;
# Only requests from the router must be accepted by proxy protocol listeners
# in order to prevent ip spoofing.
networking.firewall.extraInputRules = ''
ip6 saddr ${allowedUpstream} tcp dport 444 accept
ip6 saddr ${allowedUpstream} tcp dport 8110 accept
'';
networking.firewall.allowedTCPPorts = [
8010
];
2024-10-26 04:06:52 +02:00
luj.nginx.enable = true;
services.nginx = {
appendHttpConfig = ''
2024-12-07 01:03:20 +01:00
set_real_ip_from ${allowedUpstream};
2024-10-26 04:06:52 +02:00
real_ip_header proxy_protocol;
'';
defaultListen = [
2024-12-07 01:03:20 +01:00
# proxy protocol listener with ipv6, which is what is used by the sniproxy
2024-10-16 22:05:27 +02:00
{
addr = "[::]";
port = 444;
2024-10-16 22:05:27 +02:00
ssl = true;
proxyProtocol = true;
2024-10-13 12:32:43 +02:00
}
2024-12-07 01:03:20 +01:00
# used for certificate requests with let's encrypt
2024-10-16 22:05:27 +02:00
{
addr = "[::]";
port = 80;
ssl = false;
}
2024-12-07 01:03:20 +01:00
# listener for ipv6 clients in private infra
{
2024-12-07 01:03:20 +01:00
addr = "[${config.machine.meta.ips.vpn.ipv6}]";
port = 443;
ssl = true;
}
2024-12-07 01:03:20 +01:00
# listener for ipv4 client in private infra
{
addr = config.machine.meta.ips.vpn.ipv4;
2024-12-07 01:03:20 +01:00
port = 443;
ssl = true;
}
# used for certificate request with internal CA
{
addr = "[${config.machine.meta.ips.vpn.ipv6}]";
port = 80;
2024-10-16 22:05:27 +02:00
ssl = false;
2024-08-21 15:50:46 +02:00
}
2024-10-16 22:05:27 +02:00
];
2024-08-21 15:50:46 +02:00
2024-12-07 01:03:20 +01:00
# Listen to ipv6 packets coming from the internet, check the SNI
# If they are one of the declared virtualHosts, forward them to the proxy protocol listener
# for that virtualHost, else forward them to the page server
2024-10-26 04:06:52 +02:00
streamConfig = ''
map $ssl_preread_server_name $sni_upstream {
hostnames;
default [::]:8010;
${lib.concatMapStringsSep "\n" (vhost: " ${vhost} [::0]:444;") (
2024-10-26 04:06:52 +02:00
lib.filter (e: e != "default") (lib.attrNames config.services.nginx.virtualHosts)
)}
}
2024-08-21 15:50:46 +02:00
2024-10-26 04:06:52 +02:00
server {
2024-12-07 01:03:20 +01:00
listen [${config.machine.meta.ips.public.ipv6}]:443;
2024-10-26 04:06:52 +02:00
ssl_preread on;
proxy_pass $sni_upstream;
proxy_protocol on;
}
2024-08-21 15:50:46 +02:00
2024-10-26 04:06:52 +02:00
'';
2024-10-16 22:05:27 +02:00
2024-08-21 15:50:46 +02:00
};
2024-08-21 15:50:46 +02:00
}