Repository navigation
Description
Summary
Behind an MCP gateway that dials ShipLean on its in-cluster service name, the URLs ShipLean hands to agents still point at that service name, even on a build that includes #17. That covers upload_url from attach_file, download_url from read_attachment, and every open_url link. A laptop can't resolve the name, so curl -T <file> '<upload_url>' fails with Could not resolve host. The same request works if you swap in the public host by hand.
#17 added this rule: when base_url is blank, use the last X-Forwarded-Host from a trusted peer, and ignore *.svc. When that rule doesn't apply, ShipLean silently falls back to the dialed host, which it already knows is a cluster service name. Nothing in the logs, /health or the admin settings says why, so the first anyone hears of it is an agent failing to upload.
Steps to reproduce
- Run ShipLean in a cluster with
instance_settings.base_urlblank. - Put an MCP gateway in front that forwards
/mcptohttp://shiplean.<namespace>.svc:8080. Then either:- the gateway's address isn't in
SHIPLEAN_TRUSTED_PROXIES(it's another pod, not loopback), or - the gateway doesn't send
X-Forwarded-Host.
- the gateway's address isn't in
- From an agent, call
attach_filewithoutbase64.
Expected: upload_url is on the public host the agent connected to (for example https://shiplean.example.com/api/uploads/<token>). Or, if ShipLean can't work that host out, it says so clearly.
Actual: upload_url is http://shiplean.<namespace>.svc:8080/api/uploads/<token>. open_url in every MCP reply uses the same host.
Seen on a deployment running d1a95b8, which includes #17. Replacing the host with the public one makes the upload succeed (200, file attached). So the token, the route and the proxy skip-list are fine; only the published origin is wrong.
Why it's easy to miss
RequestOrigin.OftrustsX-Forwarded-Hostonly from loopback orSHIPLEAN_TRUSTED_PROXIES. In a cluster the gateway is never loopback, so with the default settings the header is always ignored.IsClusterServicealready knows*.svccan't be opened from outside, but that knowledge is only used to reject the forwarded header, not to flag the fallback.- Publish MCP file URLs on the host the request came in on #17's test plan has its post-deploy check unticked, and the unit tests cover the trusted-peer case but not a cluster topology where the peer is untrusted.
Suggested fix
Any one of these would have caught it. The first two are cheap.
- Say why. When the published origin falls back to a host that
IsClusterServicematches, log one warning per process naming the cause: noX-Forwarded-Host, peer<ip>not inSHIPLEAN_TRUSTED_PROXIES, or the forwarded host was itself*.svc. Also tell the operator to setbase_urlor trust the gateway. - Surface it. Add a flag to
/healthand the admin settings page, for example"publicOrigin": "unknown: set base_url", whenbase_urlis blank and recent agent requests arrived on a cluster service name. - Don't hand out a URL that can't work. When the only origin available is a cluster service name, either return the path plus a message ("ask your admin to set the base URL"), or fail
attach_filewithoutbase64with an error that points atbase_urland tells the agent to sendbase64instead. - Docs. Add a "Behind a gateway" checklist to
docs/mcp.mdanddocs/auth.md. The simplest route is to setbase_url. The alternative is to trust the gateway's network inSHIPLEAN_TRUSTED_PROXIESand check that it sendsX-Forwarded-HostandX-Forwarded-Proto. - Test. Add a
RequestOriginTests/AttachUploadTestscase for "peer not trusted, dialed host is*.svc", asserting the warning (or the error from option 3).
Workaround
Set base_url to the public origin in the instance settings. That changes the token audience, so every agent has to reconnect. Or, on the client side, replace the host in upload_url before running curl.
Activity
Refuse agent file URLs on a cluster service name, and say why (#30)