fix(proxy): route custom ports through Rocklet instead of direct connect#1093
Open
alibabarock wants to merge 1 commit into
Open
fix(proxy): route custom ports through Rocklet instead of direct connect#1093alibabarock wants to merge 1 commit into
alibabarock wants to merge 1 commit into
Conversation
898e21b to
75005ea
Compare
Problem:
When users specify a custom port (not 8080) in HTTP/WebSocket proxy requests,
the proxy attempts to connect directly to host_ip:{custom_port}. This fails
because arbitrary container ports are not mapped to the host network.
Root Cause:
- sandbox_proxy_service.http_proxy() line 939-946
- sandbox_proxy_service.get_sandbox_websocket_url() line 757-762
Both methods construct URLs like http://{host_ip}:{custom_port}/... directly,
but only the default SERVER port (8080) is mapped from container to host.
Solution:
1. Add proxy endpoints to Rocklet (local_api.py):
- /proxy/{port}/{path} for HTTP
- /proxy/{port}/{path} for WebSocket
These endpoints run inside the container on Port.PROXY (22555) and can
access localhost:{custom_port} reliably.
2. Modify sandbox_proxy_service.py to route custom ports through Rocklet:
- When port is None or 8080: use direct connection (backward compatible)
- When port is custom (e.g. 9000): route through {rocklet_port}/proxy/{port}/{path}
3. Add comprehensive tests for routing logic
Impact:
Users can now expose services running on arbitrary ports inside sandboxes
to external clients, not just the default 8080 port.
fixes alibaba#1092
75005ea to
73a62f3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When users specify a custom port (not the default 8080) in HTTP or WebSocket proxy requests via Path/Header/Query parameters, the proxy attempts to connect directly to
host_ip:{custom_port}. This fails because arbitrary container ports are not mapped to the host network.Root Cause
In
sandbox_proxy_service.py:http_proxy(): When a custom port is specified, it constructstarget_url = f"http://{host_ip}:{port}/..."directlyget_sandbox_websocket_url(): Same issue for WebSocket connectionsHowever, only the default SERVER port (8080) is mapped from container to host. Custom ports like 9000, 3000 exist inside the container but are not accessible via
host_ip:9000from outside.Solution
1. Add proxy endpoints to Rocklet (
rock/rocklet/local_api.py)/proxy/{port}/{path}for HTTP requests/proxy/{port}/{path}for WebSocket connectionsThese endpoints run inside the container on Port.PROXY (22555) and can access
localhost:{custom_port}reliably.2. Modify
sandbox_proxy_service.pyto route custom ports through RockletNoneor8080: use direct connection (backward compatible)9000): route through{rocklet_port}/proxy/{port}/{path}3. Add tests
Comprehensive tests for routing logic in
tests/unit/sandbox/test_proxy_custom_port_routing.py.Impact
Users can now expose services running on arbitrary ports inside sandboxes to external clients, not just the default 8080 port. This enables scenarios like running multiple services on different ports within a single sandbox.
Testing
fixes #1092