Skip to content

[feat][client] Add a connection validator to ClientConfiguration - #630

Open
groeneai wants to merge 2 commits into
apache:mainfrom
groeneai:add-connection-validator
Open

groeneai wants to merge 2 commits into
apache:mainfrom
groeneai:add-connection-validator

Conversation

@groeneai

Copy link
Copy Markdown

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::getConnectionAsync fails the connection attempt with ResultConnectError when the validator returns false.

Verifying this change

  • Make sure that the change passes the CI checks.

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 validator createProducer fails with ResultConnectError after 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

alexey-milovidov and others added 2 commits November 13, 2026 23:38
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>
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.

2 participants