[Bug]: dynamic-endpoint (named upstream selection) is silently ignored when the API has no upstreamDefinitions
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- api, backend-api-design
Research direction
Start by reading gateway/gateway-controller/pkg/transform/restapi.go and gateway/gateway-controller/pkg/xds/translator.go, where the issue identifies the conditions controlling cluster_header routing. Trace how API and operation policies are represented there, then check the gateway-controller tests for route translation. Done means a named upstream selection without definitions or a sandbox returns 503 instead of reaching the main upstream.
Written by the indexing model from the issue text.
Description
Please select the area the issue is related to
Gateway
Please select the aspect the issue is related to
Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)
Description
Problem in the component (gateway-controller)
The gateway-controller only builds an API's routes with Envoy cluster_header routing (the cluster is read from the x-target-upstream header) when the API has upstreamDefinitions or a sandbox upstream:
gateway/gateway-controller/pkg/transform/restapi.go:useClusterHeader := hasUpstreamDefinitions || hasSandboxgateway/gateway-controller/pkg/xds/translator.go:useClusterHeader := hasUpstreamDefinitions || hasSandboxForClusterHeader
When neither exists, every route is bound to the static main cluster and x-target-upstream is ignored. A policy that selects an upstream by name therefore has no effect, and the request is silently answered by the main upstream.
This is a gateway routing problem, not a policy problem: any policy that selects an upstream by name through UpstreamName is affected, and dynamic-endpoint is where it was found.
How the problem was found
While building an integration test suite for the dynamic-endpoint policy (gateway-controllers repo), one scenario checks that an API whose operation names an upstream that cannot be resolved never falls back to the main backend. The same check passes when the API has upstreamDefinitions (an unknown or malformed name returns 503 and the main upstream never receives the request). It fails when the API has no upstreamDefinitions: the main upstream answers with 200. It fails on gateway 1.2.0 and on the current latest image.
Current behaviour of the dynamic-endpoint policy
- With
upstreamDefinitionspresent: the policy setsUpstreamName, the policy engine resolves it to the clusterupstream_<Kind>_<apiId>_<name>, setsx-target-upstream, and the route uses it. A name with no matching definition gives 503. - Without
upstreamDefinitions(and without a sandbox): the selection is ignored and the main upstream serves the request (200). Nothing in the response or at deploy time tells the caller the policy did nothing.
Expected behaviour
A request must never reach the main upstream because a named selection could not be honoured. With a dynamic-endpoint policy attached and no matching upstream definition, the gateway should refuse the request (503), the same as it does when definitions exist but the name does not match.
Suggested fix
Also enable cluster_header routing when the API, or any of its operations, attaches the dynamic-endpoint policy. A small patch for this exists and makes the scenario pass; it can be raised as a PR.
Steps to Reproduce
-
Start a gateway (for example the 1.2.0 images) and two simple HTTP backends that echo the request path:
backend-main:5000andbackend-alt:5001. -
Deploy an API that has no
upstreamDefinitions(the management API base is/api/management/v1on 1.2.0 andlatest; 1.1.0 and older use/api/management/v0.9):curl -u admin:<password> -X POST http://localhost:9090/api/management/v1/rest-apis \ -H 'Content-Type: application/yaml' --data-binary @- <<'YAML' apiVersion: gateway.api-platform.wso2.com/v1 kind: RestApi metadata: name: dynamic-no-definitions spec: displayName: dynamic-no-definitions version: v1.0 context: /dynamic-no-definitions/$version upstream: main: url: http://backend-main:5000 operations: - method: GET path: /probe policies: - name: dynamic-endpoint version: v1 params: targetUpstream: alt-upstream YAML -
Call the route:
curl -i http://localhost:8080/dynamic-no-definitions/v1.0/probeActual:
200, served bybackend-main.
Expected:503;backend-mainmust not receive the request. -
For contrast, update the same API (
PUT /api/management/v1/rest-apis/dynamic-no-definitions) with
upstreamDefinitions: [{name: alt-upstream, basePath: /alt, upstreams: [{url: http://backend-alt:5001}]}]added underspec.
The request is now routed tobackend-altwith the/altbase path, and changingtargetUpstreamto a name that is not defined returns503. So the route behaves correctly oncecluster_headerrouting is on.
Severity Level of the Issue
Severity/Major
Environment Details (with versions)
Gateway 1.2.0 and latest (main) images, Docker, sqlite. Reproduced with the gateway-controller management API.
- Dominant language
- Go
- Stars
- 85
- Forks
- 137
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 247
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wso2/api-platform
-
Area/DeveloperPortal Aspect/UI Severity/Minor Type/Bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
wso2/api-platform#4369 ·
Maintainers usually reply within 1 day
-
[Bug]: host-rewrite policy documentation lists fewer allowed host characters than the policy acceptsOpenArea/Policies Aspect/Other Severity/Trivial Type/Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
wso2/api-platform#4355 ·
Maintainers usually reply within 1 day
-
Area/Gateway Aspect/API Severity/Minor Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wso2/api-platform#4348 ·
Maintainers usually reply within 1 day
-
Aspect/AI Aspect/API. Severity/Major
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
wso2/api-platform#4343 ·
Maintainers usually reply within 1 day
-
Area/Policies Aspect/Configuration Severity/Minor Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
wso2/api-platform#4330 ·
Maintainers usually reply within 1 day
All issues in wso2/api-platform
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Inconsistency between golang and cue in specPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
security
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Tencent/LoopForge#1087 · 1 comment ·
Maintainers usually reply within 1 day