Repository navigation
Description
Problem Description
Part 4 of #1381. The owner approved the split of #1381 into five parts on 2026-10-28.
The sandbox package resolves some host names twice, and it resolves others outside the one resolve-and-check function of devops_cli.http.egress (vet_addresses).
- The metrics scrape already dials through the factory at the loopback level. Before that,
_validate_scrape_urlcallsvalidate_url_egress, which resolves the name a second time. That pre-flight check goes. - The address-range builders of
SandboxNetworkConfigresolve whitelist names to the CIDRs of a Kubernetes NetworkPolicy. They build firewall rules, not connections, so fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 keeps their lookup. They callsocket.getaddrinfodirectly and classify the answers themselves. They change tovet_addressesat their level. - The public whitelist validator resolves each name through
is_loopback_or_private_host(host, resolve_dns=True), which calls_resolve_host_ips. The policy builder then resolves the same name again. Part 5 deletes_resolve_host_ips, so the validator stops its lookup, and the builder makes the one lookup.
Scope, with lines on origin/main d739a47 and the level from the #898 level table:
| Caller | Check today | After | Level |
|---|---|---|---|
Metrics scrape, scrape_prometheus_metrics |
pre-flight validate_url_egress in _validate_scrape_url (sandbox/metrics.py:351); the client at :374 already uses the factory |
the pre-flight check goes; the scheme and host check at :341-346 stays |
loopback (same) |
Public whitelist builder, _resolve_public_dns |
socket.getaddrinfo at sandbox/models.py:237, classified at :244-254 |
vet_addresses, with a time-of-check docstring |
public (same) |
Local whitelist builder, _resolve_local_dns |
socket.getaddrinfo at sandbox/models.py:274, classified at :281-291 |
vet_addresses, with a time-of-check docstring; the builder keeps its rule that each address is private or loopback |
private, then private or loopback only (same) |
Public whitelist validator, _validate_public_whitelist_item |
is_loopback_or_private_host(host, resolve_dns=True) at sandbox/models.py:159 |
no lookup (resolve_dns=False); the builder refuses a non-public answer |
no lookup |
"The flag" (ai.allow_private_network) changes none of these levels.
Notes:
vet_addressestakes a port._build_whitelist_egress(sandbox/models.py:326) has the port of each entry from_parse_whitelist_entry.vet_addressesrefuses a cloud metadata name before the lookup, and it refuses a scoped IPv6 answer. The builders get both refusals.- The time-of-check gap: the NetworkPolicy holds the addresses of one lookup. A later lookup in the pod can give a different address. The policy then blocks that address, so the gap fails closed. Each docstring says this.
Out of scope:
sandbox/probe.py, which already uses the factory at the private level.- The tests that patch
_resolve_host_ipsto check the container engine endpoint (tests/test_sandbox_lifecycle.py:537,:593). Part 5 changes that check.
Reproduction Steps
- On
origin/main(d739a47), runrg -n 'validate_url_egress|resolve_dns=True|socket\.getaddrinfo' src/devops_cli/sandbox. - In a test, install
resolver = scripted_resolver(monkeypatch, {"example.com": [[PUBLIC_ADDRESS]]})andrecord_connects(monkeypatch, [])fromtests/web_fakes.py. - Call
scrape_prometheus_metrics("http://example.com:9100/metrics"). - Read
resolver.lookups["example.com"]. - Reset the resolver. Build
SandboxNetworkConfig(mode="public_whitelist", public_whitelist=["example.com"]).to_k8s_network_policy(). - Read
resolver.lookups["example.com"]again.
Expected vs Actual Behavior
Expected: the metrics scrape resolves its host once, at the connect. The NetworkPolicy builder resolves each whitelist name once, through vet_addresses.
Actual: step 1 lists the checks in the table. Step 4 gives 2: one lookup for the pre-flight check and one at the connect. Step 6 gives 2 for the public whitelist: one lookup in the validator and one in the builder.
Environment Diagnostics
- DevOps CLI Version: 0.8.3 (
origin/maind739a47) - Python Version: 3.14.10
- OS & Architecture: Linux x86_64
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
src/devops_cli/sandbox/metrics.py:16:from devops_cli.core.validation import is_loopback_host, validate_url_egress
src/devops_cli/sandbox/metrics.py:351: return validate_url_egress(
src/devops_cli/sandbox/models.py:159: if is_loopback_or_private_host(host, resolve_dns=True):
src/devops_cli/sandbox/models.py:237: addr_info = socket.getaddrinfo(host, None)
src/devops_cli/sandbox/models.py:274: addr_info = socket.getaddrinfo(host, None)Acceptance criteria
These are the criteria of #1381 that apply to this part.
-
rg -n 'validate_url_egress|validate_service_url|validate_configured_service_url|validate_url\(|_resolve_host_ips|resolve_dns=True|socket\.getaddrinfo' src/devops_cli/sandboxprints nothing. - The address-range builders in
sandbox/models.pycallvet_addressesat the level of the table. Each one names its time-of-check gap in a docstring. - A test shows that the metrics scrape looks up its host once for each scrape, and that the NetworkPolicy builder looks up each whitelist name once.
- A test shows that each builder refuses a cloud metadata name, a cloud metadata answer and an answer outside its level. The local builder also refuses a public answer.
-
test_each_caller_dials_at_its_levelintests/test_http_egress.pyhas a row for the metrics scrape (loopback), with and withoutai.allow_private_network. - Tests stay offline (
ScriptedResolverandConnectRecorderintests/web_fakes.py), and each call phase stays under 1 s. - If the change makes a document wrong, the same pull request fixes it. The general statement that every HTTP client is checked at the connect waits for Part 5.
- The required CI checks pass.
Related
- Parent: fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381. This item is Part 4 of 5. fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 closes when all five parts close.
- Level table and the list of kept pre-flight checks: fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898.
- feat(security): popeye runs in the tool sandbox with one named profile that opens only the kubernetes api #2132 changes the sandbox network profile at the same time. If both change the same file, the one that lands second rebases on the other.
- feat(docker): docker and sandbox commands list their requests in a dry run and make none #2251 gives the sandbox commands a dry run. test(infra): infrastructure tests run on edge fakes #1335 moves the sandbox tests to edge fakes.
- refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 is not a duplicate. It later replaces the factory functions with one HTTP seam. This part moves callers to the factory and the resolve-and-check function that exist now.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Source: #1381
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The change reorganises existing resolution calls to use a shared vet_addresses function and drops a redundant pre-flight lookup without altering the security outcome.It is one of five approved sub-tasks of #1381 and consolidates code paths without fixing a live vulnerability.It removes a double-lookup and a direct socket.getaddrinfo call, reducing TOCTOU surface and keeping one validation path.It touches three call sites in two files with specific line numbers and a clear target API, but requires updating tests that patch _resolve_host_ips.Both touch getaddrinfo in the egress-validation path, but #2152 removes a hand-written IPv4 parser in core/validation.py while this candidate re-routes sandbox/models.py and sandbox/metrics.py through vet_addresses.