Gate the vhosts without their own sign-in with oauth2-proxy, which signs in with Pocket ID and allows members of the `admins` group. Each gated vhost serves its own `/oauth2/` endpoints with a host-only session cookie, so other `.nul.ie` sites never receive it. Sessions last a week, and a refresh token lets oauth2-proxy check back with Pocket ID every hour without a passkey. Add `my.pocket-id`, which declares Pocket ID groups and OIDC clients in Nix; `pocket-id-sync` applies them through the API with a static API key that nginx keeps from outside requests. This lets apps move to Pocket ID with their client defined next to them, with secrets from `slop secret generate`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
239 lines
7.5 KiB
Nix
239 lines
7.5 KiB
Nix
{ lib, ... }:
|
|
let
|
|
inherit (lib.my) net;
|
|
inherit (lib.my.c) pubDomain;
|
|
inherit (lib.my.c.nginx) baseHttpConfig;
|
|
inherit (lib.my.c.colony) domain prefixes;
|
|
in
|
|
{
|
|
nixos.systems.middleman = { config, ... }: {
|
|
system = "x86_64-linux";
|
|
nixpkgs = "mine";
|
|
rendered = config.configuration.config.my.asContainer;
|
|
|
|
assignments = {
|
|
internal = {
|
|
name = "middleman-ctr";
|
|
inherit domain;
|
|
ipv4.address = net.cidr.host 2 prefixes.ctrs.v4;
|
|
ipv6 = {
|
|
iid = "::2";
|
|
address = net.cidr.host 2 prefixes.ctrs.v6;
|
|
};
|
|
};
|
|
};
|
|
|
|
configuration = { lib, pkgs, config, assignments, allAssignments, ... }:
|
|
let
|
|
inherit (lib) mkMerge mkIf;
|
|
inherit (lib.my) networkdAssignment;
|
|
in
|
|
{
|
|
imports = [ ./auth.nix ./vhosts.nix ];
|
|
|
|
config = mkMerge [
|
|
{
|
|
my = {
|
|
deploy.enable = false;
|
|
server.enable = true;
|
|
network.bbr = true;
|
|
|
|
secrets = {
|
|
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAQM9U1e/XcUCyMJITrpAHjAGahpqkZCmtX6pJkYzuks";
|
|
files = {
|
|
"pdns-file-records.key" = {
|
|
owner = "acme";
|
|
group = "acme";
|
|
};
|
|
"middleman/cloudflare-credentials.conf" = {
|
|
owner = "acme";
|
|
group = "acme";
|
|
};
|
|
"middleman/mailcow-ssh.key" = {
|
|
owner = "acme";
|
|
group = "acme";
|
|
mode = "400";
|
|
};
|
|
"middleman/htpasswd" = {
|
|
owner = "nginx";
|
|
group = "nginx";
|
|
};
|
|
"librespeed.toml" = { };
|
|
};
|
|
};
|
|
|
|
firewall = {
|
|
tcp.allowed = [ "http" "https" 8448 ];
|
|
extraRules = ''
|
|
table inet nat {
|
|
chain postrouting {
|
|
oifname host0 snat ip6 to ${assignments.internal.ipv6.address}
|
|
}
|
|
}
|
|
'';
|
|
};
|
|
|
|
librespeed = {
|
|
frontend.servers = [
|
|
{
|
|
name = "Amsterdam, Netherlands";
|
|
server = "//librespeed.${domain}";
|
|
}
|
|
];
|
|
backend = {
|
|
enable = true;
|
|
extraSettingsFile = config.age.secrets."librespeed.toml".path;
|
|
};
|
|
};
|
|
|
|
paseo-relay.enable = true;
|
|
};
|
|
|
|
users = {
|
|
users = {
|
|
nginx.extraGroups = [ "acme" ];
|
|
};
|
|
};
|
|
|
|
systemd = {
|
|
network.networks."80-container-host0" = networkdAssignment "host0" assignments.internal;
|
|
services = {
|
|
# HACK: nginx seems to get stuck not being able to DNS early...
|
|
nginx = lib.my.systemdAwaitPostgres pkgs.postgresql "colony-psql";
|
|
};
|
|
};
|
|
|
|
security = {
|
|
acme = {
|
|
acceptTerms = true;
|
|
defaults = {
|
|
email = "dev@nul.ie";
|
|
#server = "https://acme-staging-v02.api.letsencrypt.org/directory";
|
|
server = "https://acme-v02.api.letsencrypt.org/directory";
|
|
reloadServices = [ "nginx" ];
|
|
dnsResolver = "8.8.8.8";
|
|
};
|
|
|
|
certs = {
|
|
"${config.networking.domain}" = {
|
|
extraDomainNames = [
|
|
"*.${config.networking.domain}"
|
|
];
|
|
dnsProvider = "exec";
|
|
environmentFile =
|
|
let
|
|
script = pkgs.writeShellScript "lego-update-int.sh" ''
|
|
case "$1" in
|
|
present)
|
|
cmd=add;;
|
|
cleanup)
|
|
cmd=del;;
|
|
*)
|
|
exit 1;;
|
|
esac
|
|
|
|
echo "$@"
|
|
exec ${pkgs.openssh}/bin/ssh \
|
|
-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
|
|
-i ${config.age.secrets."pdns-file-records.key".path} \
|
|
pdns-file-records@estuary-vm "${config.networking.domain}" "$cmd" "$2" "$3"
|
|
'';
|
|
in
|
|
pkgs.writeText "lego-exec-vars.conf" ''
|
|
EXEC_PROPAGATION_TIMEOUT=60
|
|
EXEC_POLLING_INTERVAL=2
|
|
EXEC_PATH=${script}
|
|
'';
|
|
};
|
|
"${pubDomain}" = {
|
|
extraDomainNames = [
|
|
"*.${pubDomain}"
|
|
"*.s3.${pubDomain}"
|
|
"*.slop.${pubDomain}"
|
|
];
|
|
dnsProvider = "cloudflare";
|
|
environmentFile = config.age.secrets."middleman/cloudflare-credentials.conf".path;
|
|
postRun =
|
|
let
|
|
sshKey = config.age.secrets."middleman/mailcow-ssh.key".path;
|
|
in
|
|
''
|
|
${pkgs.openssh}/bin/scp -i ${sshKey} key.pem fullchain.pem acme@mail.nul.ie:/tmp/
|
|
${pkgs.openssh}/bin/ssh -i ${sshKey} acme@mail.nul.ie mailcow-ssl-reload
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
programs = {
|
|
ssh.knownHostsFiles = [ lib.my.c.sshHostKeys.mail-vm ];
|
|
};
|
|
|
|
services = {
|
|
netdata = {
|
|
enable = true;
|
|
configDir = {
|
|
"go.d/nginxvts.conf" = pkgs.writeText "netdata-nginxvts.conf" ''
|
|
jobs:
|
|
- name: local
|
|
url: http://localhost/status/format/json
|
|
'';
|
|
};
|
|
};
|
|
|
|
nginx = {
|
|
enable = true;
|
|
enableReload = true;
|
|
additionalModules = with pkgs.nginxModules; [
|
|
vts
|
|
fancyindex
|
|
];
|
|
|
|
recommendedTlsSettings = true;
|
|
recommendedBrotliSettings = true;
|
|
# Uh so nginx is hanging with zstd enabled... maybe let's not for now
|
|
# recommendedZstdSettings = true;
|
|
clientMaxBodySize = "0";
|
|
serverTokens = true;
|
|
resolver = {
|
|
addresses = [ "[${allAssignments.estuary.base.ipv6.address}]" ];
|
|
valid = "5s";
|
|
};
|
|
proxyResolveWhileRunning = true;
|
|
workerProcesses = "auto";
|
|
|
|
# Based on recommended*Settings, but probably better to be explicit about these
|
|
appendHttpConfig = ''
|
|
${baseHttpConfig}
|
|
|
|
resolver_timeout 5s;
|
|
|
|
# caching
|
|
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=CACHE:10m inactive=7d max_size=4g;
|
|
|
|
vhost_traffic_status_zone;
|
|
|
|
map $upstream_status $nix_cache_control {
|
|
"~20(0|6)" "public, max-age=315360000, immutable";
|
|
}
|
|
map $upstream_status $nix_expires {
|
|
"~20(0|6)" "Thu, 31 Dec 2037 23:55:55 GMT";
|
|
}
|
|
'';
|
|
};
|
|
};
|
|
}
|
|
(mkIf config.my.build.isDevVM {
|
|
virtualisation = {
|
|
forwardPorts = [
|
|
{ from = "host"; host.port = 8080; guest.port = 80; }
|
|
{ from = "host"; host.port = 8443; guest.port = 443; }
|
|
];
|
|
};
|
|
})
|
|
];
|
|
};
|
|
};
|
|
}
|