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

Add hostname-verification at client tls connection #1208

Merged
merged 5 commits into from
Feb 10, 2018

Conversation

rdhabalia
Copy link
Contributor

Motivation

Right now, Pulsar client is not able to perform hostname-verification when it connects to broker over tls. Hostname-verification feature is already implemented in almost all http-client but it's not supported by netty yet. therefore, client should be able to perform hostname-verification as per RFC-2181

Modifications

  • Broker sends certs to client over tls
  • client-configuration to enable hostname-verification
  • added unit test cases
    Note:
    (Copied DefaultHostnameVerifier from httpclient)

Result

Pulsar client will be able to enable hostname verification while communicating with broker or proxy.

@rdhabalia rdhabalia added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Feb 9, 2018
@rdhabalia rdhabalia added this to the 1.22.0-incubating milestone Feb 9, 2018
@rdhabalia rdhabalia self-assigned this Feb 9, 2018
@rdhabalia rdhabalia changed the title Add host-verification at client tls connection Add hostname-verification at client tls connection Feb 9, 2018
@@ -0,0 +1,82 @@
Certificate:
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure these certificates are ignored in the apache-rat:check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked the rat-check plugin in pom which ignores all .cert/.key file but doesn't exclude *.pem so, I will add it too.

*
* @param tlsHostnameVerificationEnable
*/
public void setTlsHostnameVerificationEnable(boolean tlsHostnameVerificationEnable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The allowInsecureConnection=false, which is the default, already should imply the hostname check and that is what the HTTP client is following anyway. I don't think we need a new setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

umm.. actually one can use allowInsecureConnection in non-prod env which makes client to trust all X.509 certificates without any verification using InsecureTrustManagerFactory.java. However, hostname verification can be applied on top of secured connection as well.

that is what the HTTP client is following anyway.

Actually even HTTP client also provides separate API to set hostNameVerifier

So, as both the configs serve different purpose then shouldn't it better to give flexibility while configuring it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, we should just make sure the same check are done in http vs protobuf for the same config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I will check if asyncHttpClient-lib we are using having this feature and if it does then I will create a separate PR.

import org.slf4j.LoggerFactory;

/**
* Default {@link javax.net.ssl.HostnameVerifier} implementation. Copied from httpclient.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to depend on these classes rather than import?

If we are importing we should add a link below the ASF header stating the code was imported/copied/derived from project X at http://xyz////

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have included that as a dep by excluding all transitive dep from it.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple of final touches on maven

@@ -74,6 +74,17 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be added to the client shading as well. Also in all the other shading config they need to reuse the same list of the client shading conf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops.. I missed it. I will add it.

@@ -138,6 +138,18 @@ flexible messaging model and an intuitive client API.</description>
</exclusions>
</dependency>

<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

This dependency should be added at the end of all/src/assemble/LICENSE.bin.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added org.apache.httpcomponents:httpclient in client-shadeed pom and License file. However, I excluded all other jars from httpclient to avoid bringing lot of other things from it, but it requires commons-logging:commons-logging for internal logging without it we see ClassNotFoundException for logger class. So, I have added that dep explicitly and added to LICENSE and cliend-sahde as well.

@apache apache deleted a comment from jai1 Feb 9, 2018
@@ -81,6 +81,8 @@
<include>org.apache.pulsar:pulsar-checksum</include>
<include>net.jpountz.lz4:lz4</include>
<include>com.yahoo.datasketches:sketches-core</include>
<include>org.apache.httpcomponents:httpclient</include>
<include>commons-logging:commons-logging</include>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add these in pulsar-broker-shaded/pom.xml and pulsar-client-kafka-compat/pulsar-client-kafka/pom.xml. I know it's painful, but couldn't find a reliable way to do the shading in the different modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see..let me add it.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

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

👍

@rdhabalia rdhabalia merged commit 8d3ab43 into apache:master Feb 10, 2018
@maskit
Copy link
Member

maskit commented Feb 10, 2018

Actually I was looking into the code, and found much of duplicate code.

The blocks for trustManager and keyManager really seem like SecurityUtility::createNettySslContext. Probably only difference is context for client vs for server.

Using SecurityUtility class would also remove the dependency for org.apache.pulsar.client.impl.auth.AuthenticationDataTls. That is what AuthenticationDataTls use internally.

@maskit
Copy link
Member

maskit commented Feb 10, 2018

Submitted a PR #1213 to address the code duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants