fix(gateway): resolve vhost sentinel on the REST API update path#2178
fix(gateway): resolve vhost sentinel on the REST API update path#2178mehara-rothila wants to merge 1 commit into
Conversation
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Warning Review limit reached
More reviews will be available in 58 minutes and 42 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR fixes a bug where REST API updates do not resolve vhost sentinels (such as 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@gateway/it/features/vhost-routing-single.feature`:
- Around line 205-244: Add a new post-update check that targets the sandbox
vhost and asserts the sandbox upstream changed: after the existing update of
"vhost-single-sentinel-update-v1.0" and the main-host checks, add steps that
clear headers, set the request host to the sandbox vhost (the resolved host used
by the API, same resolved host used for sandbox traffic), send a GET to
"http://localhost:8080/vhost-single-sentinel-update/v1.0/whoami" and assert the
response is successful, valid JSON, and that the JSON response field "path"
equals "/sandbox-v2/whoami" to prove the sandbox route was updated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 77378254-c16a-402a-a0ca-baf7d781d68d
📒 Files selected for processing (3)
gateway/gateway-controller/pkg/service/restapi/service.gogateway/gateway-controller/pkg/utils/api_deployment.gogateway/it/features/vhost-routing-single.feature
f6de19d to
f609e38
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
♻️ Duplicate comments (1)
gateway/it/features/vhost-routing-single.feature (1)
237-249:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd sandbox-host verification after the update.
The scenario verifies that the main vhost route still works after the update (lines 237-243) and that the sentinel literal is rejected (lines 245-249), but it does not verify that the sandbox vhost route still works after the update. Since the update includes
sandbox: _gateway_default_, the scenario should also assert that the sandbox route resolves correctly after the update.📋 Suggested addition
After line 243, add a sandbox-host check similar to the main-host check:
When I clear all headers And I set request host to "api.wso2.com" And I send a GET request to "http://localhost:8080/vhost-single-sentinel-update/v1.0/whoami" Then the response should be successful And the response should be valid JSON And the JSON response field "path" should be "/whoami" + # Verify sandbox route also works after update + When I clear all headers + And I set request host to "api-sandbox.wso2.com" + And I send a GET request to "http://localhost:8080/vhost-single-sentinel-update/v1.0/whoami" + Then the response should be successful + And the response should be valid JSON + And the JSON response field "environment" should be "sandbox" + And the JSON response field "path" should be "/sandbox/whoami" + # The sentinel string itself must NOT be a usable host after the update When I clear all headers And I set request host to "_gateway_default_" And I send a GET request to "http://localhost:8080/vhost-single-sentinel-update/v1.0/after-update" Then the response status code should be 404🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@gateway/it/features/vhost-routing-single.feature` around lines 237 - 249, Add a sandbox-host verification after the existing main-host check: mirror the block that uses the route "vhost-single-sentinel-update" and the step "And I set request host to ..." by clearing headers, setting the request host to the sandbox host that should resolve to _gateway_default_ (the same resolved sandbox host used elsewhere in the feature), sending a GET to "http://localhost:8080/vhost-single-sentinel-update/v1.0/whoami", and asserting the response is successful, valid JSON, and that the JSON "path" equals "/whoami".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@gateway/it/features/vhost-routing-single.feature`:
- Around line 237-249: Add a sandbox-host verification after the existing
main-host check: mirror the block that uses the route
"vhost-single-sentinel-update" and the step "And I set request host to ..." by
clearing headers, setting the request host to the sandbox host that should
resolve to _gateway_default_ (the same resolved sandbox host used elsewhere in
the feature), sending a GET to
"http://localhost:8080/vhost-single-sentinel-update/v1.0/whoami", and asserting
the response is successful, valid JSON, and that the JSON "path" equals
"/whoami".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b6375870-1bc8-44d6-b4bc-ef1eee5be68d
📒 Files selected for processing (4)
gateway/gateway-controller/pkg/api/handlers/handlers_test.gogateway/gateway-controller/pkg/service/restapi/service.gogateway/gateway-controller/pkg/utils/api_deployment.gogateway/it/features/vhost-routing-single.feature
🚧 Files skipped from review as they are similar to previous changes (2)
- gateway/gateway-controller/pkg/utils/api_deployment.go
- gateway/gateway-controller/pkg/service/restapi/service.go
The update path rendered and validated without resolving the gateway-default vhost sentinel, so an updated API stored the raw marker and became unreachable. Resolve on update, mirroring the create path. Fixes wso2#2174
f609e38 to
9f457ff
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Purpose
The REST API update (PUT) path did not resolve the gateway-default vhost sentinel (
_gateway_default_) before persisting and rendering. The create path already resolves and stores the concrete hostname; the update path stored the raw sentinel.Because the xDS route builders use the stored vhost value literally (they fall back to the router default only for blank values, not the sentinel), an updated API ended up with the literal string
_gateway_default_as its vhost and became unreachable (404). The update itself returned success, so the failure was silent until traffic was tested.Fixes #2174.
Goals
Make the update path resolve the gateway-default vhost sentinel and persist the concrete hostname, exactly as the create path does, so editing an API that uses the gateway default does not silently break its routing. A redeploy then refreshes the vhost to the current default: an API on the default stays frozen until it is redeployed.
Approach
ResolveVhostSentinelsfrompkg/utils/api_deployment.go(a thin wrapper over the existing internalresolveVhostSentinels) so the service layer can call it.RestAPIService.Update(pkg/service/restapi/service.go) before template rendering and validation, mirroring the create path, and re-syncSourceConfigurationso the resolved value is what gets persisted.User stories
As an API developer, when I edit an API that was deployed using the gateway default vhost (for example to change a backend URL), the API should keep serving on its resolved hostname instead of silently dropping off its address.
Documentation
N/A. This is a bug fix with no change to the user-facing API contract or configuration.
Automation tests
Security checks
Samples
Gateway config:
An API deployed with the default vhost, then updated (the platform sends the marker on every deploy and update):
Before: after an update,
vhosts.mainwas stored as the literal_gateway_default_and the API returned 404. After: the update resolves it toapis.acme.comand the API keeps serving.Notes
Related PRs
N/A.
Test environment
gateway/gateway-controller/go.mod)