Skip to content

Agent URLs (upload_url, download_url, open_url) fall back to the cluster service name behind a gateway, with no warning #28

Closed

Description

@joeldickson

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

  1. Run ShipLean in a cluster with instance_settings.base_url blank.
  2. Put an MCP gateway in front that forwards /mcp to http://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.
  3. From an agent, call attach_file without base64.

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.Of trusts X-Forwarded-Host only from loopback or SHIPLEAN_TRUSTED_PROXIES. In a cluster the gateway is never loopback, so with the default settings the header is always ignored.
  • IsClusterService already knows *.svc can'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.

  1. Say why. When the published origin falls back to a host that IsClusterService matches, log one warning per process naming the cause: no X-Forwarded-Host, peer <ip> not in SHIPLEAN_TRUSTED_PROXIES, or the forwarded host was itself *.svc. Also tell the operator to set base_url or trust the gateway.
  2. Surface it. Add a flag to /health and the admin settings page, for example "publicOrigin": "unknown: set base_url", when base_url is blank and recent agent requests arrived on a cluster service name.
  3. 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_file without base64 with an error that points at base_url and tells the agent to send base64 instead.
  4. Docs. Add a "Behind a gateway" checklist to docs/mcp.md and docs/auth.md. The simplest route is to set base_url. The alternative is to trust the gateway's network in SHIPLEAN_TRUSTED_PROXIES and check that it sends X-Forwarded-Host and X-Forwarded-Proto.
  5. Test. Add a RequestOriginTests / AttachUploadTests case 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions