Repository navigation
Description
Problem
devops sandbox network-policy (src/devops_cli/commands/sandbox.py:999-1053) and the MCP tool sandbox_network_policy (src/devops_cli/ai/mcp/server.py:1419-1446) print a Kubernetes NetworkPolicy for a sandbox pod. Isolated mode is deny-all (src/devops_cli/sandbox/models.py:339-340). The namespace and whitelist modes add a kube-dns rule on port 53 (models.py:138-151). The whitelist modes then add one rule whose peers are the resolved ipBlocks (models.py:230-264). That rule has no ports, so it opens every port and protocol to each listed address. Sandboxes still default to no network (models.py:269, :428).
-
Ports are dropped.
_extract_host_or_ipkeeps the host and drops the port (models.py:67-68,:80-81). Both builders emit{"to": [...]}with noports(models.py:237-244,:254-264). Measured on 9c879ae: the entrieshttps://1.1.1.1:8443and1.1.1.1:8443both yield{"to": [{"ipBlock": {"cidr": "1.1.1.1/32"}}]}. The MCP tool refuses/in whitelist items (server.py:111), so it cannot pass a URL. It does accepthost:port, and that loses its port the same way. An agent that asks for one port gets all of them. -
Public CIDR entries are not checked as ranges.
_resolve_public_hostadmits a network whenis_non_public_ipis false (models.py:174-184), and that function isnot addr.is_global(src/devops_cli/core/validation.py:107-117). For a network, Python'sis_globalonly asks whether the whole network sits inside one special-purpose block. A wide range that contains private blocks therefore counts as global. Measured on 9c879ae:devops sandbox network-policy --network-mode public_whitelist --public-whitelist 0.0.0.0/0exits 0 and emitsipBlock: {cidr: 0.0.0.0/0}.::/0,128.0.0.0/1(which contains 172.16.0.0/12 and 192.168.0.0/16) and8.0.0.0/5(which contains 10.0.0.0/8) are also admitted. Such a policy reaches the pod network, the API server and 169.254.169.254. The plan to "keep the resolved-/32 allowlist" holds only for host entries. -
No lane reaches the OTel collector. The cluster collector is the
otel-collectorrelease ofopen-telemetry/opentelemetry-collectorin namespaceotel(src/devops_cli/commands/k8s/stack_lifecycle.py:103-108,src/devops_cli/config/constants.py:826-827). That namespace already admits OTLP on 4317 and 4318 from every namespace (k8s/otel/networkpolicy.yaml:36-45), so only the sandbox's egress rule is missing. Jaeger runs in the same namespace and also listens on 4317 and 4318 (k8s/otel/jaeger.yaml:54,57). A selector on the namespace alone would let a sandbox bypass the collector. -
Containers get no trace context. When tracing is on,
run_subprocessandrun_subprocess_asyncwriteTRACEPARENTinto the child's environment (src/devops_cli/core/process.py:264,404) throughinject_trace_env(src/devops_cli/telemetry/tracer.py:815-824), which mutates the dict it is given. The two container builders pass onlyconfig.env:WorkloadSandboxEngine._build_create_kwargs(src/devops_cli/sandbox/engine.py:230,:247-253) andWorkloadSandboxRunner._network_create_kwargs(src/devops_cli/docker/sandbox.py:237-255).DockerEngineService.exec_in_containertakes no environment (src/devops_cli/docker/engine.py:401-412), andWorkloadSandboxEngine.execopens no span (sandbox/engine.py:423-453).grep -rn 'TRACEPARENT\|inject_env\|inject_trace_env' src/devops_cli/sandbox src/devops_cli/docker | wc -lprints 0.
What changed since this issue was written:
- feat(cli): ipv6 egress cidr fix and deny-class property tests for sandbox policy #701 (v0.2.24) fixed the IPv6 prefix bug, so every host entry now gets its family's full-length prefix. Line numbers moved.
- feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734 removed Squid. Nothing records denied egress, so the old fourth step, a Loki panel of
TCP_DENIEDrows, stays dropped. - Alertmanager is still disabled (
k8s/monitoring/prometheus-values.yaml:28-29), andgrep -rn 'alert:' k8s | wc -lstill prints 0. - A second Valkey,
valkey-runs, now exists. It sits outside thellmperimeter (k8s/llm/networkpolicy.yaml:18) and admits any source on 6379 behind a password (k8s/llm/valkey-runs.yaml:155-159). - The
llmperimeter now also admits Traefik (k8s/llm/networkpolicy.yaml:31-38). - None of the merges on 2026-10-02 changes the behaviour described here.
Enforcement:
- A NetworkPolicy only works if the CNI enforces it.
devops k8s bootstrapstarts minikube with no--cni(src/devops_cli/commands/k8s/cluster_runtime.py:95,100), but its help says Calico (src/devops_cli/lang/en/help.py:266). The previous body called this a separate item, but no such issue exists. - The homelab cluster is k3s, whose built-in policy controller enforces NetworkPolicy unless it is disabled. Nothing in the repository records how the cluster was installed.
Docker lanes: the whitelist modes refuse to start without an egress proxy (sandbox/engine.py:242-245, docker/sandbox.py:230-233). Since #734, no CLI option sets egress_proxy (models.py:272-275). Port scoping therefore changes only the emitted NetworkPolicy.
Out of scope:
- counting or alerting on blocked egress;
- the Docker egress-proxy path;
- the bootstrap CNI and its help text;
- comparing declared controls with enforced ones (feat(cli): sandbox enforcement audit declared vs engine vs enforced (
devops sandbox audit) #698).
Acceptance criteria
All four parts land in one pull request, in the order below.
Port scoping (sandbox/models.py)
- Each whitelist entry becomes its own egress rule with its own
ports. Entries never share a rule, so no address is opened on another entry's port. - The port comes from the entry:
scheme://host:port,host:portand[v6]:portuse the stated port.https://hostand a bare host, IP or CIDR use TCP 443.http://hostuses TCP 80.- A bare IPv6 address takes no port suffix and gets 443.
- These entries are refused with an error that names the entry, and the CLI exits 1:
- an entry with any other scheme and no port;
- a port outside 1-65535.
- Tests stub DNS with the
public_dnsfixture or a patchedsocket.getaddrinfo, and check:https://1.1.1.1:8443and1.1.1.1:8443give1.1.1.1/32on TCP 8443 only;http://example.comgives TCP 80, andexample.comgives TCP 443;[2606:4700::1]:8443gives2606:4700::1/128on TCP 8443;http://localhost:11434in the local whitelist gives127.0.0.1/32on TCP 11434;a.example:8443,b.examplegives two rules, and neither rule pairs A's addresses with 443 or B's with 8443.
- One test runs over every whitelist policy the tests generate. It asserts that every egress rule except the DNS rule has a non-empty
ports. - The
--public-whitelistand--local-whitelisthelp (commands/sandbox.py:1017-1026) states the port syntax and defaults. It also says to regenerate the policy when a name's addresses change.
Public CIDRs
- A public whitelist CIDR is admitted only if none of its addresses is non-public.
- Refused:
0.0.0.0/0,::/0,128.0.0.0/1,8.0.0.0/5and64:ff9b::/96. - Still admitted:
2606:4700::/48and140.82.112.0/20. The feat(cli): ipv6 egress cidr fix and deny-class property tests for sandbox policy #701 tests (tests/test_sandbox_networking.py:450-469) keep passing.
- Refused:
- The range check lives in
core/validation.pynext tois_non_public_ipand uses the same classification, so fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897's NAT64 handling covers it too.
Collector lane
devops sandbox network-policy --allow-collectorandsandbox_network_policy(allow_collector=True)add one egress rule with a single peer:- that peer has both
namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: otel}}andpodSelector: {matchLabels: {app.kubernetes.io/name: opentelemetry-collector, app.kubernetes.io/instance: otel-collector}}; - the rule's ports are TCP 4317 and 4318, and it has no
ipBlock; - the namespace and labels are constants next to
CONST_OTEL_COLLECTOR_NAMESPACE.
- that peer has both
- The flag is accepted with
sandbox_namespace,public_whitelistandlocal_whitelist. Withisolatedorbridgeit is refused with an error that names the modes it applies to. - Without the flag, no rule selects
otel. - No mode emits a rule for port 6379.
Container trace context
- With tracing enabled, both builders call
get_tracer().inject_trace_envon a copy ofconfig.env. That putsTRACEPARENT, andTRACESTATEwhen one is set, into the container's environment.- The deploy engine does this inside the
sandbox.deployspan, and the workload runner insidedocker.workload_sandbox.run. The injected parent id is that span's id. config.envis unchanged afterwards.- In proxy modes the proxy variables are still present.
- The deploy engine does this inside the
- With tracing disabled, the container's environment is exactly what it is today.
DockerEngineService.exec_in_containertakesenvironment: dict[str, str] | None = Noneand passes it toexec_run.WorkloadSandboxEngine.execopens asandbox.execspan and passes that span's context to the exec. Two execs in one sandbox carry different parent ids, and neither carries the context from deploy time.- These tests use the mocked Docker SDK and need no daemon.
General
- No test resolves a real name or opens a non-loopback socket.
uv run devops cipasses. - Generated docs are refreshed with
devops docs generate --sync-readme. - The pull request carries its task file and
changelog.d/702.md. It does not editCHANGELOG.mdordocs/ROADMAP.md. - Person-run check, on the homelab cluster:
- Apply a policy generated with
--public-whitelist 1.1.1.1:443to a test pod in a test namespace. - Confirm that
1.1.1.1:443connects and1.1.1.1:80times out. - Apply a policy generated with
--allow-collectorand confirm that an OTLP request reaches the collector. - Record the results in the task file. If port 80 connects, the cluster does not enforce NetworkPolicy, and the owner decides what follows.
- Apply a policy generated with
- Person-run check:
kubectl -n otel get pods --show-labelsshows the two collector labels the rule selects.
Key questions
- Which entry forms, and which defaults? Proposed: those listed in the acceptance criteria.
- Only TCP is supported. There is no UDP syntax, because no current use needs it.
- Both whitelists follow the same rules. A local entry such as
192.168.1.50opens every port today and will open only 443 unless it names a port. This is a deliberate break; pre-1.0, there is no shim.
- Should names still be resolved to
/32and/128when the policy is generated? The alternative is vibes'0.0.0.0/0 except RFC 1918. Proposed: keep resolving, because theexceptform admits every public host. A resolved address goes stale when DNS changes; the fix is to regenerate the policy, and the help says so. - Should the public whitelist keep CIDR entries? Proposed: yes, with the range check. feat(cli): ipv6 egress cidr fix and deny-class property tests for sandbox policy #701 kept them, and tests cover them.
- Should the MCP tool accept URLs and bracketed IPv6? Proposed: no. Its character check (
server.py:111) stays as it is, becausehostandhost:portcover what an agent needs, and MCP clients are untrusted. - Should MCP expose the collector lane? Proposed: yes. The tool only prints YAML, and a person or a pipeline applies it. The lane reaches one labelled pod on two ports.
- Can isolated mode have the collector lane? Proposed: no. Isolated means no egress. A sandbox that has to export telemetry uses
sandbox_namespacewith the lane. - Should there be a lane for the cache on port 6379? Proposed: no.
- The cache Valkey is inside the
llmperimeter, which admits only its own namespace,monitoringand Traefik (k8s/llm/networkpolicy.yaml:22-38). valkey-runsholds the shared run index, and a sandbox has no reason to reach it.
- The cache Valkey is inside the
- Should blocked egress raise an alert? Proposed: no.
- Since Squid was removed (feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734), nothing in the cluster records a denied connection.
- Under
--network=none, a failed connect never leaves the container. - Alerts fire into nothing: no Alertmanager, and k3s false positives #549 adds Alertmanager in v0.2.28. A denial counter would be its own item, if one is ever wanted.
- Should the bubblewrap host sandbox get trace context as well? It runs with
--clearenvand sets only its default environment plus the caller's (src/devops_cli/sandbox/host.py:379-389,:407). Proposed: no, not in this item.- The host sandbox runs with
--unshare-all, so no process inside it can export a span. - Its output is already captured under the caller's span.
- The host sandbox runs with
- Should the containers get an exporter endpoint? Proposed: no, this item only passes trace context.
- A workload that exports sets
OTEL_EXPORTER_OTLP_ENDPOINTthroughconfig.env. - Only bridge mode, or a pod with the collector lane, can reach a collector.
- A workload that exports sets
- Should this item repair the Docker whitelist path? Proposed: no. Those modes refuse to start without an egress proxy, and nothing has set one since feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734. Removing or replacing
egress_proxyis separate work. - Should the false Calico claim be fixed here? Proposed: no. It needs its own fix item: either pass a CNI that enforces policy, or correct the help text.
Depends on: #897 (v0.2.27). The 64:ff9b::/96 criterion uses its NAT64-aware classifier, and it lands first by release order.
Related: #701 (done in v0.2.24, full-length prefixes); #734 (done, Squid removed); #549 (v0.2.28, Alertmanager); #857 (v0.2.28, ToolAnnotations on the same MCP tool, no conflict); #698 (backlog, declared versus enforced sandbox audit).
Source: vibes patterns/zero-trust-sandboxing-and-observability.md, resources/k8s/agent-sandbox/network-policy.yaml, resources/observability/prometheus-agent-alerts.yaml.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Sep 30, 2026
Moved from v0.2.25 to v0.2.26. v0.2.25 is capped at 12 items (#740): it keeps #739-#742, their dependency #704, and the oldest P1 items. This P1 item is next in line.
dan-petty commentedon Oct 1, 2026
Moved from v0.2.26 to the backlog. After the v0.2.23 P1 leftovers were retargeted (they were committed earlier), v0.2.25 and v0.2.26 are full at 12 items each, and the roadmap-service items placed in v0.2.26 stay. It is next in line for a planned release.
dan-petty commentedon Oct 2, 2026
Placed in v0.2.29 on 2026-10-02. v0.2.29 holds P1 work that has to land before v0.3.0, which v0.2.25 to v0.2.28 had no room for. Backlog P1 items were ranked by Value, then Effort, with defects and security fixes first at a tie. This item ranked in the top ten, and two of the release's twelve slots stay open for P1 items that surface before then.
dan-petty commentedon Oct 2, 2026
Refined to Ready on 2026-10-02 for v0.2.29. The body was checked claim by claim against release/v0.2.25 at 9c879ae, and a second agent then tried to refute it; every major objection was resolved in a revision. Cited lines were updated for code that moved, and the scope was corrected where merged work changed it. Acceptance criteria were tightened so each fails on the current code, and every key question now has a proposed answer.
dan-petty commentedon Oct 2, 2026
Moved to the backlog: #1021 (a P1 review defect, High value) took this slot in v0.2.29. This item was the lowest-ranked one the job placed there (a P1 feature, Medium/Medium). It goes first among backlog P1s when a pre-v0.3.0 slot opens.
dan-petty commentedon Oct 3, 2026
Lines cited at dcafadf.
The first PR of #897 (v0.2.27) changes the public-whitelist check in
_resolve_public_host(sandbox/models.py:174-184). Withipaddressobjects and the metadata classifier #897 settles, it refuses a CIDR that overlaps link-local space (169.254.0.0/16,fe80::/10), holds a cloud metadata address, is notis_global, or has a non-public first or last address.0.0.0.0/0,::/0,128.0.0.0/1and64:ff9b::/96from this item's refused list, and still admits2606:4700::/48and140.82.112.0/20.8.0.0.0/5: both ends are public and it overlaps no link-local space, but it holds an RFC 1918 block.The general rule, that no address in a public range may be non-public, stays with this item, and
8.0.0.0/5is its case. Build it on #897's predicates incore/validation.py, as this item's "same classification" criterion already says, and keep the refused and admitted lists in this item's acceptance criteria.dan-petty commentedon Oct 8, 2026
Placed in v0.2.30 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: P1 secret and sandbox-boundary fixes, the review tools lock, kube-linter finding identity and a faster gate. Position 6 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.
feat(telemetry): sandbox egress port scoping, collector lane & in-con…
dan-petty-bot commentedon Oct 9, 2026
What changed
#1465, merged into
release/v0.2.30as b37eb54.23 file(s) changed.
How it was verified
Check runs at 21c3c3f:
Acceptance Criteria of
docs/agent/tasks/task-702-sandbox-egress-port-scoping-collector-lane-in-container-trac.md:https://1.1.1.1:8443and1.1.1.1:8443give1.1.1.1/32on 8443 only,http://example.com80,example.com443,[2606:4700::1]:84432606:4700::1/128on 8443, and localhttp://localhost:11434127.0.0.1/32on 11434 (tests/test_sandbox_networking.py::test_a_whitelist_entry_opens_only_its_own_port, names throughpublic_dns).example.com:8443,example.org, each name stubbed to its own public address through a patchedsocket.getaddrinfo, gives two rules, and neither pairs one entry's addresses with the other's port (test_two_entries_never_share_a_rule).network-policyexits 1 with the entry in its output forftp://example.com,example.com:0,example.com:70000and140.82.112.0/20:8443(test_network_policy_exits_1_naming_an_entry_it_cannot_scope_to_a_port); the parser's forms and refusals are pinned bytest_a_whitelist_entry_parses_into_its_host_and_port,test_a_whitelist_entry_that_cannot_name_one_port_is_refusedand the IPv6 property test intests/test_sandbox_policy_properties.py.test_every_whitelist_rule_but_the_dns_rule_names_its_ports).is_non_public_iprefuses0.0.0.0/0,::/0,128.0.0.0/1,8.0.0.0/5,64:ff9b::/96,64:ff9b::800:0/101,::800:0/101and64::/16, and admits2606:4700::/48and140.82.112.0/20(tests/test_validation.py::test_a_range_is_non_public_when_any_of_its_addresses_is).test_is_non_public_ip, which keeps64:ff9b::808:0/112public, and the feat(cli): ipv6 egress cidr fix and deny-class property tests for sandbox policy #701 tests pass unchanged.--allow-collectoradds exactly the collector rule insandbox_namespace,public_whitelistandlocal_whitelist; withisolatedorbridgethe command exits 1 naming those three modes; without the flag no rule selectsotel; no mode, with or without the flag, opens 6379; the MCP tool adds--allow-collectoronly when asked (test_the_collector_lane_*,test_without_the_flag_no_rule_selects_the_collector_namespace,test_no_policy_opens_the_cache_port,test_the_mcp_tool_asks_for_the_collector_lane_only_when_told_to).TRACEPARENTnames thesandbox.deployspan and a workload's thedocker.workload_sandbox.runspan;config.envis unchanged; proxy variables stay; with tracing disabled the environment is exactlyconfig.env(tests/test_sandbox_lifecycle.py,tests/test_workload_sandbox.py, mocked Docker SDK, no daemon).sandbox.execspan and neither the deploy span; with tracing disabled an exec sends no environment;exec_in_containerhandsenvironmenttoexec_run(test_each_exec_is_parented_to_its_own_exec_span,test_an_exec_with_tracing_off_sends_no_environment,tests/test_docker_engine.py::test_exec_in_container_hands_its_environment_to_the_exec).devops docs generate --sync-readmeand passdevops docs check;docs/TELEMETRY.md, written fromdocs/generator.py, names the sandbox containers and execs, andchangelog.d/702.mdcarries the entry;CHANGELOG.mdanddocs/ROADMAP.mdare not edited.devops sandbox network-policy --network-mode public_whitelist --public-whitelist 1.1.1.1:443 --name egress-check --namespace <test-namespace> | kubectl apply -f -, run a pod labelledapp.kubernetes.io/name=egress-checkthere (kubectl -n <test-namespace> run egress-check --image=curlimages/curl --labels=app.kubernetes.io/name=egress-check --command -- sleep 3600), and from it confirm1.1.1.1:443connects and1.1.1.1:80times out (kubectl -n <test-namespace> exec egress-check -- curl -sS -m 5 -o /dev/null https://1.1.1.1andkubectl -n <test-namespace> exec egress-check -- curl -sS -m 5 -o /dev/null http://1.1.1.1). If port 80 connects, the cluster does not enforce NetworkPolicy, and the owner decides what follows.devops sandbox network-policy --network-mode sandbox_namespace --allow-collector --name egress-check --namespace <test-namespace>the same way, and confirm an OTLP request from the pod reaches the collector (kubectl -n <test-namespace> exec egress-check -- curl -sS -m 5 -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -d '{}' http://otel-collector-opentelemetry-collector.otel:4318/v1/tracesprints a status rather than timing out).kubectl -n otel get pods --show-labelsshows the collector pod with bothapp.kubernetes.io/name=opentelemetry-collectorandapp.kubernetes.io/instance=otel-collector.feat(release): v0.2.30 (#1473)
fix(k8s): start minikube with calico cni and align bootstrap help (#2122