[Bug]: Updating a REST API on the gateway doesn't resolve its vhosts, so _gateway_default_ is stored as a hostname

Open Beginner friendly
#4,167 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
api, backend

Research direction

Read gateway/gateway-controller/pkg/service/restapi/service.go, especially RestAPIService.Update and the create path through DeployAPIConfiguration; compare how each handles vhosts. Then inspect gateway/gateway-controller/pkg/utils/api_deployment.go and its resolveVhostSentinels function. Done means updates resolve _gateway_default_ and missing vhosts to the current gateway defaults and GET returns the resolved values; check for existing REST API update tests to confirm this behavior.

Written by the indexing model from the issue text.

Description

Area/Gateway 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

When a REST API is created on the gateway, its vhosts are resolved at deploy time: _gateway_default_, or a missing vhosts block, becomes the gateway's current default hosts. The resolved values are stored, so a later change to the gateway defaults doesn't move the API (discussion #369).

Updating the API through the gateway's REST API (PUT /rest-apis/{id}) skips that step:

  • With vhosts.main: _gateway_default_: the placeholder is stored literally, as a hostname. The API stops answering on the default hosts.
  • With no vhosts block: nothing is stored. The API keeps answering on the defaults only because the router falls back to the live default. So it follows the next config change, which is what deploy-time resolution is meant to prevent, and GET shows no vhosts.

Observed (gateway with router.vhosts.main.default = "*.wso2.com" and router.vhosts.sandbox.default = "*-sandbox.wso2.com")

  1. POST /rest-apis with no vhosts: GET /rest-apis/{id} shows spec.vhosts.main *.wso2.com and spec.vhosts.sandbox *-sandbox.wso2.com, and a request with Host: api.wso2.com answers 200.
  2. PUT /rest-apis/{id} with vhosts: {"main": "_gateway_default_"}: GET shows spec.vhosts.main _gateway_default_, and the same request now answers 404.
  3. PUT /rest-apis/{id} with no vhosts: GET shows no spec.vhosts at all.

Expected
An update resolves vhosts the same way a create does. _gateway_default_ and a missing vhosts block become the current gateway defaults, which are stored and shown by GET.

Cause
Create goes through DeployAPIConfiguration (gateway/gateway-controller/pkg/service/restapi/service.go:174), which calls resolveVhostSentinels (gateway/gateway-controller/pkg/utils/api_deployment.go:312). RestAPIService.Update (pkg/service/restapi/service.go:320) parses the body and saves it without that call. The event gateway's WebSub update does resolve vhosts, because it goes through DeployAPIConfiguration.

Steps to Reproduce
  1. Start a gateway with [router.vhosts.main] default = "*.wso2.com".
  2. Create a REST API with no vhosts through POST /rest-apis. A request with Host: api.wso2.com answers 200.
  3. Update it through PUT /rest-apis/{id} with "vhosts": {"main": "_gateway_default_"}.
  4. GET /rest-apis/{id} shows _gateway_default_, and the request with Host: api.wso2.com answers 404.
  5. Update it again with no vhosts: GET shows no vhosts.
Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)

Current main (e90cde473). Platform-api and gateway built from source and run by the IT suite (tests/framework), on macOS with Rancher Desktop.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.