Skip to content

Reapply "hydra-proxy: replace abuse handling with anubis" #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 27 additions & 36 deletions build/hydra-proxy.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
{
config,
lib,
pkgs,
...
}:

let
bannedUserAgentPatterns = [
"Trident/"
"Android\\s[123456789]\\."
"iPod"
"iPad\\sOS\\s"
"iPhone\\sOS\\s[23456789]"
"Opera/[89]"
# Chrome 134+
"(Chrome|CriOS)/(\\d\\d?\\.|1[012]|13[0123])"
# Firefox ESR 128 and Firefox 137+
"(Firefox|FxiOS)/(\\d\\d?\\.|1[01]|12[012345679]|13[0123456])"
"PPC\\sMac\\sOS"
"Windows\\sCE"
"Windows\\s95"
"Windows\\s98"
"Windows\\sNT\\s[12345]\\."
];
in
{
networking.firewall.allowedTCPPorts = [
80
443
9001
];

services.anubis.instances."hydra-server" = {
settings = {
TARGET = "http://127.0.0.1:3000";
BIND = ":3001";
BIND_NETWORK = "tcp";
METRICS_BIND = ":9001";
METRICS_BIND_NETWORK = "tcp";
};
};

services.nginx = {
enable = true;
enableReload = true;
Expand All @@ -47,18 +38,21 @@ in
worker_processes auto;
'';

appendHttpConfig = ''
map $http_x_from $upstream {
default "anubis";
nix.dev-Uogho3gi "hydra-server";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is the difference that's going to allow this to avoid the problem we ran into last time? (I don't understand it)

Copy link
Member

@Mic92 Mic92 May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this checking x-forwarded-for? This could need a comment because it's also not clear to me how it works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
'';

eventsConfig = ''
worker_connections 1024;
'';

appendHttpConfig = ''
map $http_user_agent $badagent {
default 0;
${lib.concatMapStringsSep "\n" (pattern: ''
~${pattern} 1;
'') bannedUserAgentPatterns}
}
'';
upstreams = {
anubis.servers."127.0.0.1:3001" = { };
hydra-server.servers."127.0.0.1:3000" = { };
};

virtualHosts."hydra.nixos.org" = {
forceSSL = true;
Expand All @@ -82,19 +76,16 @@ in
'';

locations."/" = {
proxyPass = "http://127.0.0.1:3000";
extraConfig = ''
if ($badagent) {
access_log /var/log/nginx/abuse.log;
return 403;
}
'';
proxyPass = "http://anubis";
};

locations."~ ^/build/\\d+/download/" = {
proxyPass = "http://hydra-server";
};

locations."/static/" = {
alias = "${config.services.hydra-dev.package}/libexec/hydra/root/static/";
};
};
};

}
3 changes: 2 additions & 1 deletion build/pluto/prometheus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
imports = [
./alertmanager.nix
./exporters/up.nix
./exporters/anubis.nix
./exporters/blackbox.nix
./exporters/channel.nix
./exporters/domain.nix
Expand All @@ -17,6 +17,7 @@
./exporters/owncast.nix
./exporters/postgresql.nix
./exporters/rasdaemon.nix
./exporters/up.nix
./exporters/zfs.nix
];

Expand Down
16 changes: 16 additions & 0 deletions build/pluto/prometheus/exporters/anubis.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
services.prometheus = {
scrapeConfigs = [
{
job_name = "anubis";
static_configs = [
{
targets = [
"hydra.nixos.org:9001"
];
}
];
}
];
};
}