Skip to content

Dynamic Endpoint policy does not apply upstream base path #1999

@renuka-fernando

Description

@renuka-fernando

Description

The dynamic-endpoint policy routes a request to a named upstreamDefinitions entry via the SDK UpstreamName field. When the targeted upstream definition has a base path (e.g. http://backend:9080/foo), the gateway switches to the correct upstream cluster but does not apply the upstream's base path correctly — the request reaches the backend at the wrong path.

Two root causes in gateway/gateway-runtime/policy-engine/internal/kernel/translator.go:

  • upstreamDefinitionPaths is looked up by the raw upstream-definition name, but the controller keys that map by the full cluster key (upstream_<Kind>_<UUID>_<name>). The lookup always misses, so the base path is never resolved and defaults to /.
  • Even when the base path is resolved, the routed path is built by naive string concatenation that does not strip the API context, producing e.g. /foo/<context>/v1.0/items instead of /foo/items.

A fix is implemented in commit 5653ee6d0 on branch dynamic-ep, along with an integration test (gateway/it/features/dynamic-endpoint.feature).

Steps to reproduce

  1. Deploy a RestApi with an upstreamDefinitions entry whose URL has a base path, e.g. http://sample-backend:9080/foo.
  2. Attach the dynamic-endpoint policy to an operation with targetUpstream pointing at that definition.
  3. Invoke the operation through the gateway.

Expected behavior

The request reaches the backend at <upstream-base-path>/<operation-path> — e.g. /foo/items.

Actual behavior

The upstream base path is dropped, and the API context is left in the forwarded path — e.g. /foo/dynamic-endpoint-routes/v1.0/items.

Version

No response

Related Issue

No response

Metadata

Metadata

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions