Authentication using TLS
provides TLS related cipher suites and algorithms in Pulsar. If you need version of Bouncy Castle Provider
, please reference Bouncy Castle page.
Client certificates are generated using the certificate authority. Server certificates are also generated with the same certificate authority.
The biggest difference between client certs and server certs is that the common name for the client certificate is the role token which that client is authenticated as.
To use client certificates, you need to set tlsRequireTrustedClientCertOnConnect=true
at the broker side. For details, refer to .
First, you need to enter the following command to generate the key :
$ openssl pkcs8 -topk8 -inform PEM -outform PEM \
-in admin.key.pem -out admin.key-pk8.pem -nocrypt
Next, enter the command below to generate the certificate request. When you are asked for a common name, enter the role token that you want this key pair to authenticate a client as.
$ openssl req -config openssl.cnf \
-key admin.key.pem -new -sha256 -out admin.csr.pem
note
If openssl.cnf is not specified, read to get the openssl.cnf.
Then, enter the command below to sign with request with the certificate authority. Note that the client certs uses the usr_cert extension, which allows the cert to be used for client authentication.
$ openssl ca -config openssl.cnf -extensions usr_cert \
-days 1000 -notext -md sha256 \
-in admin.csr.pem -out admin.cert.pem
You can get a cert, admin.cert.pem
, and a key, admin.key-pk8.pem
from this command. With ca.cert.pem
, clients can use this cert and this key to authenticate themselves to brokers and proxies as the role token admin
.
note
If the “unable to load CA private key” error occurs and the reason of this error is “No such file or directory: /etc/pki/CA/private/cakey.pem” in this step. Try the command below:
To configure brokers to authenticate clients, add the following parameters to broker.conf
, alongside :
# Configuration to enable authentication
authenticationEnabled=true
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderTls
superUserRoles=admin
# Authentication settings of the broker itself. Used when the broker connects to other brokers, either in same or other clusters
brokerClientTlsEnabled=true
brokerClientAuthenticationParameters={"tlsCertFile":"/path/my-ca/admin.cert.pem","tlsKeyFile":"/path/my-ca/admin.key-pk8.pem"}
brokerClientTrustCertsFilePath=/path/my-ca/certs/ca.cert.pem
To configure proxies to authenticate clients, add the following parameters to proxy.conf
, alongside the configuration to enable tls transport:
The proxy should have its own client key pair for connecting to brokers. You need to configure the role token for this key pair in the proxyRoles
of the brokers. See the for more details.
# For clients connecting to the proxy
authenticationEnabled=true
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderTls
# For the proxy to connect to brokers
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTls
brokerClientAuthenticationParameters=tlsCertFile:/path/to/proxy.cert.pem,tlsKeyFile:/path/to/proxy.key-pk8.pem
When you use TLS authentication, client connects via TLS transport. You need to configure the client to use https://
and 8443 port for the web service URL, pulsar+ssl://
and 6651 port for the broker service URL.
CLI tools
like pulsar-admin, , and pulsar-client use the conf/client.conf
config file in a Pulsar installation.
webServiceUrl=https://broker.example.com:8443/
brokerServiceUrl=pulsar+ssl://broker.example.com:6651/
useTls=true
tlsAllowInsecureConnection=false
tlsTrustCertsFilePath=/path/to/ca.cert.pem
authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTls
authParams=tlsCertFile:/path/to/my-role.cert.pem,tlsKeyFile:/path/to/my-role.key-pk8.pem
Python client
from pulsar import Client, AuthenticationTLS
auth = AuthenticationTLS("/path/to/my-role.cert.pem", "/path/to/my-role.key-pk8.pem")
client = Client("pulsar+ssl://broker.example.com:6651/",
tls_allow_insecure_connection=False,
authentication=auth)
#include <pulsar/Client.h>
pulsar::ClientConfiguration config;
config.setUseTls(true);
config.setTlsTrustCertsFilePath("/path/to/ca.cert.pem");
config.setTlsAllowInsecureConnection(false);
pulsar::AuthenticationPtr auth = pulsar::AuthTls::create("/path/to/my-role.cert.pem",
"/path/to/my-role.key-pk8.pem")
config.setAuth(auth);
pulsar::Client client("pulsar+ssl://broker.example.com:6651/", config);
Node.js client
const Pulsar = require('pulsar-client');
(async () => {
const auth = new Pulsar.AuthenticationTls({
certificatePath: '/path/to/my-role.cert.pem',
privateKeyPath: '/path/to/my-role.key-pk8.pem',
});
const client = new Pulsar.Client({
serviceUrl: 'pulsar+ssl://broker.example.com:6651/',
authentication: auth,
tlsTrustCertsFilePath: '/path/to/ca.cert.pem',
})();