{ config, ... }: # Tailnet door to luna's Honcho (honcho.nix) for Claude Code on terra # (hosts/terra/claude-honcho.nix). Honcho itself stays on loopback with auth # off, so Hermes and honcho-console need no key; this bearer token is the only # credential, and it reaches luna's workspace only. 8099 stays closed in the # firewall: tailscale0 only, like honcho-console. let port = 8099; in { imports = [ ../../services/network/caddy.nix ]; # Fails closed: an unset token must not turn "Bearer " into the password. services.caddy.virtualHosts.":${toString port}".extraConfig = '' @allowed { expression `{env.HONCHO_GATE_TOKEN} != "" && {http.request.header.Authorization} == "Bearer " + {env.HONCHO_GATE_TOKEN}` path /v3/workspaces /v3/workspaces/luna/* not path /v3/workspaces/luna/webhooks* } # Workspace get-or-create only; listing, keys and other workspaces stay out. @workspaceCreate { path /v3/workspaces not method POST } handle @workspaceCreate { respond 403 } handle @allowed { reverse_proxy 127.0.0.1:8000 } handle { respond 403 } ''; services.caddy.environmentFile = config.sops.templates."honcho-gate.env".path; # Same value in secrets/terra.yaml, where the Claude Code plugin sends it. sops.secrets.honcho_gate_token.restartUnits = [ "caddy.service" ]; sops.templates."honcho-gate.env" = { content = "HONCHO_GATE_TOKEN=${config.sops.placeholder.honcho_gate_token}\n"; restartUnits = [ "caddy.service" ]; }; }