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

Switch to rely on Netty for Hostname Verification #15824

Merged
merged 4 commits into from
Jun 1, 2022

Conversation

michaeljmarshall
Copy link
Member

@michaeljmarshall michaeljmarshall commented May 29, 2022

Motivation

Currently, we perform hostname verification for the Java Client and the Proxy Java Client using a custom Pulsar hostname verifier. In order to simplify the code, I propose that we refactor these clients so they rely on a Netty, its SslHandler, and the JVM, to perform the hostname verification.

When HTTPS is configured as the endpoint verification algorithm, it uses RFC 2818 to perform hostname verification. This is defined by the Java Security Standard Algorithm Names documentation for JDK versions 8, 11, and 17. Here are the official docs:

Modifications

  • Update the Java Client so that it configures the SslHandler's SslEngine to use HTTPS for endpoint verification and remove unnecessary custom hostname verification logic.
  • Update the Proxy's DirectProxyHandler class so that it configures the SslHandler to perform hostname verification and so that the proxy handler itself does not perform that verification.
  • Make it possible to disable hostname verification checking in the HttpClient used by the HTTP Lookup Client code in the Java Client. Currently, it defaults to being always enabled.

Verifying this change

There are tests that already cover the changes, and I performed integration testing on a minikube cluster with Cert-Manager created certs.

Does this pull request potentially affect one of the following parts:

This change deprecates support for CN matching in the Pulsar Java Client. A future change should remove this support from the Pulsar Admin Client, which relies on Pulsar's verifier that still supports CN matching.

Documentation

There is no need for documentation. This is an internal change.

  • doc-not-needed

@michaeljmarshall michaeljmarshall added area/proxy area/security component/client-java type/refactor Code or documentation refactors. e.g. refactor code structure or methods to improve code readability labels May 29, 2022
@michaeljmarshall michaeljmarshall added this to the 2.11.0 milestone May 29, 2022
@michaeljmarshall michaeljmarshall self-assigned this May 29, 2022
@github-actions
Copy link

@michaeljmarshall:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

2 similar comments
@github-actions
Copy link

@michaeljmarshall:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@github-actions
Copy link

@michaeljmarshall:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@michaeljmarshall michaeljmarshall added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels May 29, 2022
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Lgtm

@eolivelli
Copy link
Contributor

/pulsarbot rerun-failure-checks

1 similar comment
@eolivelli
Copy link
Contributor

/pulsarbot rerun-failure-checks

Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

LGTM

I have a quest:

If a subjectAltName extension of type dNSName is present, that MUST
be used as the identity. Otherwise, the (most specific) Common Name
field in the Subject field of the certificate MUST be used. Although
the use of the Common Name is existing practice, it is deprecated and
Certification Authorities are encouraged to use the dNSName instead.

Do your changes follow up on this rule?

@lhotari
Copy link
Member

lhotari commented May 30, 2022

There are 2 test failures:

  • org.apache.pulsar.client.api.AuthenticationTlsHostnameVerificationTest ► testTlsSyncProducerAndConsumerWithInvalidBrokerHost
  • org.apache.pulsar.proxy.server.ProxyWithAuthorizationTest ►
    testTlsHostVerificationProxyToClient

I debugged and fixed the first one. The test was invalid.
I pushed the commit to my fork: lhotari@7c9545ec

One observation is that when the handshake fails because of hostname verification, the client will keep on retrying for some time. Here's an example log: https://gist.github.com/lhotari/8455fc155e0c7526398f36e9bd0bd88c
(can be reproduced by running AuthenticationTlsHostnameVerificationTest with the above commit)

@lhotari
Copy link
Member

lhotari commented May 30, 2022

I got both failing tests fixed. I pushed my change to my fork and I'm running tests there: lhotari#72

@lhotari
Copy link
Member

lhotari commented May 31, 2022

@michaeljmarshall I'll rebase this PR and include my changes to fix the tests. I hope this is fine.

@lhotari
Copy link
Member

lhotari commented May 31, 2022

@michaeljmarshall It seems that when you opened the PR you didn't grant access to others for collaborating in the PR. I pushed changes to my fork in master...lhotari:use-netty .

one way to make your branch to match the changes:

git pull https://github.com/lhotari/pulsar.git use-netty
git reset --hard FETCH_HEAD

@michaeljmarshall
Copy link
Member Author

@lhotari thank you for finding and fixing those tests! I just gave maintainers access to collaborate. If you’re no longer available to push, I’ll get the commits in soon.

lhotari pushed a commit that referenced this pull request Jun 1, 2022
* Switch to relying on Netty for Hostname Verification

- Add "subjectAltName = DNS:localhost, IP:127.0.0.1" to unit test certs

Co-authored-by: Lari Hotari <lhotari@apache.org>
(cherry picked from commit aa7700d)
lhotari pushed a commit that referenced this pull request Jun 1, 2022
* Switch to relying on Netty for Hostname Verification

- Add "subjectAltName = DNS:localhost, IP:127.0.0.1" to unit test certs

Co-authored-by: Lari Hotari <lhotari@apache.org>
(cherry picked from commit aa7700d)
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jun 1, 2022
* Switch to relying on Netty for Hostname Verification

- Add "subjectAltName = DNS:localhost, IP:127.0.0.1" to unit test certs

Co-authored-by: Lari Hotari <lhotari@apache.org>
(cherry picked from commit aa7700d)
(cherry picked from commit d808271)
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jun 1, 2022
* Switch to relying on Netty for Hostname Verification

- Add "subjectAltName = DNS:localhost, IP:127.0.0.1" to unit test certs

Co-authored-by: Lari Hotari <lhotari@apache.org>
(cherry picked from commit aa7700d)
(cherry picked from commit d63cc31)
@lhotari lhotari added cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life labels Jun 1, 2022
lhotari pushed a commit that referenced this pull request Jun 1, 2022
* Switch to relying on Netty for Hostname Verification

- Add "subjectAltName = DNS:localhost, IP:127.0.0.1" to unit test certs

Co-authored-by: Lari Hotari <lhotari@apache.org>
(cherry picked from commit aa7700d)
@lhotari lhotari added cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.5 labels Jun 2, 2022
@michaeljmarshall michaeljmarshall deleted the use-netty branch June 5, 2022 04:40
@nodece nodece mentioned this pull request Jul 1, 2022
5 tasks
lhotari added a commit to datastax/pulsar that referenced this pull request Jul 19, 2022
* Switch to relying on Netty for Hostname Verification

- Add "subjectAltName = DNS:localhost, IP:127.0.0.1" to unit test certs

Co-authored-by: Lari Hotari <lhotari@apache.org>
(cherry picked from commit aa7700d)
@github-actions github-actions bot added doc-label-missing and removed doc-not-needed Your PR changes do not impact docs labels Sep 10, 2022
@github-actions
Copy link

@michaeljmarshall Please provide a correct documentation label for your PR.
Instructions see Pulsar Documentation Label Guide.

@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Sep 13, 2022
lhotari added a commit to lhotari/pulsar that referenced this pull request Sep 29, 2023
- add 2 suppressions.
  - CVE-2023-37475 is a false positive
  - CVE-2023-4586 is about Netty hostname verification and that is already covered in Pulsar code base with apache#15824 changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/proxy area/security cherry-picked/branch-2.7 Archived: 2.7 is end of life cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.10 doc-not-needed Your PR changes do not impact docs release/2.7.5 release/2.8.4 release/2.9.3 release/2.10.1 type/refactor Code or documentation refactors. e.g. refactor code structure or methods to improve code readability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants