Skip to content

[fix][broker] Request TLS client certificates only when they are required or used - #27046

Merged
lhotari merged 2 commits into
apache:masterfrom
lhotari:lh-fix-tls-client-cert-request
Nov 10, 2026
Merged

lhotari merged 2 commits into
apache:masterfrom
lhotari:lh-fix-tls-client-cert-request

Conversation

@lhotari

@lhotari lhotari commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #27036

Motivation

Pulsar TLS servers (broker, proxy, websocket proxy, functions worker; binary and web listeners) always requested a
client certificate. tlsRequireTrustedClientCertOnConnect=false only downgraded "require" to "want". Each TLS
CertificateRequest carries the names of every trust anchor in certificate_authorities:

  • With tlsTrustCertsFilePath pointing at an operating-system CA bundle (~120 CAs), the CertificateRequest is
    about 16 KB. The TLS 1.3 server flight (EncryptedExtensions + CertificateRequest + Certificate +
    CertificateVerify + Finished) then spans two TLS records. That is valid TLS, but some clients mishandle it:
    a .NET client on Windows stopped connecting after a base-image CA bundle update added two CAs. No error was
    logged by the broker or the proxy.
  • With no trust file, the server trusts the JVM default anchors and lists them all: JDK 25's cacerts has 146 CAs,
    15,734 bytes of names.

This happened in deployments that never authenticate clients by certificate (token or OAuth 2.0 only), where
requesting a client certificate serves no purpose.

Modifications

  • New tlsClientAuthMode setting (NONE, OPTIONAL, REQUIRE) on the broker, proxy, websocket proxy and
    functions worker (TlsClientAuthMode in pulsar-common). It applies to all TLS listeners, binary and web.
    When unset, it is resolved for compatibility as follows:

    • REQUIRE if tlsRequireTrustedClientCertOnConnect=true;
    • OPTIONAL if authenticationEnabled=true and AuthenticationProviderTls (or a subclass) is among the
      authenticationProviders;
    • NONE otherwise: no CertificateRequest is sent.

    Two combinations are rejected at startup: tlsRequireTrustedClientCertOnConnect=true with an explicit NONE or
    OPTIONAL, and an explicit NONE while AuthenticationProviderTls is enabled (TLS authentication could never
    succeed).

  • Each component with a TLS listener logs the effective mode once at startup, with where it came from, e.g.
    TLS client auth mode {component=broker, mode=NONE, source=derived: AuthenticationProviderTls not among authenticationProviders}.

  • tlsRequireTrustedClientCertOnConnect is deprecated in favor of tlsClientAuthMode=REQUIRE. It is kept in
    every conf file that had it, so environment-variable overrides keep working. The new TLS factory APIs take only
    the mode: FileBasedTlsFactorySettings.Builder.clientAuthMode, TlsSynthesisSpec.server,
    JettyTlsFactory.createReloadingServerFactory, and the TlsContexts builders.

  • All server consumers are wired:

    • broker: binary (PulsarChannelInitializer, DefaultBrokerTlsFactory) and web (WebService)
    • proxy: binary (ServiceChannelInitializer, ProxyTlsFactories) and web (WebServer)
    • websocket proxy: ProxyServer
    • functions worker: WorkerServer

    For a custom tlsFactoryClassName, the mode applies through the framework's Netty and Jetty synthesis paths.

  • Config docs and conf files describe the new setting and the record-size interaction: when a certificate is
    requested, the CertificateRequest lists every CA in tlsTrustCertsFilePath / tlsTrustStore, so that trust
    store should hold only the CAs that issue client certificates. Two PIP-478 references to the deprecated flag now
    name tlsClientAuthMode=OPTIONAL.

  • The trust anchors used for validating client certificates are unchanged (tlsTrustCertsFilePath /
    tlsTrustStore). Separating them from the outbound trust of function instances is left to a follow-up.

Behavior change: with no configuration change, a TLS server that neither requires client certificates nor
authenticates with AuthenticationProviderTls no longer requests one. A custom authentication provider that reads
the client certificate must set tlsClientAuthMode=OPTIONAL (or REQUIRE). A functions worker reads its own
authenticationProviders, as its AuthenticationService already does.

Pulsar 4.x (the PIP-337 DefaultPulsarSslFactory TLS path) needs a separate fix. It always requests a client
certificate when tlsRequireTrustedClientCertOnConnect=false (setWantClientAuth(true)), so the reported issue
remains there until a 4.x change stops requesting client certificates when they are neither required nor used.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • TlsClientAuthModeTest and TlsFactorySupportTest cover:
    • mode resolution and both conflict checks
    • detection of AuthenticationProviderTls, including a subclass, an unknown class and authentication disabled
  • FileBasedTlsFactoryTest (JDK and OpenSSL engines, TLS 1.2 and 1.3): a client key manager records what the
    server asked for.
    • NONE sends no CertificateRequest, also in insecure mode and with the JVM default anchors.
    • OPTIONAL lists the trusted CA and captures the client certificate.
    • REQUIRE rejects a missing certificate.
  • SslParametersSynthesisTest and JettyTlsFactoryTest cover the mode on the synthesized Netty and Jetty server
    contexts.
  • Wiring tests for the broker, proxy, websocket proxy and functions worker check the resolved mode in the factory
    settings.
  • TlsClientAuthModeBrokerTest (end to end): a real broker's binary and web TLS ports send no
    CertificateRequest by default and send one with tlsClientAuthMode=OPTIONAL.
  • Existing TLS-authentication suites still pass with the derived mode. These include ClientAuthenticationTlsTest,
    TlsProducerConsumerTest, AuthenticatedProducerConsumerTest, ProxyWithAuthorizationTest,
    ProxyMutualTlsTest, the ProxyKeyStoreTls* tests and both PulsarFunctionTlsTests.
  • Mutation check: hard-coding OPTIONAL in the broker's WebService or DefaultBrokerTlsFactory wiring fails the
    end-to-end and policy tests.

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

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations: a TLS server no longer requests a client certificate unless it is
    required or AuthenticationProviderTls is enabled; tlsRequireTrustedClientCertOnConnect is deprecated in
    favor of tlsClientAuthMode
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment: new configuration key tlsClientAuthMode

…ired or used

Pulsar TLS servers always requested a client certificate, and the
TLS CertificateRequest lists every CA in the server's trust store, or
all ~150 JVM default CAs (about 16 KB of names) when no trust file is
configured. With a large bundle the TLS 1.3 server flight exceeds one
16 KB TLS record, which some clients fail to handle, even in
deployments that never authenticate clients by certificate.

Add tlsClientAuthMode (NONE, OPTIONAL, REQUIRE) to the broker, proxy,
websocket proxy and functions worker. When unset, it is REQUIRE if the
now deprecated tlsRequireTrustedClientCertOnConnect is true, OPTIONAL
if authentication is enabled with AuthenticationProviderTls, and NONE
otherwise, so no certificate is requested when nothing requires or
uses one.

Add tlsClientAuthTrustCertsFilePath and tlsClientAuthTrustStore (with
type and password) to validate client certificates against dedicated
CAs, such as a private client CA, while tlsTrustCertsFilePath keeps
serving outbound connections. Public CAs are removing the clientAuth
extended key usage from their TLS certificates, so the client-auth
trust anchors should not be a public CA bundle.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari marked this pull request as draft October 22, 2026 20:05
…E with TLS auth

- Remove tlsClientAuthTrustCertsFilePath and the tlsClientAuthTrustStore*
  keys and helpers. The server listeners validate client certificates
  against tlsTrustCertsFilePath / tlsTrustStore as before; separating
  them from outbound trust is a follow-up.
- Reject an explicit tlsClientAuthMode=NONE while
  AuthenticationProviderTls is enabled.
- Log the effective mode and its source once per component that has a
  TLS listener.
- PulsarFunctionTlsTest: configure the worker's own
  authenticationProviders, as a real worker does.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari merged commit deac87c into apache:master Nov 10, 2026
83 of 85 checks passed
@lhotari lhotari added this to the 5.1.0 milestone Nov 10, 2026
lhotari added a commit that referenced this pull request Nov 11, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
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.

[Bug] Proxy/broker always sends CertificateRequest with full truststore CA list, breaking TLS 1.3 handshakes with large truststores

3 participants