Skip to content

feat(telemetry): sandbox egress port scoping, collector lane & in-container trace context (#702) - #1465

Merged
dan-petty merged 1 commit into
release/v0.2.30from
feat/702-sandbox-egress-ports-collector-lane-trace-context
Oct 9, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.30from
feat/702-sandbox-egress-ports-collector-lane-trace-context

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Closes #702

Summary

devops sandbox network-policy and MCP sandbox_network_policy used to put every whitelist address into one egress rule with no ports. That opened every port and protocol to each address and ignored the port an entry named. A public whitelist CIDR was checked only at its two ends, so 8.0.0.0/5, which holds 10.0.0.0/8, was admitted. No rule reached the OTel collector, and sandbox containers and execs got no trace context. All four fixes land together.

  • Public CIDR range check (core/validation.py): is_non_public_ip refuses a range that is not global, that has a non-public end, or that overlaps one of pydantic-ai's non-public blocks or a private IPv4 block's NAT64 (64:ff9b::/96) or IPv4-compatible (::/96) image. 0.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/101 and 64::/16 are refused. 2606:4700::/48 and 140.82.112.0/20 are still admitted. Space that only Python's is_global treats as non-global, such as the documentation prefix 3fff::/20, is not looked for inside a wider range. That prefix is never routed, and the docstring says so.
  • Port scoping (sandbox/models.py): _parse_whitelist_entry returns an entry's host and one TCP port. ipaddress reads IPs and CIDRs, and urllib.parse.urlsplit reads everything else. An entry gets the port it names, otherwise 443 (no scheme, or https) or 80 (http). These entries are refused with an error naming them: one with no host, another scheme with no port, port 0, a port that cannot be read, or a path with no scheme (such as 140.82.112.0/20:8443). _build_whitelist_egress emits the kube-dns rule, then one rule per entry with ports: [{protocol: TCP, port}].
  • Collector lane: --allow-collector / allow_collector=True adds one rule to the collector pods (namespace otel plus the opentelemetry-collector / otel-collector pod labels) on TCP 4317 and 4318, with no ipBlock. It works in sandbox_namespace, public_whitelist and local_whitelist; with isolated or bridge the command exits 1 and names the modes that support it. No mode opens 6379.
  • Container trace context: deployed sandbox containers get TRACEPARENT parented to sandbox.deploy, and workload containers get one parented to docker.workload_sandbox.run. Each sandbox exec runs in its own sandbox.exec span and passes that span's context to the command through the new environment argument of exec_in_container. config.env is not mutated, proxy variables are kept, and with tracing disabled the environment is exactly config.env.

This is a deliberate break: an entry that named no port no longer opens every port, and there is no fallback to the old rule.

Tests

  • tests/test_sandbox_networking.py: each entry opens only its own port; two entries never share a rule; network-policy exits 1 naming an entry it cannot scope to a port; every whitelist rule except the DNS rule names its ports, checked over one module-level _WHITELIST_POLICIES map that every whitelist test reads; collector lane on, off and refused; no policy opens 6379.
  • tests/test_validation.py: the refused and admitted ranges listed above.
  • tests/test_sandbox_lifecycle.py, tests/test_workload_sandbox.py, tests/test_docker_engine.py: trace context on deploy, workload run and exec, using a mocked Docker SDK and the shared tracer fixture in tests/conftest.py.
  • No test resolves a real name or opens a non-loopback socket. Name resolution goes through public_dns or a patched socket.getaddrinfo, and dummy hosts are example.com / example.org.

Docs

The generated CLI and MCP docs are refreshed, docs/TELEMETRY.md (written from docs/generator.py) names the sandbox containers and execs, the changelog entry is in changelog.d/702.md, and the task file is updated. CHANGELOG.md and docs/ROADMAP.md are not edited.

For a person to check on the cluster

The task file gives the exact commands. In a test namespace:

  1. Apply a public_whitelist policy for 1.1.1.1:443 and start the egress-check pod. 443 should connect and 80 should time out.
  2. Apply a sandbox_namespace --allow-collector policy. An OTLP request from the pod should reach the collector.
  3. Confirm the collector pod carries both selector labels.

@dan-petty
dan-petty merged commit b37eb54 into release/v0.2.30 Oct 9, 2026
8 checks passed
@dan-petty
dan-petty deleted the feat/702-sandbox-egress-ports-collector-lane-trace-context branch October 9, 2026 03:30
dan-petty added a commit that referenced this pull request Oct 9, 2026
* chore(review): suppress the logger-credential rule on vault_lease.py's token-path warning (#1456)

* docs(service): subscribe each webhook to issues, pull_request, milestone and release only (#1457)

Step 8 of the roadmap Service setup and AGENTS.md listed Issues, Pull requests
and Milestones (AGENTS.md also push). The Service treats release published as a
reprioritize hint, and every other event only starts extra rounds (#1386).
The 8 live hooks were switched to these four events on 2026-10-09.

* fix(docs): the docs check validates the options inside optional-group brackets such as [-v <ver>] (#1299) (#1458)

* fix(mcp): fastmcp's debug log of tool calls never records argument values (#899) (#1459)

FastMCP logs every tools/call and prompts/get with its arguments at DEBUG on fastmcp.server.mixins.mcp_operations, so FASTMCP_LOG_LEVEL=DEBUG wrote a vault_set call's key_values to stderr. ArgumentValueLogFilter on that logger replaces each mapping argument with <redacted>, keeping the record and the tool or prompt name; the whole mapping goes, since an undeclared parameter's name is the caller's own text. #862's RejectedInputLogFilter on fastmcp.server.server is removed: since fastmcp 4.0.11 FastMCP logs a refusal's error count and types, never the input, so it matched nothing. The fastmcp_log fixture now captures every FastMCP logger at DEBUG.

* fix(security): a sandbox workspace never holds the user's ssh agent or X11 socket (#1384) (#1463)

* feat(telemetry): sandbox egress port scoping, collector lane & in-container trace context (#702) (#1465)

* refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner (#773) (#1466)

devops_cli.core.code_metrics is now the one copy of the nesting and
complexity metric. It is stdlib only and imports nothing from devops_cli.
The structural-invariants hook runs it with --max-depth 5 and loads no
scanner and no pydantic-ai. devops scan complexity, MCP scan_complexity,
the inspection hotspots and devops ai spec read it too.

- Nesting counts the function body as depth 1, as CI already did, so
  5 nested blocks now fail at commit. The six test functions that sat at
  depth 6 are flattened.
- Complexity is Ruff C901's McCabe count. It equals ruff on all 18,000
  functions in src/ and tests/, and flags the same 54 functions in src/
  at a cap of 10.
- One whole-tree test, test_the_source_tree_keeps_its_structural_invariants,
  parses src/ once through _parse_src().
- The parity test and the hook's subprocess spawns are gone.

Removed: devops_cli.security.structural_invariants, analyze_file_complexity
and FileComplexityReport.

* fix(ai): a web_fetch budget cut inside a code block closes the fence before the truncation note and boundary tag (#1298) (#1462)

* feat(review): review tools install from a tools lock with exact versions, binary checksums and hashed Python requirements, and every review records them (#1142) (#1467)

* fix(security): mask_secrets masks every GitHub token prefix, ghu_, ghs_ and ghr_ included (#1398) (#1464)

* fix(config): the secrets audit never prints a config line it cannot parse, and an unparsable file is not reported clean (#1022) (#1461)

* fix(cli): `devops branches create` creates the branch instead of failing on `checkout -b --` (#900) (#1460)

* fix(security): kube-linter findings carry their own check, message and manifest file, and scan reports keep each one (#1045) (#1471)

* feat(review): devops review score scores saved review sessions against a label file offline and reproduces the S11 and loop baselines (#1138) (#1472)

* feat(release): v0.2.30

---------

Co-authored-by: Daniel Petty <contact@danielpetty.com>
Co-authored-by: dan-petty-bot <dan-petty-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant