Repository navigation
Description
Problem Description
Part 2 of #1381. The owner approved the split of #1381 into five parts on 2026-10-28.
The Grafana, Prometheus and Argo CD clients below build a raw httpx2.Client. Each checks the host name before the dial with validate_service_url, and httpx2 then resolves the name again at the socket. A rebinding DNS server can give a different address the second time. #898 closed this window for the callers that it moved to the egress-checked factory (devops_cli.http.client). The Loki and cluster-service clients already use the factory at the private level, but they still make a pre-flight check that resolves the name a second time.
Scope, with lines on origin/main 86d5bce and the level from the #898 level table:
| Caller | Raw client | Pre-flight check that goes | Level |
|---|---|---|---|
devops grafana commands |
commands/grafana.py:116, :168, :233, :352, :478, :518, :555 |
commands/grafana.py:71 |
configured (wider: loopback without the flag) |
devops prometheus commands |
commands/prometheus.py:151, :205, :294, :349, :391 |
commands/prometheus.py:52 |
configured (wider, as above) |
devops argo commands |
commands/argo.py:212, :265, :294 |
commands/argo.py:176 |
configured (wider, as above) |
| Argo CD fleet | argo/fleet.py:60 |
argo/fleet.py:49 |
configured (wider, as above) |
| Argo CD GitOps | argo/gitops.py:402 |
argo/gitops.py:391 |
configured (wider, as above) |
| Rollout metric gate (Prometheus) | argo/rollouts.py:92 |
argo/rollouts.py:91 |
configured (wider, as above) |
| Argo CD token mint, Grafana token mint, token check | k8s/credentials.py:302, :429, :511 |
k8s/credentials.py:105 (_service_base_url) |
configured (wider, as above) |
| Loki | none: k8s/logql.py:393 already uses the factory |
k8s/logql.py:384 |
private (same) |
| Cluster-service direct URL | none: k8s/service_http.py:75 already uses the shared pool |
k8s/service_http.py:74 |
private (same) |
"Configured" is loopback, or private when ai.allow_private_network is set (configured_level).
Correction to the earlier analysis: the check at commands/k8s/cluster_context.py:197 is for devops k8s apply. kubectl dials that URL, not httpx2, and #1381 keeps that pre-flight check. Part 5 changes it to vet_addresses. It is not in this part.
Reproduction Steps
- On
origin/main(86d5bce), runrg -n -g '*.py' 'httpx2\.Client\(' src/devops_cli/commands/grafana.py src/devops_cli/commands/prometheus.py src/devops_cli/commands/argo.py src/devops_cli/argo src/devops_cli/k8s/credentials.py. - In a test, install
scripted_resolver(monkeypatch, {"example.com": rebinding(1, "10.0.0.1")})andrecord_connectsfromtests/web_fakes.py. - Without
ai.allow_private_network, setprometheus.urltohttp://example.com:9090and rundevops prometheus query up. - Read
recorder.dialled.
Expected vs Actual Behavior
Expected: each caller resolves its host once, at the connect. It dials only the addresses that its level admits. The factory checks each redirect hop the same way. Loki and the direct cluster-service URLs resolve their host only once.
Actual: step 1 lists the raw clients in the table. In step 4, validate_service_url passes on the first (public) answer, and httpx2 resolves the name again and dials 10.0.0.1. Loki and the direct cluster-service URLs resolve the name in the pre-flight check and again at the connect.
Environment Diagnostics
- DevOps CLI Version: 0.8.2 (
origin/main86d5bce) - Python Version: 3.14.10
- OS & Architecture: Linux x86_64
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
src/devops_cli/argo/fleet.py:60: with httpx2.Client() as client:
src/devops_cli/argo/gitops.py:402: with httpx2.Client() as client:
src/devops_cli/argo/rollouts.py:92: with httpx2.Client() as client:
src/devops_cli/commands/argo.py:212: with httpx2.Client() as client:
src/devops_cli/commands/argo.py:265: with httpx2.Client() as c:
src/devops_cli/commands/argo.py:294: with httpx2.Client() as client:
src/devops_cli/commands/grafana.py:116: with httpx2.Client() as http_client:
src/devops_cli/commands/grafana.py:168: with httpx2.Client() as http_client:
src/devops_cli/commands/grafana.py:233: with httpx2.Client() as http_client:
src/devops_cli/commands/grafana.py:352: with httpx2.Client() as http_client:
src/devops_cli/commands/grafana.py:478: with httpx2.Client() as http_client:
src/devops_cli/commands/grafana.py:518: with httpx2.Client() as http_client:
src/devops_cli/commands/grafana.py:555: with httpx2.Client() as http_client:
src/devops_cli/commands/prometheus.py:151: with httpx2.Client() as http_client:
src/devops_cli/commands/prometheus.py:205: with httpx2.Client() as http_client:
src/devops_cli/commands/prometheus.py:294: with httpx2.Client() as http_client:
src/devops_cli/commands/prometheus.py:349: with httpx2.Client() as http_client:
src/devops_cli/commands/prometheus.py:391: with httpx2.Client() as http_client:
src/devops_cli/k8s/credentials.py:302: with httpx2.Client(timeout=timeout) as client:
src/devops_cli/k8s/credentials.py:429: with httpx2.Client(auth=("admin", password), timeout=timeout) as client:
src/devops_cli/k8s/credentials.py:511: with httpx2.Client(timeout=timeout) as client:Acceptance criteria
These are the criteria of #1381 that apply to this part.
-
rg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src/devops_cli/commands/grafana.py src/devops_cli/commands/prometheus.py src/devops_cli/commands/argo.py src/devops_cli/argo src/devops_cli/k8s/credentials.py src/devops_cli/k8s/logql.py src/devops_cli/k8s/service_http.pyprints nothing. - No pre-flight address check remains in the files of the table:
rg -n 'validate_url_egress|validate_service_url|validate_configured_service_url|validate_url\(' <those files>prints nothing. A scheme and syntax check without a lookup can stay where a command needs an early error. -
test_each_caller_dials_at_its_levelintests/test_http_egress.pyhas a row for each caller in the table, with and withoutai.allow_private_network. Each wider row has a case that fails on the code before the move. - A test shows that Loki and the direct cluster-service URL look up their host once for each request.
- Tests stay offline (
ScriptedResolverandConnectRecorderintests/web_fakes.py), and each call phase stays under 1 s. - If the move 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 2 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: fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898.
- test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327 and test(infra): infrastructure tests run on edge fakes #1335 change the tests of these commands 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 that exists 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
Proposed design
Problem statement
The Grafana, Prometheus, Argo CD, Loki, and cluster-service clients build a raw httpx2.Client and check the host name before the dial. A rebinding DNS server can return a different address at the socket, so the client dials an address the egress check never saw. This issue moves every caller in the scope table to the egress-checked factory and removes the pre-flight address checks that resolve the name a second time.
Acceptance criteria
- Criterion 1: No raw httpx2 client call remains in the scope files.
Verification: Runrg -n -g '*.py' 'httpx2\.((Async)?Client|get|post|put|patch|delete|head|request|stream)\(' src/devops_cli/commands/grafana.py src/devops_cli/commands/prometheus.py src/devops_cli/commands/argo.py src/devops_cli/argo src/devops_cli/k8s/credentials.py src/devops_cli/k8s/logql.py src/devops_cli/k8s/service_http.pyand confirm it prints nothing. - Criterion 2: No pre-flight address check that performs a DNS lookup remains in the scope files.
Verification: Runrg -n 'validate_url_egress|validate_service_url|validate_configured_service_url|validate_url\('on each file in the scope table and confirm it prints nothing. A scheme and syntax check without a lookup may remain where a command needs an early error. - Criterion 3: test_each_caller_dials_at_its_level has a row for every caller in the scope table, with and without ai.allow_private_network.
Verification: Runpytest tests/test_http_egress.py::test_each_caller_dials_at_its_level -vand confirm each caller in the table appears as a row, with both flag settings. Each wider row has a case that fails on the code before the move. - Criterion 4: Loki and the direct cluster-service URL resolve their host exactly once per request.
Verification: Run the dedicated test that uses ScriptedResolver and asserts lookups[name] equals 1 for each request made through k8s/logql.py and k8s/service_http.py. - Criterion 5: All tests in the change run offline and each call phase stays under 1 second.
Verification: Runpytest tests/test_http_egress.py -v --timeout=5and confirm all tests pass using only ScriptedResolver and ConnectRecorder from tests/web_fakes.py, with no real network access. - Criterion 6: Any document that the move makes wrong is corrected in the same pull request.
Verification: Search the repository documentation for statements about which clients are egress-checked and confirm they are accurate after the change. The general statement that every HTTP client is checked at the connect waits for Part 5. - Criterion 7: The required CI checks pass.
Verification: Confirm Static Analysis, Tests & Coverage, and Semantic PR title all report a passing status on the pull request.
Key questions
- What factory function do the callers use to obtain an egress-checked client?: The callers use the egress-checked factory in devops_cli.http.client, established by fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898. The k8s/service_http.py file already imports get_shared_client from devops_cli.http.pool, and tests/web_fakes.py imports EgressLevel and vet_addresses from devops_cli.http.egress. [sources: src/devops_cli/k8s/service_http.py, tests/web_fakes.py]
- What egress level applies to the Grafana, Prometheus, Argo CD, and credentials callers?: The configured level: loopback, or private when ai.allow_private_network is set. The issue body calls this configured_level. [sources: src/devops_cli/commands/grafana.py:71, src/devops_cli/commands/prometheus.py:52, src/devops_cli/commands/argo.py:176]
- What egress level applies to Loki and the direct cluster-service URL?: The private level. Both already use the factory at the private level but still make a pre-flight check that resolves the name a second time. [sources: src/devops_cli/k8s/logql.py:384, src/devops_cli/k8s/service_http.py:74]
- Can a scheme and syntax check without a DNS lookup remain in a caller?: Yes. The issue states that a scheme and syntax check without a lookup can stay where a command needs an early error. Only the address-lookup part of the pre-flight check is removed. (proposed)
- Does the check at commands/k8s/cluster_context.py:197 belong in this part?: No. The issue body corrects the earlier analysis: that check is for devops k8s apply, where kubectl dials the URL, not httpx2. Part 5 changes it to vet_addresses. It is not in this part. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
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 fix closes a DNS rebinding TOCTOU window that bypasses egress restrictions.A security bypass of network egress controls is high priority.Users can be dialed to private addresses despite egress restrictions being set.The change spans nine files but is mechanical: replace raw clients with the factory and delete pre-flight checks.Both work on the HTTP client seam, but #1314 consolidates the factory architecture while this candidate moves specific callers to the factory and removes their TOCTOU pre-flight checks.dan-petty commentedon Oct 28, 2026
Status set to Ready at 73d1807 (see proposed design in issue body).
docs(openspec): plan the move of the grafana, prometheus, argo cd and…
test(k8s): the egress test has a row for each grafana, prometheus, ar…
fix(k8s): the grafana, prometheus and argo cd commands dial through t…
fix(argo): the fleet sync, the gitops sync and the rollout gate dial …
fix(k8s): the argo cd and grafana token calls dial through the egress…
fix(k8s): the loki client and direct service urls look up their host …
docs(security): name the grafana, prometheus, argo cd and loki client…
docs(k8s): say what exit_on does for the grafana, prometheus and argo…
fix(grafana): a refused address ends the dashboard sync at the first …
fix(argo): the argo cd commands check the url before the token mint a…
docs(openspec): the k8s egress change names the dashboard sync stop a…
docs(security): name the config init wizard as the exception to the l…
fix(k8s): the grafana, prometheus and argo cd commands name their url…
docs(openspec): archive the change that moves the grafana, prometheus…