[Bug]: dynamic-endpoint (named upstream selection) is silently ignored when the API has no upstreamDefinitions

Aperta
#4,324 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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

Aspect/API Severity/Major Type/Bug
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 || hasSandbox
  • gateway/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 upstreamDefinitions present: the policy sets UpstreamName, the policy engine resolves it to the cluster upstream_<Kind>_<apiId>_<name>, sets x-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
  1. Start a gateway (for example the 1.2.0 images) and two simple HTTP backends that echo the request path: backend-main:5000 and backend-alt:5001.

  2. Deploy an API that has no upstreamDefinitions (the management API base is /api/management/v1 on 1.2.0 and latest; 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
    
  3. Call the route:

    curl -i http://localhost:8080/dynamic-no-definitions/v1.0/probe
    

    Actual: 200, served by backend-main.
    Expected: 503; backend-main must not receive the request.

  4. 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 under spec.
    The request is now routed to backend-alt with the /alt base path, and changing targetUpstream to a name that is not defined returns 503. So the route behaves correctly once cluster_header routing 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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wso2/api-platform

Tutte le issue di wso2/api-platform

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.