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

Đang mở Phù hợp với người mới
#4,167 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api, backend

Hướng nghiên cứu

Đọc gateway/gateway-controller/pkg/service/restapi/service.go, đặc biệt là RestAPIService.Update và luồng tạo thông qua DeployAPIConfiguration; so sánh cách mỗi luồng xử lý vhosts. Sau đó kiểm tra gateway/gateway-controller/pkg/utils/api_deployment.go và hàm resolveVhostSentinels trong tệp này. Công việc hoàn tất khi các lần cập nhật phân giải _gateway_default_ và các vhost bị thiếu thành giá trị mặc định hiện tại của gateway, còn GET trả về các giá trị đã phân giải; kiểm tra xem có các bài kiểm thử cập nhật REST API hiện có để xác nhận hành vi này hay không.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
85
Fork
137
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
247

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wso2/api-platform

Tất cả issue của wso2/api-platform

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.