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 - #2497

Merged
dan-petty merged 14 commits into
mainfrom
fix/2424-k8s-clients-egress-factory
Oct 28, 2026
Merged

dan-petty merged 14 commits into
mainfrom
fix/2424-k8s-clients-egress-factory

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The Grafana, Prometheus and Argo CD clients now get their HTTP client from the egress-checked factory (devops_cli.http.client). Each client resolves the host one time, at the connect, and dials only the addresses that its egress level admits. The factory checks each redirect hop in the same way. Before, these clients built a raw httpx2.Client and checked the host name with validate_service_url before the request. Then httpx2 resolved the name again at the socket. A rebinding DNS server could give a different address at the second lookup, for example a private or cloud metadata address. The Loki client and the direct cluster-service URLs already used the factory, but a pre-flight validate_url_egress check resolved the name a second time. This change is part 2 of the split of #1381. Part 1 (#2422) moved the AI service clients.

The moved callers and their levels:

  • devops grafana, devops prometheus and devops argo cd apps commands: configured level.
  • Argo CD fleet sync, GitOps sync (trigger_argocd_sync) and the rollout metric gate: configured level.
  • Argo CD token mint, Grafana token mint and the token checks (k8s/credentials.py): configured level.
  • Loki (execute_loki_query) and the direct cluster-service URL (service_http.get_json): private level, as before. Each request now looks up its host one time.

"Configured" is loopback and public addresses, and private addresses too when ai.allow_private_network is true. Cloud metadata addresses are refused at every level.

The pre-flight address checks of these callers are deleted, with _service_base_url of k8s/credentials.py and the purpose parameter of service_http.get_json, which only the deleted check read. The mint and check functions take a keyword level in place of allow_private_network, whose default was True. get_or_mint_argocd_token, get_or_mint_grafana_auth and sync_k8s_credentials give configured_level(settings.ai). A refused address in a mint or a token check is a failed step with its cause, as a request error is: the sync reports it, keeps the stored token and does not stop.

A check that reads only the URL stays where a command needs an early error. _clean_service_base_url moves to devops_cli.http.urls as service_base_url. The three command groups call it, so a k8s:// address that devops k8s configure-urls --addressing proxy wrote stops the command with an error that names the setting, before any lookup. In devops argo cd apps, this check now runs before the token mint. httpx2 refuses a URL that is not http or https before any lookup, so Loki and get_json need no scheme check of their own.

The three command groups report SSRFBlockedError without a traceback (new_typer(exit_on=...)). The exit status of a refusal is 2, the status of SSRF_BLOCKED in docs/ERRORS.md. The pre-flight refusal exited with status 1. devops grafana dashboards sync stops at the first refused file. A failed Argo CD token mint in a devops argo cd apps command prints the failure with its cause, without a traceback, and exits with status 1.

Some levels change. Without the flag, the commands and the token calls are wider: they dial a loopback answer, such as a kubectl port-forward on localhost. The credential sync is narrower: before, it checked with allow_private_network=True whatever the flag said. Now a private Argo CD or Grafana address needs the flag in the sync too, as it does in the commands. The devops config init wizard still checks these three URLs with validate_service_url, so it refuses loopback without the flag; part 5 (#2437) changes it. devops config set checks only the syntax of these URLs.

test_each_caller_dials_at_its_level has a row for each moved caller, with and without the flag, and fails when a caller host name reaches the dial. test_each_k8s_service_caller_dials_the_address_it_checked reproduces the issue: each host answers a public address at the first lookup and cloud metadata at each later lookup. test_loki_and_a_direct_service_url_look_up_their_host_once counts the lookups. The specs configured-service-urls, stack-credential-sync, k8s-logs and k8s-service-proxy get requirements for these levels, refusals and lookups. README.md, SECURITY.md and docs/KNOWN_ISSUES.md name the moved clients and the exception of the wizard.

Closes #2424

Change: openspec/changes/archive/2026-10-28-2424-k8s-clients-egress-factory/

…he egress factory

The commands get their clients from new_http_client at the configured level, so the connect
checks the address that it dials. The validate_service_url calls before the request go. The
commands keep a check of the URL scheme that makes no lookup, service_base_url, which names the
setting when a k8s:// address is in it. A refusal at the connect ends the command with its
message and no traceback.

Refs #2424
…through the egress factory

Each one gets its client from new_http_client at the configured level, and its
validate_service_url call before the request goes. Each one already reports the error of one
request in its result, so a refusal at the connect needs no new branch.

Refs #2424
… factory

The mint and the check functions take a keyword level in place of allow_private_network, whose
default allowed private addresses. The callers that read the settings give the configured
level, the credential sync too. An address that the level refuses fails the step with its
cause, as a request error does, so the sync reports it and keeps the stored token.

Refs #2424
…once

The validate_url_egress calls before the request go. The factory client at the private level
resolves the host at the connect, and httpx2 refuses a scheme other than http and https before
any lookup. The purpose parameter of get_json, which only the deleted check read, goes too.

Refs #2424
…file

The per-file handler of `devops grafana dashboards sync` caught the
refusal of the connect as a failed file, so each file printed the
refusal and the sync exited 1. The refusal applies to each file. The
handler now lets `SSRFBlockedError` out, and `exit_on` reports it
with status 2.

Refs #2424
…nd report a failed mint

`_argocd` minted the Argo CD token before its URL check and outside
any handler. A mint that the egress level refused, or a `k8s://`
address in `argocd.url`, came out of `devops argo cd apps list`,
`sync` and `status` with a traceback. The URL check now runs first,
and a failed mint ends the command with its cause and status 1.

Refs #2424
…oopback rule of the grafana, prometheus and argo cd urls

The wizard checks these URLs with `validate_service_url`, which
refuses loopback without `ai.allow_private_network`. Part 5 (#2437)
changes it to the configured level. Until then, `devops config set`
sets a loopback URL, because it checks only the syntax.

Refs #2424
… setting by its dotted key

The settings refactor of #2466 deleted `devops_cli.config.options`,
and code now names a setting by its dotted key. The URL check of the
three command groups imported its setting name from that module.

Refs #2424
…, argo cd and loki clients to the egress factory

Refs #2424
@dan-petty dan-petty added scope/k8s Kubernetes commands, Helm charts, pods, services, and policies scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results

Targeted run after the rebase onto origin/main (0c2cba63): uv run devops ci test -n 4 with each changed source and test file, and tests/test_grafana_dashboards.py, tests/test_argo_gitops.py, tests/argo/test_gitops_fuzzing.py and tests/test_ui_telemetry_panel.py.

1475 passed in 122.78s (0:02:02)

The pre-push hook (fast static checks) passed. uv run devops openspec archive 2424-k8s-clients-egress-factory archived the change and validated every spec and change.

Fail-to-pass

uv run devops ci fail-to-pass --base origin/main, run after the rebase:

43 failed on base (43 failed and 332 passed in tests/test_argo.py, tests/test_argo_fleet.py, tests/test_grafana.py, tests/test_http_egress.py, tests/test_k8s_credentials.py, tests/test_k8s_logql.py, tests/test_k8s_service_proxy.py, tests/test_prometheus.py; 0 errored).
Tests that failed on the base
failed on base: tests.test_argo::test_a_k8s_address_in_the_argocd_url_stops_the_command_before_the_token_mint[sync] (AssertionError: assert (1, <class 'd... False, 0, []) == (1, <class 'S..., True, 0, []))
failed on base: tests.test_argo::test_a_refused_address_in_the_argocd_token_mint_ends_the_command_with_the_cause[status] (AssertionError: assert (1, <class 'd...se, False, []) == (1, <class 'S...rue, True, []))
failed on base: tests.test_argo::test_a_k8s_address_in_the_argocd_url_stops_the_command_before_the_token_mint[status] (AssertionError: assert (1, <class 'd... False, 0, []) == (1, <class 'S..., True, 0, []))
failed on base: tests.test_argo::test_a_refused_address_in_the_argocd_token_mint_ends_the_command_with_the_cause[list] (AssertionError: assert (1, <class 'd...se, False, []) == (1, <class 'S...rue, True, []))
failed on base: tests.test_argo::test_a_k8s_address_in_the_argocd_url_stops_the_command_before_the_token_mint[list] (AssertionError: assert (1, <class 'd... False, 0, []) == (1, <class 'S..., True, 0, []))
failed on base: tests.test_argo::test_a_refused_address_in_the_argocd_token_mint_ends_the_command_with_the_cause[sync] (AssertionError: assert (1, <class 'd...se, False, []) == (1, <class 'S...rue, True, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd fleet-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[grafana command] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[grafana token mint-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[stack token check] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[argo cd fleet] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[argo cd gitops] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd token mint-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[prometheus command-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[prometheus command] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[rollout metric gate-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_a_loki_url_that_is_not_http_fails_with_no_lookup (devops_cli.exceptions.security.SSRFBlockedError: SSRF blocked: <masked>Invalid Loki URL scheme 'ftp': must be http or https (Target resolves to a private or loopback network endpoint))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[grafana command-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd gitops-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_loki_and_a_direct_service_url_look_up_their_host_once[k8s direct] (AssertionError: assert (2, [('93.184.215.14', 9090)]) == (1, [('93.184.215.14', 9090)]))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd token mint-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[stack token check-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[grafana command-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[argo cd command] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_loki_and_a_direct_service_url_look_up_their_host_once[loki] (AssertionError: assert (2, [('93.184.215.14', 3100)]) == (1, [('93.184.215.14', 3100)]))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[grafana token mint-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd command-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[rollout metric gate-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[stack token check-without-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[prometheus command-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[grafana token mint] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd command-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[rollout metric gate] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd fleet-with-flag] (AssertionError: assert (<EgressLevel...example.com']) == (<EgressLevel...private'>, []))
failed on base: tests.test_http_egress::test_each_caller_dials_at_its_level[argo cd gitops-without-flag] (AssertionError: assert (<EgressLevel...'public'>, []) == (<EgressLevel...oopback'>, []))
failed on base: tests.test_http_egress::test_each_k8s_service_caller_dials_the_address_it_checked[argo cd token mint] (AssertionError: assert ['example.com'] == [])
failed on base: tests.test_prometheus::test_a_k8s_address_in_the_prometheus_url_stops_the_query_before_a_lookup (assert (1, False, 0, []) == (1, True, 0, []))
failed on base: tests.test_prometheus::test_a_refused_prometheus_address_ends_the_query_with_the_refusal (AssertionError: assert (1, <class 'S...'>, False, []) == (2, <class 'S...t'>, True, []))
failed on base: tests.test_grafana::test_a_refused_grafana_address_ends_the_dashboard_sync_with_the_refusal (AssertionError: assert (1, <class 'S...Exit'>, 0, []) == (2, <class 'S...Exit'>, 1, []))
failed on base: tests.test_k8s_credentials::test_a_private_address_without_the_flag_fails_the_check_and_keeps_the_stored_token (AssertionError: assert (<SyncState.F...stored-token') == ('failed', Tr...stored-token'))
failed on base: tests.test_k8s_credentials::test_a_failed_mint_raises_its_cause (TypeError: mint_argocd_token() got an unexpected keyword argument 'level')
failed on base: tests.test_k8s_credentials::test_mint_tokens_refuse_a_url_with_no_scheme (TypeError: mint_argocd_token() got an unexpected keyword argument 'level')
failed on base: tests.test_k8s_credentials::test_mint_tokens_use_a_lowercase_scheme (TypeError: mint_argocd_token() got an unexpected keyword argument 'level')

The last 3 credential tests fail on the base only from the new level keyword (TypeError), not from the defect. Each other test fails on the base from the defect: a raw client sends the host name to the socket, the pre-flight check refuses the loopback answer that the configured level admits, a request makes 2 lookups in place of 1, or a refusal or a k8s:// URL ends a command with the wrong status or a traceback.

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 18:55
@dan-petty
dan-petty merged commit e7ca1d5 into main Oct 28, 2026
17 of 21 checks passed
@dan-petty
dan-petty deleted the fix/2424-k8s-clients-egress-factory branch October 28, 2026 18:56
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.11.0](v0.10.1...v0.11.0)
(2026-10-28)


### Features

* **monitoring:** the roadmap Service's identity refusals, failing and
stalled jobs, restarts, and GitHub and model request volume raise alerts
([#2496](#2496))
([0137f23](0137f23)),
closes [#2472](#2472)
* **service:** roadmap-service runs at one replica, and each model call
in the cluster is sent at most two times
([#2500](#2500))
([2d32dae](2d32dae)),
closes [#2494](#2494)


### Bug Fixes

* **cli:** every command reports a DevOpsCLIError through one exit seam
([#2502](#2502))
([eadd55f](eadd55f)),
closes [#2487](#2487)
* **github:** pr monitor waits until the checks settle and names every
blocker, and pr ready reads the merge-readiness verdict
([#2498](#2498))
([43326ea](43326ea))
* **k8s:** a pod that does not call the Kubernetes API mounts no service
account token
([#2522](#2522))
([305d3ba](305d3ba))
* **k8s:** the cloudflared tunnel replicas prefer different nodes and
keep one up through a drain
([#2499](#2499))
([d4edaf6](d4edaf6)),
closes [#1023](#1023)
* **k8s:** the grafana, prometheus, argo cd and loki clients dial
through the egress-checked factory, and their pre-flight address checks
go ([#2497](#2497))
([e7ca1d5](e7ca1d5))
* **monitoring:** the roadmap Service alerts count a series that starts
in the hour, and a lane of a new pod can stall
([#2514](#2514))
([c7692b2](c7692b2)),
closes [#2505](#2505)
* **review:** a review's scanners leave out the rules that never gave a
valid finding here
([#2508](#2508))
([fe953ac](fe953ac))
* **roadmap:** a refine round leaves an outside account issue to a
person, and refine neutralizes comment openers, www links and
cross-repository references
([#2507](#2507))
([e6230dc](e6230dc)),
closes [#2478](#2478)
* **sandbox:** the metrics scrape and the whitelist NetworkPolicy
resolve each host one time, through the egress check
([#2521](#2521))
([7c01426](7c01426))
* **security:** the subprocess environment guard refuses the zsh and
interpreter keys that make a child run code
([#2510](#2510))
([459621a](459621a))
* **service:** a restart keeps the halt, the budget window and the
failure ledger, and a rate limit or a suspended installation stops every
worker ([#2515](#2515))
([3630de1](3630de1)),
closes [#2474](#2474)


### Code Refactoring

* **config:** settings resolve in one declared order through
pydantic-settings sources
([#2518](#2518))
([6a5447a](6a5447a)),
closes [#2445](#2445)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/k8s Kubernetes commands, Helm charts, pods, services, and policies scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant