diff --git a/changelog.d/fixed-15432-broker-no-proxy.md b/changelog.d/fixed-15432-broker-no-proxy.md new file mode 100644 index 0000000000..bb2ccdb382 --- /dev/null +++ b/changelog.d/fixed-15432-broker-no-proxy.md @@ -0,0 +1 @@ +- Agents now bypass the hive proxy for the host of `OMP_AUTH_BROKER_URL` (added to `NO_PROXY`), so a credential broker on a private address such as the Docker bridge gateway is no longer refused by the plain-forward guard and the agent CLI no longer exits on start ([#15432](https://github.com/hivecommons/hive/issues/15432)). diff --git a/src/crux/agent/coverage_boost_test.go b/src/crux/agent/coverage_boost_test.go index 2dea3e55f1..ec674b8f83 100644 --- a/src/crux/agent/coverage_boost_test.go +++ b/src/crux/agent/coverage_boost_test.go @@ -268,6 +268,7 @@ func TestAgentEnvPairs_NonInference_NoProxyLoopback(t *testing.T) { Config: config.AgentConfig{Backend: "claude", Model: "sonnet"}, } + t.Setenv("OMP_AUTH_BROKER_URL", "") count := 0 for _, p := range m.agentEnvPairs(ap) { if p.Key == "NO_PROXY" { diff --git a/src/crux/agent/manager_env.go b/src/crux/agent/manager_env.go index b1c769e7dc..2ea197e540 100644 --- a/src/crux/agent/manager_env.go +++ b/src/crux/agent/manager_env.go @@ -3,6 +3,7 @@ package agent import ( "encoding/json" "fmt" + "net/url" "os" "os/exec" "path/filepath" @@ -16,6 +17,23 @@ import ( "github.com/hivecommons/hive/crux/jev" ) +// agentNoProxy returns the NO_PROXY value handed to agents: loopback plus the +// host of OMP_AUTH_BROKER_URL, and only that host. An unset, unparsable or +// host-less URL adds nothing, so every other private address stays behind the +// proxy's destination guard. +func agentNoProxy() string { + const loopback = "127.0.0.1,localhost,::1" + u, err := url.Parse(strings.TrimSpace(os.Getenv("OMP_AUTH_BROKER_URL"))) + if err != nil { + return loopback + } + host := u.Hostname() + if host == "" || strings.ContainsAny(host, ", \t") { + return loopback + } + return loopback + "," + host +} + func (m *Manager) buildBootstrapPrompt(agent *AgentProcess) string { // No boot prompt — the governor's first eval cycle (10s after startup) // kicks all due agents via BuildKickMessages with fully substituted @@ -253,7 +271,10 @@ func (m *Manager) agentEnvPairs(agent *AgentProcess) []agentEnvPair { vars = append(vars, agentEnvPair{"HTTP_PROXY", proxyURL, false}) // Loopback must never traverse the hive proxy for any backend: an agent // polling a local dev server would otherwise get proxy-side dial errors (#14076). - vars = append(vars, agentEnvPair{"NO_PROXY", "127.0.0.1,localhost,::1", false}) + // The credential broker (OMP_AUTH_BROKER_URL) usually sits on a private + // address the proxy's plain-forward guard refuses, so its host bypasses + // the proxy too (#15432). + vars = append(vars, agentEnvPair{"NO_PROXY", agentNoProxy(), false}) vars = append(vars, agentEnvPair{"HIVE_PROXY_AGENT", agent.Name, false}) vars = append(vars, agentEnvPair{"GIT_TERMINAL_PROMPT", "0", false}) vars = append(vars, agentEnvPair{"NODE_EXTRA_CA_CERTS", proxyCACertPath, false}) diff --git a/src/crux/agent/manager_env_noproxy_test.go b/src/crux/agent/manager_env_noproxy_test.go new file mode 100644 index 0000000000..bc0a0d3a25 --- /dev/null +++ b/src/crux/agent/manager_env_noproxy_test.go @@ -0,0 +1,26 @@ +package agent + +import "testing" + +func TestAgentNoProxy(t *testing.T) { + const loop = "127.0.0.1,localhost,::1" + cases := []struct { + name, url, want string + }{ + {"unset", "", loop}, + {"ipv4 with port", "http://172.18.0.1:18765/v1/snapshot", loop + ",172.18.0.1"}, + {"hostname", "http://broker.internal:8080", loop + ",broker.internal"}, + {"ipv6 literal", "http://[fd00::1]:18765", loop + ",fd00::1"}, + {"invalid", "http://[::1", loop}, + {"no host", "/just/a/path", loop}, + {"opaque", "mailto:x@y", loop}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Setenv("OMP_AUTH_BROKER_URL", tc.url) + if got := agentNoProxy(); got != tc.want { + t.Errorf("agentNoProxy() = %q, want %q", got, tc.want) + } + }) + } +}