[Bug]: dynamic-endpoint (named upstream selection) is silently ignored when the API has no upstreamDefinitions
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- api, backend-api-design
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Go
- Stelle
- 85
- Fork
- 137
- Merge medio
- 1g 12h
- PR unite (30g)
- 247
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di wso2/api-platform
-
Area/DeveloperPortal Aspect/UI Severity/Minor Type/Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
wso2/api-platform#4369 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: host-rewrite policy documentation lists fewer allowed host characters than the policy acceptsApertaArea/Policies Aspect/Other Severity/Trivial Type/Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
wso2/api-platform#4355 ·
I maintainer di solito rispondono entro 1 giorno
-
Area/Gateway Aspect/API Severity/Minor Type/Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
wso2/api-platform#4348 ·
I maintainer di solito rispondono entro 1 giorno
-
Aspect/AI Aspect/API. Severity/Major
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
wso2/api-platform#4343 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: content-length-guardrail policy accepts a non-string streamingJsonPath at API creationApertaArea/Policies Aspect/Configuration Severity/Minor Type/Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
wso2/api-platform#4330 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di wso2/api-platform
Issue simili
-
benchmark
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
mozilla-ai/cq#601 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation migration
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno