Transport Layer Security (TLS) is a form of public key cryptography. By default, Pulsar clients communicate with Pulsar services in plain text. This means that all data is sent in the clear. You can use TLS to encrypt this traffic to protect the traffic from the snooping of a man-in-the-middle attacker.
This section introduces how to configure TLS encryption in Pulsar. For how to configure mTLS authentication in Pulsar, refer to mTLS authentication. Alternatively, you can use another Athenz authentication on top of TLS transport encryption.
note
Enabling TLS encryption may impact the performance due to encryption overhead.
TLS uses certificates containing public keys and separate private keys:
A Certificate Authority (CA) signs server and client certificates with its private key. Keep that key with the CA; do not distribute it to brokers, proxies, or clients. Distribute the CA's public certificate (trust cert) to parties that need to verify those signatures.
Servers hold their own private key and certificate to prove their identity to clients.
Clients hold their own private key and certificate when using mutual TLS.
Generate each server or client's key pair and a certificate signing request, then have the CA sign the request. During the handshake, the peer verifies the certificate chain against its trusted CA and verifies possession of the corresponding private key. The Common Name (CN) of a client certificate is used as the client's role token for mTLS authentication, while server certificates should use Subject Alternative Names (SANs) for Hostname verification.
note
The certificate-generation examples below use a validity of 365 days and SHA-256 signatures. Choose validity and rotation policies suitable for your deployment.
Hostname verification is a TLS security feature whereby a client refuses to connect to a server if the server certificate's Subject Alternative Name (SAN) does not match the hostname the client is connecting to. It defends against man-in-the-middle attacks even when the attacker holds a certificate signed by the trusted CA.
Hostname verification is enabled by default for Java clients and outbound TLS connections from brokers, proxies, WebSocket services, and Functions workers, including geo-replication. Give each server certificate SANs that match the addresses clients use in service URLs and the individual addresses advertised by brokers. A wildcard DNS SAN such as *.broker.example.com can cover a group of hosts; connections to an IP address require a matching IP SAN. Other language clients have independent releases and defaults; enable hostname verification explicitly in their configuration.
Pulsar delegates matching to the provider's standard endpoint-identification algorithm. The default JDK/native engines can still fall back to the server certificate's CN when connecting by hostname if there is no DNS SAN. A client explicitly using Conscrypt rejects CN-only certificates because Pulsar's former CN-tolerant verifier has been removed. Reissue CN-only certificates with SANs rather than relying on fallback; current RFC 9525 uses SAN identities. The CN of a client certificate remains the role token for mTLS authentication.
Hostname verification settings differ by component:
Component
Setting
Default
Existing Java client/admin builder
enableTlsHostnameVerification(true)
Enabled
Java client configuration / client.conf
tlsHostnameVerificationEnable=true
Enabled
Broker, proxy, WebSocket service
tlsHostnameVerificationEnabled=true
Enabled
Functions worker
tlsEnableHostnameVerification: true
Enabled
Disabling verification allows a trusted certificate for a different server name to be accepted. Configure matching certificates; see the upgrade checklist when updating an existing deployment.
Certificate trust and hostname verification are separate checks. Keep allowTlsInsecureConnection(false) on Java client/admin builders and tlsAllowInsecureConnection=false in server configuration to reject untrusted certificates, as well as keeping hostname verification enabled.
By default, Pulsar uses netty-tcnative. It includes two implementations, OpenSSL (default) and JDK. When OpenSSL is unavailable, JDK is used.
To configure mTLS encryption with PEM, complete the following steps.
The shared Java PEM reader in Pulsar accepts unencrypted PKCS#8 private keys (BEGIN PRIVATE KEY), PKCS#1 RSA keys (BEGIN RSA PRIVATE KEY), and SEC1 EC keys (BEGIN EC PRIVATE KEY). SEC1 parsing requires Bouncy Castle bcpkix and its matching dependencies on the classpath; otherwise, convert the EC key to PKCS#8. Parsing SEC1 does not register or select a Bouncy Castle cryptographic provider: the configured JCA provider still creates the private-key object. See Bouncy Castle providers.
The examples below use unencrypted PKCS#8 keys. Keep these keys readable only by the component that needs them. Independently released language clients can have different format support; verify their requirements before reusing a key file.
You can use a certificate authority (CA) to sign both server and client certificates. This ensures that each party trusts the others. Store CA in a very secure location (ideally completely disconnected from networks, air-gapped, and fully encrypted).
To configure hostname verification, you need to enter the hostname of the server in alt_names as the Subject Alternative Name (SAN). To ensure that multiple machines can reuse the same certificate, you can also use a wildcard to match a group of server hostnames, for example, *.server.usw.example.com.
At this point, you have a cert, server.cert.pem, and a key, server.key-pk8.pem, which you can use along with ca.cert.pem to configure TLS encryption for your brokers and proxies.
At this point, you have a cert broker_client.cert.pem and a key broker_client.key-pk8.pem, which you can use along with ca.cert.pem to configure TLS encryption for your broker client.
At this point, you have a cert admin.cert.pem and a key admin.key-pk8.pem, which you can use along with ca.cert.pem to configure TLS encryption for your pulsar admin.
At this point, you have a cert client.cert.pem and a key client.key-pk8.pem, which you can use along with ca.cert.pem to configure TLS encryption for your client.
At this point, you have a cert proxy.cert.pem and a key proxy.key-pk8.pem, which you can use along with ca.cert.pem to configure TLS encryption for your proxy.
To configure a Pulsar broker to use TLS encryption, you need to add these values to broker.conf in the conf directory of your Pulsar installation. Substitute the appropriate certificate paths where necessary.
To configure the broker (and proxy) to require specific TLS protocol versions and ciphers for TLS negotiation, you can use the TLS protocol versions and ciphers to stop clients from requesting downgraded TLS protocol versions or ciphers that may have weaknesses.
The built-in factory enables TLS 1.3 and TLS 1.2 when protocols are unset. Binary connections use Netty's native OpenSSL engine when available and fall back to the JDK engine. Explicit JSSE provider selection uses the JDK engine with that provider. HTTPS listeners prefer Conscrypt when available and usable, falling back to the JVM default provider. See TLS providers and custom factories for explicit selection.
Both the TLS protocol versions and cipher properties can take multiple values, separated by commas. The possible values for protocol versions and ciphers depend on the TLS provider that you are using.
tlsProtocols specifies the enabled protocol versions. An unset value enables TLS 1.3 and TLS 1.2 with the built-in factory.
tlsCiphers specifies cipher suites. When unset, the provider's defaults apply. The example includes a TLS 1.3 suite and a TLS 1.2 suite for RSA server certificates; check support in your chosen provider.
For JDK provider behavior and supported algorithms, see the JSSE reference guide.
To enable TLS encryption, you need to configure the clients to use https:// with port 8443 for the web service URL, and pulsar+ssl:// with port 6651 for the broker service URL.
As the server certificate that you generated above does not belong to any of the default trust chains, you also need to either specify the path of the trust cert (recommended) or enable the clients to allow untrusted server certs.
The following examples show how to configure TLS encryption for Java/Python/C++/Node.js/C#/WebSocket clients.
uri ="wss://localhost:8080/ws/v2/producer/persistent/public/default/testtopic"
# encode message
s ="Hello World"
firstEncoded = s.encode("UTF-8")
binaryEncoded = base64.b64encode(firstEncoded)
payloadString = binaryEncoded.decode('UTF-8')
asyncdefproducer_handler(websocket):
await websocket.send(json.dumps({
'payload': payloadString,
'properties':{
'key1':'value1',
'key2':'value2'
},
'context':5
}))
asyncdeftest():
asyncwith websockets.connect(uri)as websocket:
await producer_handler(websocket)
message =await websocket.recv()
print(f"< {message}")
asyncio.run(test())
note
In addition to the required configurations in the conf/client.conf file, you need to configure more parameters in the conf/broker.conf file to enable TLS encryption on WebSocket service. For more details, see security settings for WebSocket.
PEM and KeyStore configurations use the same provider-selection rules. Choosing KeyStore format does not make Conscrypt the default for binary broker connections.
To configure mTLS encryption with KeyStore, complete the following steps:
Replace the example SAN with the DNS names and IP addresses used to reach your broker, for example -ext SAN=IP:127.0.0.1,IP:192.168.20.2,DNS:broker.example.com. Supply -ext when generating the key pair; it is not an option for all the export/import commands that reuse BROKER_COMMON_PARAMS.
To disable non-TLS ports, you need to set the values of brokerServicePort and webServicePort to empty.
note
The default value of tlsRequireTrustedClientCertOnConnect is false, which represents one-way TLS. When it's set to true (mutual TLS is enabled), brokers/proxies require trusted client certificates; otherwise, brokers/proxies reject connection requests from clients.
HTTPS-listener overrides; unset values inherit their general TLS counterparts.
Named providers must be available on the classpath and resolvable; an unavailable explicitly selected provider fails initialization. Format and provider are independent: for example, a deployment pinning jcaProvider=BCFIPS needs a store type that provider supports, rather than assuming JKS works. See Bouncy Castle providers.
For keys held in an HSM, external credential stores, or a different rotation mechanism, implement org.apache.pulsar.tls.PulsarTlsFactory from org.apache.pulsar:pulsar-tls-factory-api. Select it with tlsFactoryClassName and pass parameters through tlsFactoryConfig; select a separate outbound factory with brokerClientTlsFactoryClassName and brokerClientTlsFactoryConfig. The configuration accepts a JSON object or comma-separated key=value parameters. The v4 Java client and admin builders expose tlsFactoryClassName(...) and tlsFactoryConfig(...); the v5 builder also accepts a factory instance. See Custom TLS factories.
For migration from PulsarSslFactory and its configuration keys, follow the upgrade checklist.
With the built-in file-based factory, tlsCertRefreshCheckDurationSec controls periodic certificate refresh in seconds. The default is 300. Setting it to 0 disables background rotation; it does not request a certificate refresh on every new listener connection. Restart listeners to load replaced certificates when background rotation is disabled. A failed rebuild retains the last good TLS instance and retries on a later material change. Verify new connections after rotating certificates; existing TLS connections do not renegotiate merely because a file changed. Custom factories implement their own loading and reload behavior.