Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use SNI for TLS enabled Pulsar Java broker client. #8117

Merged
merged 1 commit into from
Sep 24, 2020

Conversation

racorn
Copy link
Contributor

@racorn racorn commented Sep 23, 2020

Motivation

The Java Pulsar client does not currently set the SNI header when it creates TLS connections using the binary protocol to brokers (except when using proxyUrl with SNI routing).

If the client always set the SNI header, it can enable ingress routing using reverse proxies like HAProxy, possibly in combination with external advertised addresses (PIP-61).

Modifications

The main modification is to always create SslEngines with advisory peer information (peer host and port).

  • org.apache.pulsar.client.impl.PulsarChannelInitializer modified to set up the SslHandler after the Netty channel is registered. A new method CompletableFuture<Channel> initTls(Channel ch, InetSocketAddress sniHost) was added to explicitly specify the remote peer.

  • org.apache.pulsar.client.impl.ConnectionPool modified to always invoke PulsarChannelInitializer.initTls with a remote peer if TLS is enabled.

  • Added method public SSLEngine createSSLEngine(String peerHost, int peerPort) to org.apache.pulsar.common.util.keystoretls.KeyStoreSSLContext so SNI header can be set irrespective of using OpenSSL or internal Java TLS.

Verifying this change

  • Added org.apache.pulsar.client.api.TlsSniTest to verity that using an IP-address in the brokerServiceUrl does not cause problems.

Copy link
Contributor

@rdhabalia rdhabalia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rdhabalia
Copy link
Contributor

/pulsarbot run-failure-checks

3 similar comments
@racorn
Copy link
Contributor Author

racorn commented Sep 23, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

5 similar comments
@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

/pulsarbot run-failure-checks

@racorn
Copy link
Contributor Author

racorn commented Sep 24, 2020

@rdhabalia Thanks. Finally got all checks to pass.

@rdhabalia rdhabalia merged commit f2933f7 into apache:master Sep 24, 2020
@racorn racorn deleted the enable-sni-java-client branch September 25, 2020 09:25
racorn pushed a commit to racorn/pulsar that referenced this pull request Oct 1, 2020
sijie pushed a commit that referenced this pull request Oct 2, 2020
### Motivation

Improve previous PR #8117 (Always use SNI for TLS enabled Java client)

### Modifications
- Use `ChannelFutures.toCompletableFuture` instead of private static utility method.
- When TLS is not enabled, use 'original' code that invokes `Bootstrap.connect(InetSocketAddress)`; it is only when TLS is enabled we need custom setup code to properly set SNI headers.
- Add documentation and argument checks to `PulsarChannelInitializer.initTls`
lbenc135 pushed a commit to lbenc135/pulsar that referenced this pull request Oct 3, 2020
Co-authored-by: Rolf Arne Corneliussen <rolf.arne.corneliussen@addsecure.com>
lbenc135 pushed a commit to lbenc135/pulsar that referenced this pull request Oct 3, 2020
### Motivation

Improve previous PR apache#8117 (Always use SNI for TLS enabled Java client)

### Modifications
- Use `ChannelFutures.toCompletableFuture` instead of private static utility method.
- When TLS is not enabled, use 'original' code that invokes `Bootstrap.connect(InetSocketAddress)`; it is only when TLS is enabled we need custom setup code to properly set SNI headers.
- Add documentation and argument checks to `PulsarChannelInitializer.initTls`
@wolfstudy wolfstudy added this to the 2.7.0 milestone Oct 28, 2020
@wolfstudy
Copy link
Member

Move this change to 2.6.2, because the #8177 depends on this pr.

wolfstudy pushed a commit that referenced this pull request Oct 30, 2020
Co-authored-by: Rolf Arne Corneliussen <rolf.arne.corneliussen@addsecure.com>
(cherry picked from commit f2933f7)
wolfstudy pushed a commit that referenced this pull request Oct 30, 2020
### Motivation

Improve previous PR #8117 (Always use SNI for TLS enabled Java client)

### Modifications
- Use `ChannelFutures.toCompletableFuture` instead of private static utility method.
- When TLS is not enabled, use 'original' code that invokes `Bootstrap.connect(InetSocketAddress)`; it is only when TLS is enabled we need custom setup code to properly set SNI headers.
- Add documentation and argument checks to `PulsarChannelInitializer.initTls`


(cherry picked from commit 1af5c8e)
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Nov 13, 2020
Co-authored-by: Rolf Arne Corneliussen <rolf.arne.corneliussen@addsecure.com>
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Nov 13, 2020
### Motivation

Improve previous PR apache#8117 (Always use SNI for TLS enabled Java client)

### Modifications
- Use `ChannelFutures.toCompletableFuture` instead of private static utility method.
- When TLS is not enabled, use 'original' code that invokes `Bootstrap.connect(InetSocketAddress)`; it is only when TLS is enabled we need custom setup code to properly set SNI headers.
- Add documentation and argument checks to `PulsarChannelInitializer.initTls`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants