Skip to content
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
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4213,6 +4213,7 @@
./hosts/gamebox/disko.nix
./hosts/gamebox/streaming.nix
./hosts/gamebox/em-ci.nix
./hosts/gamebox/tc-fallback-proxy.nix
];
};

Expand Down
65 changes: 65 additions & 0 deletions hosts/gamebox/tc-fallback-proxy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Fallback egress for devbox's TeamClaude: a CONNECT-only proxy that devbox can
# use (TeamClaude "upstreamProxy") when its own route to Cloudflare-fronted
# api.anthropic.com is broken. On 2026-12-02 devbox's (Hetzner HEL1) traffic to
# Cloudflare anycast landed on Cloudflare's Moscow site and went dark in
# 20-70 s clusters for two hours; gamebox egresses from the US and reaches a
# different Cloudflare site (EWR), so it is a path that fails independently.
# Bead workstation-dkts.3.
#
# Exposure: only devbox may use it, only CONNECT, only for the two hosts
# TeamClaude needs (the API, and platform.claude.com for OAuth token refresh),
# only on 443.
# - Listen 0.0.0.0, not the tailnet address: binding 100.x races tailscaled
# at boot. Explicit (not unset) so a failed bind is fatal and the unit
# restarts until it binds; with Listen unset tinyproxy starts "successfully"
# on [::] alone when the v4 bind fails. Reachability is bounded by the
# firewall: port 8888 is NOT in allowedTCPPorts and only tailscale0 is
# trusted (configuration.nix), so the guest Wi-Fi cannot reach it; the
# em-ci containers' egress fence drops host-local destinations.
# - Allow: devbox's tailnet IPv4 only; everything else gets 403. If devbox is
# re-registered on the tailnet this address changes and the fallback
# answers 403 exactly when it is needed: update it here.
# - FilterURLs + anchored host:443 patterns + FilterDefaultDeny: the filter
# runs on the request target, which for CONNECT is "host:port" and for
# plain-HTTP proxying starts with "http://", so plain HTTP is refused by
# construction (ConnectPort alone does not cover it).
# The tunnel is end-to-end TLS (TeamClaude speaks TLS to Anthropic through the
# CONNECT), so this box never sees tokens or prompts.
{ pkgs, ... }:

let
devboxTailnetIp = "100.73.94.25";
filter = pkgs.writeText "tc-fallback-proxy-filter" ''
^api\.anthropic\.com:443$
^platform\.claude\.com:443$
'';
in
{
services.tinyproxy = {
enable = true;
settings = {
Listen = "0.0.0.0"; # see the exposure note above
Port = 8888;
Allow = devboxTailnetIp;
ConnectPort = 443;
Filter = "${filter}";
FilterURLs = true;
FilterType = "ere";
FilterDefaultDeny = true;
# TeamClaude streams long responses; an idle tunnel must survive a slow
# model turn.
Timeout = 900;
# TeamClaude opens one tunnel per upstream request (no keep-alive pool);
# at the limit tinyproxy spins and queues rather than refusing, so leave
# ample headroom. Threads are cheap.
MaxClients = 256;
DisableViaHeader = true;
LogLevel = "Connect";
};
};

# Restart=on-failure with the default 100 ms delay can trip the start-limit
# on a transient error and leave the proxy dead; back off instead.
systemd.services.tinyproxy.serviceConfig.RestartSec = "5s";
systemd.services.tinyproxy.unitConfig.StartLimitIntervalSec = 0;
}
Loading