feat(networks): add portable sandbox port mappings#291
Conversation
|
PR Title: feat(networks): add portable sandbox port mappings Commit: 本PR引入了沙箱网络(sandbox networks)功能,核心变更包括:
整体架构清晰,测试覆盖较全。但在 Compose 规范的 published port 校验逻辑中存在一个漏判:当两条 |
| result := make([]PublishedPortSpec, 0, len(values)) | ||
| seen := make(map[string]struct{}, len(values)) | ||
| for index, value := range values { | ||
| protocol, err := normalizeTCPProtocol(value.Protocol) |
There was a problem hiding this comment.
Compose 规范中固定 published port 的重复冲突未被检测
在 normalizePublishedPorts 中,published port 的去重键包含了 target 端口:key := fmt.Sprintf("%s/%d/%d", hostIP, value.Published, value.Target)。这导致当两条 ports 条目具有相同的 host IP 和相同的固定 published 端口、但 target 端口不同时,不会被识别为重复。例如 "127.0.0.1:8080:80" 与 "127.0.0.1:8080:81" 在 Compose 规范化阶段不会报错,但在运行时 Docker 会尝试将同一个 host IP:port 绑定到两个不同的容器端口,导致容器创建失败。
Problem code:
Changed code at pkg/compose/network.go:176-185
Recommendation:
修改 normalizePublishedPorts 中的去重逻辑:仅当 published != 0(固定端口)时,使用 hostIP + published 作为去重键;动态端口可保持原有逻辑。并补充对应的单元测试。
Summary
networks, agent network attachments, internalexpose, and externalportsconfigurationport_mappingnetworks logical: they do not create project Docker networks or install firewall policyexposelong syntax to fix an internal listener port withhost_port; omitted listener ports remain dynamically allocatedExample:
Named networks currently record logical membership and annotate bindings. The driver does not provide DNS, transparent
api:8080routing, or enforced cross-network isolation.Testing
task lint0 issues.scripts/test-coverage.sh, with deployment/runtime/LLM override variables removed)deploy/install_test.shpassed in a non-root temporary checkoutscripts/test-compose-kvm-config.shpassedscripts/test-installer-assets.shpassedtask buildgo test ./pkg/compose ./pkg/runs ./pkg/networks ./pkg/agentcompose/apiThe literal root-run
task testcommand stops in the installerincomplete-rollbackcase because that test useschmod a-wto force restoration failure and root can bypass the directory permission. The branch does not modifydeploy/. Running the same deployment gate as a non-root user exercised the intended failure path and passed; the remaining coverage gate passed under the normal build user.Microsandbox real-runtime resume also exposed an existing lifecycle failure (
disk image ... is already attached with an incompatible disk mode). It is outside the network data path and was not changed in this PR.Checklist