Skip to content

ZOOKEEPER-4828: Honor ssl.context.supplier.class for client-server TLS - #2433

Merged
anmolnar merged 1 commit into
apache:masterfrom
SvenssonWeb:ZOOKEEPER-4828
Aug 10, 2026
Merged

ZOOKEEPER-4828: Honor ssl.context.supplier.class for client-server TLS#2433
anmolnar merged 1 commit into
apache:masterfrom
SvenssonWeb:ZOOKEEPER-4828

Conversation

@SvenssonWeb

Copy link
Copy Markdown
Contributor

ZOOKEEPER-4622 (4a79427) replaced the JDK SSLContext based Netty setup with SslContextBuilder, which builds key/trust managers straight from keyStore.location/trustStore.location. As a side effect, the documented ssl.context.supplier.class property stopped being honored for the client-server protocol in 3.9.0: ClientCnxnSocketNetty and NettyServerCnxnFactory never consult it, only FourLetterWordMain still does. A file based key/trust store is now effectively mandatory for client-server TLS, silently breaking use of a PKCS11 key store or a container supplied SSLContext.

This restores option (2) from the JIRA discussion. The blocker recorded there was that quorum needs a javax.net.ssl.SSLContext while the client needs an io.netty.handler.ssl.SslContext — Netty's JdkSslContext bridges that, and is the same adapter ZooKeeper used before ZOOKEEPER-4622 removed it, so one Supplier<SSLContext> still serves both protocols.

  • Extract the supplier lookup into X509Util.loadSuppliedSSLContext, reused by createNettySslContextForClient/ForServer before they fall back to SslContextBuilder.
  • Reject a supplied context combined with a non JDK sslProvider, since OpenSSL builds its own native context.

Also fixes a leaking system property in X509UtilTest's teardown that made context construction depend on test order.

cc @anmolnar @PDavid

ZOOKEEPER-4622 replaced the JDK SSLContext based Netty setup with
SslContextBuilder, which builds key and trust managers directly from
keyStore.location and trustStore.location. As a side effect the
documented ssl.context.supplier.class property stopped being honored
for the client-server protocol in 3.9.0: it is now only read by
X509Util.createSSLContextAndOptions, which the Netty client and server
no longer call. Users needing a custom SSLContext, such as a hardware
key store or one obtained from a container, are forced to a file based
key and trust store for any client-server TLS.

Restore the property on both Netty paths by wrapping the supplied
SSLContext in a Netty JdkSslContext, the same adapter ZooKeeper used
before ZOOKEEPER-4622. Configured protocols, cipher suites, client auth
and hostname verification are applied on top of the supplied context,
so no new configuration is introduced and the quorum protocol keeps
using the identical Supplier<SSLContext>.

A supplied SSLContext cannot be used by the OpenSSL providers, which
build their own native context, so combining it with a non JDK
sslProvider is now rejected with a clear error instead of being
silently ignored.

Also clear the hostname verification system properties in the
X509UtilTest teardown. They leaked between test methods and made
context construction depend on test execution order.

@anmolnar anmolnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! lgtm.

@SvenssonWeb

Copy link
Copy Markdown
Contributor Author

@anmolnar Thanks for the review.

JDK 17 passed while only JDK 25 failed on SaslAuthRequiredMultiClientTest.testClientOpWithInvalidSASLPasswordAuthAfterSuccessLogin, which doesn't seem to do any SSL handling so should be unaffected by this PR. This seems to be a flaky test case.

How do we go forward here, should the build be re-triggered, or can it be merged eventually in this state?

@PDavid PDavid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Many thanks for fixing this, looks good to me. 👍

Comment on lines +95 to +96
System.clearProperty(x509Util.getSslHostnameVerificationEnabledProperty());
System.clearProperty(x509Util.getSslClientHostnameVerificationEnabledProperty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice that you also fixed this, thanks!

@anmolnar
anmolnar merged commit 1b6a4c2 into apache:master Aug 10, 2026
21 of 22 checks passed
@anmolnar

Copy link
Copy Markdown
Contributor

Merged to master. Thanks @SvenssonWeb !
Would you mind creating a separate PR for the branch-3.9 branch? I think it's also applicable.

@SvenssonWeb

Copy link
Copy Markdown
Contributor Author

Great, absolutely!

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.

3 participants