Repository navigation
fix: Restrict server listening to loopback for security; update CPU and TPU server configurations - #117
Conversation
…nd TPU server configurations
There was a problem hiding this comment.
Code Review
This pull request restricts CPU and TPU servers to listen on loopback (127.0.0.1) instead of 0.0.0.0, and updates the evaluation server to resolve local IPs to 127.0.0.1. It also updates get_local_cpu_port to exclude TPU VMs. A review comment suggests caching the result of get_local_ip() in eval_server.py to avoid inefficient, blocking network calls inside a loop.
| ip = backend_config["ip"] | ||
| # CPU/TPU servers only listen on loopback, so reach local ones via | ||
| # 127.0.0.1 even when the config lists this machine's network IP. | ||
| if ip in ["localhost", get_local_ip()]: | ||
| ip = "127.0.0.1" |
There was a problem hiding this comment.
Calling get_local_ip() inside a loop can be highly inefficient and slow down server startup, as get_local_ip() performs a blocking network socket connection to 8.8.8.8. We should cache the resolved local IP address on the Evaluator instance so that it is only fetched once.
ip = backend_config["ip"]
# CPU/TPU servers only listen on loopback, so reach local ones via
# 127.0.0.1 even when the config lists this machine's network IP.
local_ip = getattr(self, "_local_ip", None) or get_local_ip()
self._local_ip = local_ip
if ip in ["localhost", local_ip]:
ip = "127.0.0.1"There was a problem hiding this comment.
The _load_backends only execute once and adds little overhead.
Bind CPU/TPU execution servers to loopback
Fixes an unauthenticated remote code execution vulnerability.
cpu_server.pyandtpu_server.pyrun submitted Python code with no authentication, and they listened on0.0.0.0. Anyone who could reach ports 5463/5464 could run arbitrary code on the host.Changes
cpu_server.py,tpu_server.py: bind127.0.0.1instead of0.0.0.0.eval_server.py: connect to backends on this machine through127.0.0.1, even wheneval_config.yamllists the VM's network IP (whichprepare_maxkernel.shgenerates).server_config.py: skip CPU backends with atpu_vmblock when deciding which local servers to start, matching the existing TPU logic.