Repository navigation
Conversation
Applications embedding the client may need to constrain the set of hosts the client is allowed to dial. Validating only the service URL is not enough: the client follows lookup responses and connects to the returned broker addresses directly. Every physical connection goes through ConnectionPool::getConnectionAsync, so invoke an application-provided validator there and reject the connection attempt with ResultConnectError when the validator returns false. Rebased onto apache/pulsar-client-cpp main: the connection future carries an `Error` since apache#579.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Motivation
An application that must restrict the hosts the client connects to (for example, a server that creates clients from user-provided service URLs and must not be usable to reach other hosts) cannot do it by validating the service URL alone: the client follows lookup responses and connects to the returned broker addresses directly. Every physical connection is opened through
ConnectionPool::getConnectionAsync, so that is the one place where such a check covers all of them.Modifications
ClientConfiguration::setConnectionValidator/getConnectionValidator: a callback invoked with the physical address of every broker the client is about to connect to (e.g.pulsar://broker-1:6650), including the brokers discovered through lookups. It must be thread-safe. By default no validator is set.ConnectionPool::getConnectionAsyncfails the connection attempt withResultConnectErrorwhen the validator returnsfalse.Verifying this change
This change added tests and can be verified as follows:
ClientTest.testConnectionValidator: with an allowing validator a producer is created and every address passed to it is the broker's; with a rejecting validatorcreateProducerfails withResultConnectErrorafter one call.Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
The new methods are documented in
ClientConfiguration.h.This fix comes from the fork of this repository that ClickHouse uses for its Pulsar table engine (ClickHouse/ClickHouse#64184).
🤖 Generated with Claude Code