Repository navigation
fix(valkey): the Valkey client resolves a name once, vets every answer and dials the vetted address - #2029
Merged
Conversation
…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
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.
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:_GuardedConnection.connectand in the dial of valkey-py (Connection._connectcallssocket.getaddrinfoitself). A probe with a resolver that changes its answer counted three lookups for oneping, and the client dialled the third answer (127.0.0.2), which no check saw._resolved_addressesreturned no address and the check passed.The change:
_VettedConnection._connectcallsvet_addresses(host, port, EgressLevel.PRIVATE)once for each dial and dials the vetted literals in answer order, asVettingBackend.connect_tcpdoes._VettedSSLConnection(SSLConnection, _VettedConnection)givesvalkeys://andrediss://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, withssl_check_hostname=True(the valkey-py default isFalse) and the platform CA store. Before, such an endpoint in thehostargument connected in plaintext.runs.index_urlgives the client its URL in this argument.ValkeyConnectionErrorthat names the host and port. valkey-py does not catchSSRFBlockedErrororhttpcore2.ConnectError(default retryRetry(NoBackoff(), 0), andconnectcatches onlysocket.timeoutandOSError), so_valkey_failuresmaps them.EgressLevel.PRIVATEadmits every address but cloud metadata and scoped IPv6 (SECURITY.md).validate_destination,_resolved_addresses,_GuardedConnectionand theallow_private_networkargument are gone. No caller insrcpassed the argument.Tests:
TestValkeyClientDestinationis replaced andTestValkeyClientTlsis new. They use the sharedScriptedResolveroftests/web_fakes.pyfor the rebinding case, loopback listeners for the dial, and a CA fromdevops_cli.crypto.tls_certificatesthat the client trusts throughSSL_CERT_FILE. 11 new tests fail onorigin/mainand pass on this branch. A change ofssl_check_hostnametoFalsefails 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_addressesof #898, TLS is theSSLConnectionof valkey-py, and the test CA comes from the project generators. valkey-py has no resolver hook, so the build is one_connectoverride 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 privateConnection._connectof 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.urlstill reaches the client as a host and a port without the scheme, so avalkeys://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