Skip to content

fix(k8s): the grafana, prometheus, argo cd and loki clients dial through the egress-checked factory, and their pre-flight address checks go #2424

Closed

Description

@dan-petty

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

  1. On origin/main (86d5bce), run rg -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.
  2. In a test, install scripted_resolver(monkeypatch, {"example.com": rebinding(1, "10.0.0.1")}) and record_connects from tests/web_fakes.py.
  3. Without ai.allow_private_network, set prometheus.url to http://example.com:9090 and run devops prometheus query up.
  4. 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/main 86d5bce)
  • 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.py prints 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_level in tests/test_http_egress.py has a row for each caller in the table, with and without ai.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 (ScriptedResolver and ConnectRecorder in tests/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

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: Run 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.py and confirm it prints nothing.
  • Criterion 2: No pre-flight address check that performs a DNS lookup remains in the scope files.
    Verification: Run rg -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: Run pytest tests/test_http_egress.py::test_each_caller_dials_at_its_level -v and 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: Run pytest tests/test_http_egress.py -v --timeout=5 and 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.

Activity

  1. added
    source/agent
    type/security
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/security. The fix closes a DNS rebinding TOCTOU window that bypasses egress restrictions.
    • Priority: P1-High. A security bypass of network egress controls is high priority.
    • Value: High. Users can be dialed to private addresses despite egress restrictions being set.
    • Effort: Medium. The change spans nine files but is mechanical: replace raw clients with the factory and delete pre-flight checks.
    • Related: refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, which asks for a different change. 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.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 73d1807 (see proposed design in issue body).

  4. added
    priority/p1-high
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  5. removed
    status/ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highsource/agenttype/securityvalue/high

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions