Skip to content

fix(valkey): the Valkey client resolves a name once, vets every answer and dials the vetted address - #2029

Merged
dan-petty merged 1 commit into
mainfrom
fix/1988-valkey-vetted-dial
Oct 24, 2026
Merged

dan-petty merged 1 commit into
mainfrom
fix/1988-valkey-vetted-dial

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

Step C of #1113. The Valkey client now resolves a name once, when it dials, vets every answer at the private egress level and dials only a vetted IP literal. This closes a DNS rebinding window (time of check to time of use).

Evidence on origin/main:

  • The client resolved a name three times: in the constructor, in the check of _GuardedConnection.connect and in the dial of valkey-py (Connection._connect calls socket.getaddrinfo itself). A probe with a resolver that changes its answer counted three lookups for one ping, and the client dialled the third answer (127.0.0.2), which no check saw.
  • When a lookup failed and private networks were allowed, _resolved_addresses returned no address and the check passed.
  • The check refused every link-local address, also the 169.254.1.2 that a rootless Podman container reaches its host at.

The change:

  • The constructor makes no DNS lookup. _VettedConnection._connect calls vet_addresses(host, port, EgressLevel.PRIVATE) once for each dial and dials the vetted literals in answer order, as VettingBackend.connect_tcp does.
  • _VettedSSLConnection(SSLConnection, _VettedConnection) gives valkeys:// and rediss:// endpoints TLS over the vetted dial. The TCP connection goes to the literal. The handshake uses the endpoint host name for SNI and for the certificate check, with ssl_check_hostname=True (the valkey-py default is False) and the platform CA store. Before, such an endpoint in the host argument connected in plaintext. runs.index_url gives the client its URL in this argument.
  • A cloud metadata answer and a failed lookup each give ValkeyConnectionError that names the host and port. valkey-py does not catch SSRFBlockedError or httpcore2.ConnectError (default retry Retry(NoBackoff(), 0), and connect catches only socket.timeout and OSError), so _valkey_failures maps them.
  • A link-local address that is not a cloud metadata address, such as 169.254.1.2, is now dialled. Valkey is an internal service, and EgressLevel.PRIVATE admits every address but cloud metadata and scoped IPv6 (SECURITY.md).
  • validate_destination, _resolved_addresses, _GuardedConnection and the allow_private_network argument are gone. No caller in src passed the argument.

Tests: TestValkeyClientDestination is replaced and TestValkeyClientTls is new. They use the shared ScriptedResolver of tests/web_fakes.py for the rebinding case, loopback listeners for the dial, and a CA from devops_cli.crypto.tls_certificates that the client trusts through SSL_CERT_FILE. 11 new tests fail on origin/main and pass on this branch. A change of ssl_check_hostname to False fails the TLS test, and a dial of the host name in place of the vetted literal fails five tests.

Open tools and cost (AGENTS.md rule 3): the lookup and the check are vet_addresses of #898, TLS is the SSLConnection of valkey-py, and the test CA comes from the project generators. valkey-py has no resolver hook, so the build is one _connect override of 16 lines and one TLS class with no body. Cost: about 300k tokens and 1.5 hours to build. To keep it: the override depends on the private Connection._connect of valkey-py; each valkey-py upgrade needs a check of about 20k tokens, and the dial and TLS tests fail if the method changes. A fix after such a change costs about 50k tokens.

Not in this change: valkey.url still reaches the client as a host and a port without the scheme, so a valkeys:// URL there connects in plaintext until step B of #1113 gives every endpoint one validated URL. #2026 covers it.

Item

Closes #1988

Task file: docs/agent/tasks/task-1988-valkey-vetted-dial.md

…r and dials the vetted address

The client resolved a name three times: in the constructor, in the check
at the dial and in the dial of valkey-py. The check saw only the first
two answers, so a rebinding DNS server could give the dial an address
that no check saw. A failed lookup passed the check when private networks
were allowed.

Now the constructor makes no lookup. Each dial calls vet_addresses once
at the private egress level and connects only to the vetted IP literals,
in answer order. A valkeys:// or rediss:// endpoint uses TLS over the
vetted dial, and the handshake checks the certificate against the host
name. A cloud metadata answer and a failed lookup give
ValkeyConnectionError, which names the host.

A link-local address that is not a cloud metadata address, such as the
169.254.1.2 of a rootless Podman host, is now dialled.
validate_destination, _resolved_addresses and the allow_private_network
argument of ValkeyClient are gone.

Closes #1988
@dan-petty
dan-petty marked this pull request as ready for review October 24, 2026 00:49
@dan-petty
dan-petty merged commit 71ee0ae into main Oct 24, 2026
16 checks passed
@dan-petty
dan-petty deleted the fix/1988-valkey-vetted-dial branch October 24, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(valkey): the Valkey client resolves a name once, vets every answer and dials the vetted address

1 participant