Repository navigation
fix(ai): the AI service clients dial through the egress-checked factory and check the address at the connect - #2484
Merged
Merged
Conversation
The level test gets a row for each AI service caller of #2422, with and without ai.allow_private_network. It also fails when a caller host name reaches the dial. A new test gives each host a public answer at the first two lookups and cloud metadata after them, as the issue reproduction does. The OpenSpec change 2422-ai-clients-egress-factory plans the move.
…egress factory The gateway model query, the gateway health probe and the backend probe get a factory client at the configured level. The probe of devops ai gateway connect gets a private-level factory client. prometheus_query takes the level from its caller, and devops ai gateway load gives the configured level. The connect checks each address, so the validate_url_egress and validate_service_url calls before the request are deleted.
The batch client, the Ollama batch and the two dimension probes of the embeddings engine get factory clients at the configured level of the engine's AI configuration. The connect checks each address, so the four validate_configured_service_url calls before the request are deleted. The tests that patched the deleted check no longer patch it, and the fake gateway connection answers the lookup of the connect.
… the egress factory devops ai cost update-pricing fetches a --source URL at the configured level and the default genai-prices registry at the public level, each with a factory client. The branch that called UpdatePrices.fetch() with the own client of genai-prices never ran, because UpdatePrices.url always has a value, so it is deleted. The documentation crawler gets a public-level factory client, and its two validate_service_url calls before the request are deleted.
create_ollama_provider gave OllamaProvider no http_client, so pydantic-ai built a client of its own that resolved the host again at the socket. The provider now gets a client from new_async_http_client at the configured level of the AI configuration that the bridge gives, so a private Ollama needs ai.allow_private_network on this path too. The lookup of the metadata check, the validate_url call and the allow_private parameters are deleted. normalize_ollama_base_url keeps its scheme check. create_pydantic_ai_provider no longer checks the base URL with a lookup: its factory client checks the address at the connect. The bridge branch that turned that refusal into a ConfigurationError, and the setting name that only it used, are deleted.
…clients The chat and embedding benchmark runners no longer check an endpoint with validate_url before they build the AI client or the embeddings engine. Those clients check each address at the connect, at the configured level, so a loopback answer is dialled without ai.allow_private_network. devops ai benchmark --servers checks each URL with HttpUrlStr, the type of ai.ollama_urls, before the run, because the settings copy does not validate it. An embedding endpoint that ai.ollama_urls cannot hold still fails its run as a ValidationError.
README.md lists the LLM gateway probes and model query, the pool-load query, the embeddings engine, the pydantic-ai models, the pricing fetch and the documentation crawler among the factory clients, with their levels. docs/KNOWN_ISSUES.md and the pydantic-ai page of the knowledge base say that the pydantic-ai models and the embedding calls check the address at the connect.
…ssage The invariant test_no_test_certifies_a_failure_without_checking_it refuses an isinstance assert as a presence check. The test now compares the type and the message of the cause.
Their first import takes over 1 s. A module fixture imports them once, so the call phase of the first row that builds a model checks only the dial.
…point The design of change 2422-ai-clients-egress-factory names the ValidationError that keeps the failed-run behavior of the deleted InvalidURLError.
… the proposal names its four requirements The scenarios of the spec delta wrote the RFC 1918 address 10.0.0.1. SECURITY.md item 8 and openspec/config.yaml do not allow a private address in a committed file, and the archive copies the scenarios into the main spec. The scenarios now use 192.0.2.10 (RFC 5737). The egress levels give it the same decision as 10.0.0.1: refused at the public and loopback levels, dialled at the private level. The proposal said that the delta adds one requirement. It adds four, and the Modified Capabilities entry now names each of them.
The factory client of the Ollama provider had no timeout of its own, so it got the factory default: a 1 s connect, a 1 s pool wait and a 3600 s read. openai 3.26.1 uses the timeout of the client that it gets when ai.timeout is not set. Before #2422, pydantic-ai built the client with 600 s and a 5 s connect, so an Ollama node that took 1 to 5 s to accept the connect failed with the factory client. The provider client now gets pydantic_ai.models.DEFAULT_HTTP_TIMEOUT with DEFAULT_AI_CONNECT_TIMEOUT_SECONDS for the connect. The new test reads the connect bound of a real dial and the timeout of the openai client.
…aces docs/TESTING.md does not let a new test patch devops-cli or reach private code. The tests that #2422 adds now go through the public interface that uses the code: - The --servers test runs the command with no patch. The URL check stops the command before the benchmark starts. - The test of an endpoint that ai.ollama_urls cannot hold runs evaluate_model, and shows that the error fails the run of that model. - The rows of the two embedding dimension probes read the dimension property of the engine, for a model with no known dimension. - The embedding benchmark row runs evaluate_model. - The connect probe row runs `devops ai gateway connect`, with ProcessFake answering kubectl. Each rewritten row still fails on the code before the move.
…way mcp tools their own level The MCP tools of `devops ai gateway status`, `routes` and `probe-backend` take a URL override from the model. The router dials it at the configured level of the #2422 table, so without ai.allow_private_network a tool argument can reach loopback. The routes query also sends the AI API key to the override. The fix changes the router and fetch_model_info, so #2480 does it. The proposal, the non-goals of the design and the follow-up of the tasks name it.
dan-petty
marked this pull request as ready for review
October 28, 2026 18:05
dan-petty
pushed a commit
that referenced
this pull request
Oct 28, 2026
🤖 I have created a release *beep* *boop* --- ## [0.10.1](v0.10.0...v0.10.1) (2026-10-28) ### Bug Fixes * **ai:** a reply names its server by the origin of the URL called, so a password in an AI URL stays out of every record ([#2488](#2488)) ([3ec083f](3ec083f)), closes [#1110](#1110) * **ai:** the AI service clients dial through the egress-checked factory and check the address at the connect ([#2484](#2484)) ([08d70ca](08d70ca)) ### Code Refactoring * **config:** each setting declares its variable on its settings field, and the option, variable and secret registries are derived from it ([#2466](#2466)) ([daaffc6](daaffc6)) --- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AI service 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 rawhttpx2.Client, calledhttpx2.get, or let pydantic-ai build its own client. Most of them checked the host name with a pre-flight check, and 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. #898 closed this window for the callers that it moved to the factory. This change moves the AI service callers. It is part 1 of the split of #1381.The moved callers and their levels:
devops ai gateway connectprobe: private level, because its address is a node address from the Kubernetes API.devops ai gateway loadPrometheus query:prometheus_querytakes the level from its caller, and the command gives the configured level.devops ai cost update-pricing --source <url>: configured level. The default pricing registry: public level.ai.allow_private_networkdoes not widen it.create_ollama_providergivesOllamaProvidera factory client at the configured level of the settings in use, with the timeouts of the client that pydantic-ai builds."Configured" is loopback and public addresses, and private addresses too when
ai.allow_private_networkis true. Cloud metadata addresses are refused at every level.The pre-flight address checks of these callers are deleted (
validate_url_egress,validate_service_url,validate_configured_service_url,validate_urland_is_cloud_metadata_host), with theallow_privateparameters ofnormalize_ollama_base_urlandcreate_ollama_provider, and the deadUpdatePrices.fetch()branch of the pricing fetch. Checks that read only the URL stay where a command needs an early error:normalize_ollama_base_urlstill refuses a scheme other than http and https, anddevops ai benchmark --serverschecks each URL withHttpUrlStr, the type ofai.ollama_urls. The bridge no longer turns an address refusal into aConfigurationErrorwhen it builds a remote model. A request to an address that the level refuses raisesSSRFBlockedErrorat the connect, and openai does not retry it.Some levels change. A private Ollama on the pydantic-ai path and a private
--sourceURL now needai.allow_private_network. The default pricing registry and the documentation crawler dial only public addresses. The gateway and backend probes, the pool-load query and the benchmark endpoints now dial a loopback answer without the flag. This also applies to the URL override of thedevops ai gatewayMCP tools, until #2480 gives an override its own level.test_each_caller_dials_at_its_levelhas a row for each moved caller, with and without the flag, and fails when a caller host name reaches the dial.test_each_ai_service_caller_dials_the_address_it_checkedreproduces the issue: each host answers a public address at the first lookup and cloud metadata at each later lookup. The specconfigured-service-urlsgets four requirements for these levels.README.md,docs/KNOWN_ISSUES.mdand the pydantic-ai page of the knowledge base name the moved clients. Part 5 (#2437) removes the pre-flight check ofai/client/*.Closes #2422
Change:
openspec/changes/archive/2026-10-28-2422-ai-clients-egress-factory/