Starlight for Kafka security
This page covers enabling authentication features for Starlight for Kafka.
Starlight for Kafka supports SASL/PLAIN authentication, JWT authorization, and SSL encryption.
Starlight for Kafka is installed with no authentication, authorization, or encryption, but these can be enabled to improve security.
|
These features are only available in Java. |
Authentication
Starlight for Kafka authentication uses the Kafka SASL/PLAIN mechanisms and Pulsar token-based mechanisms.
OAUTHBEARER authentication is also available.
Enabling authentication for Starlight for Kafka requires enabling authentication for the following components:
-
Pulsar brokers
-
Starlight for Kafka (some configurations of S4K rely on the configurations of Pulsar brokers)
-
Kafka clients
Currently, Starlight for Kafka only supports the PLAIN SASL mechanism, but there are more to come.
PLAIN authentication
Authenticate Starlight for Kafka with the PLAIN SASL mechanism, follow the steps below.
-
Enable authentication on the Pulsar broker. For the
PLAINmechanism, Kafka authentication is forwarded to the JWT authentication of Pulsar, so you need to configure the JWT authentication by setting the following properties inconf/broker.conf.Modify
conf/standalone.confif you’re using a standalone Pulsar deployment.-
Enable authentication for the Pulsar broker.
authenticationEnabled=true authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderToken -
Enable authentication between the Pulsar broker and Starlight for Kafka.
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken brokerClientAuthenticationParameters=token:<token-of-super-user-role> superUserRoles=<super-user-roles> -
Specify the key. For more information, see Enable Token Authentication on Brokers.
-
If using a secret key, set the property as below.
tokenSecretKey=file:///path/to/secret.key -
To pass the key inline, set the property as below.
tokenSecretKey=data:;base64,FLFyW0oLJ2Fi22KKCm21J18mbAdztfSHN/lAT5ucEKU= -
If using a public/private key, set the property as below.
tokenPublicKey=file:///path/to/public.key
-
-
-
Enable authentication on Starlight for Kafka. Set the following property in the
conf/broker.conf:saslAllowedMechanisms=PLAIN -
Enable authentication on the Kafka client. To forward your credentials,
SASL-PLAINis used on the Kafka client side. To enableSASL-PLAIN, set the following properties through Kafka JAAS.
| Property | Description | Example Value |
|---|---|---|
|
|
The |
|
|
|
security.protocol=SASL_PLAINTEXT
# or security.protocol=SASL_SSL if SSL connection is used
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule \
required username="public/default" password="token:xxx";
For more on passing credentials with JAAS, see Configuring SASL/PLAIN.
OAUTHBEARER authentication
Authenticate Starlight for Kafka using the OAUTHBEARER mechanism by following the steps below.
-
Enable authentication on the Pulsar broker. Set the following properties in the
conf/broker.conforconf/standalone.conffile.The properties are the same as
PLAINauthentication except forbrokerClientAuthenticationPluginandbrokerClientAuthenticationParameters.Property Description Required or optional Example value audienceAn OAuth 2.0 "resource server" identifier for the Pulsar cluster
Optional
issuerUrlURL of the authentication provider which allows the Pulsar client to obtain an access token
Required
privateKeyURL to a JSON credential file. The following pattern formats are supported:
-
file:/path/to/file -
data:application/json;base64,<base64-encoded value>
Required
scopeThe scope of the access request that is expressed as a list of space-delimited, case-sensitive strings
Optional
api://pulsar-cluster-1/.defaulttypeOAuth 2.0 authentication type
Default:
client_credentialsOptional
client_credentialsHere is an example
conf/broker.conffile:authenticationEnabled=true authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderToken superUserRoles=<super-user-roles> brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2 brokerClientAuthenticationParameters={"type":"client_credentials","privateKey":"file:///path/to/credentials_file.json""issuerUrl":"<issuer-url>","audience":"<audience>"} tokenPublicKey=<token-public-key> -
Enable authentication on S4K. Set the following property in the
conf/broker.conforconf/standalone.conffile:saslAllowedMechanisms=OAUTHBEARER -
Specify the Kafka server callback handler. For the
OAUTHBEARERmechanism, useAuthenticationProviderTokenor customize your authentication provider to process the access tokens from an OAuth 2.0 server. S4K provides a built-inAuthenticateCallbackHandlerthat uses the authentication provider of Pulsar for authentication. You need to configure the following properties in theconf/kop-handler.propertiesfile:# Use S4K's built-in handler: kopOauth2AuthenticateCallbackHandler=io.streamnative.pulsar.handlers.kop.security.oauth.OauthValidatorCallbackHandler # Java property configuration file of OauthValidatorCallbackHandler kopOauth2ConfigFile=conf/kop-handler.properties -
Specify the authentication method name of the provider (
oauth.validate.method) in theconf/kop-handler.propertiesfile. By default, it uses thetokenauthentication method.-
If you have configured the
tokenauthentication method, you don’t need to specify the authentication method name. -
If you use
AuthenticationProviderToken, sinceAuthenticationProviderToken#getAuthMethodName()returnstoken, set theoauth.validate.methodas the token. -
If you use other providers, set the
oauth.validate.methodas the result ofgetAuthMethodName().oauth.validate.method=token
-
-
Enable authentication on Kafka client. Install the S4K built-in callback handler to your local Maven repository.
-
To retrieve an access token from an OAuth 2.0 server, use the S4K built-in callback handler instead of the Kafka login callback handler.
mvn clean install -pl oauth-client -DskipTests -
Add the following dependencies to the
pom.xmlfile. For stable releases, thepulsar.versionis the same as thekop.version.<dependency> <groupId>com.datastax.oss</groupId> <artifactId>oauth-client</artifactId> <version>${version}</version> </dependency> -
Configure the producer or consumer with the following required properties:
Property Description Example value Note sasl.login.callback.handler.classClass of SASL login callback handler
com.datastax.oss.kafka.oauth.OauthLoginCallbackHandlerSet this value to the value in the example properties configuration below.
security.protocolSecurity protocol
SASL_PLAINTEXTsasl.mechanismSASL mechanism
OAUTHBEARERsasl.jaas.configJAAS configuration
org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModuleoauth.issuer.urlURL of the authentication provider which allows the Pulsar client to obtain an access token.
This property is the same to the issuerUrl property as Pulsar client credentials.
oauth.credentials.urlURL to a JSON credentials file.
The following pattern formats are supported:
-
file:/path/to/file -
data:application/json;base64,<base64-encoded value>
This property is the same as the privateKey property in Pulsar client credentials.
oauth.audienceOAuth 2.0 "resource server" identifier for the Pulsar cluster.
This property is the same as the audience property in Pulsar client credentials.
oauth.scopeThe scope of the access request that is expressed as a list of space-delimited, case-sensitive strings.
api://pulsar-cluster-1/.defaultThis property is the same as the scope property in Pulsar client credentials.
Here is an example properties configuration:
sasl.login.callback.handler.class=com.datastax.oss.kafka.oauth.OauthLoginCallbackHandler security.protocol=SASL_PLAINTEXT # or security.protocol=SASL_SSL if SSL connection is used sasl.mechanism=OAUTHBEARER sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule \ required oauth.issuer.url="https://accounts.google.com"\ oauth.credentials.url="file:///path/to/credentials_file.json"\ oauth.audience="https://broker.example.com";
Authorization
To enable authorization on Starlight for Kafka, ensure that authentication is enabled first.
For more on authorization in Pulsar, see Pulsar Authorization.
-
Enable authorization and assign superusers for the Pulsar broker:
authorizationEnabled=true -
Generate JWT tokens. A token is the credential associated with a user. The association is done through the
principalorrole. In the case of JWT tokens, this field is typically referred assubject, though they are exactly the same concept.Use this command to require the generated token to have a
subjectfield set:bin/pulsar tokens create --secret-key file:///path/to/secret.key \ --subject <user-role>This command prints the token string on
stdout. -
Grant permission to a specific role. The token itself doesn’t have any permissions associated with it. The authorization engine determines whether the token should have permissions or not. Once you have created the token, you can grant permission for this token.
For example, to grant a role to the
user-rolecreated above:bin/pulsar-admin --auth-plugin "org.apache.pulsar.client.impl.auth.AuthenticationToken" --auth-params "token:<token-of-super-user-role>" \ namespaces grant-permission <tenant>/<namespace> \ --role <user-role> \ --actions produce,consume
SSL encryption
This section explains connecting and configuring Starlight for Kafka with SSL. There are two methods available:
-
Existing TLS certificates (Recommended): Use the TLS certificates already configured for the Pulsar TLS endpoint to also connect the Kafka client. This is a new feature of Starlight for Kafka designed to make TLS connection fast and painless. Proceed to Create SSL connection with Pulsar.
-
Dedicated TLS certificates: Create dedicated TLS certificates and modify the Pulsar broker and Kafka client. Instructions for this method are here.
Create SSL configuration with Pulsar
Starlight for Kafka features fast, painless TLS configuration between Pulsar and Kafka. Instead of creating different certificates for the Pulsar broker and Kafka client, simply modify broker.conf to pick up the existing Pulsar TLS certifications and configurations.
-
Configure TLS on the Pulsar broker. For more information, see Create TLS certificates.
-
Expose TLS endpoints by adding the following configurations to
broker.conf:kopTlsEnabledWithBroker=true kafkaListeners=PLAINTEXT://127.0.0.1:9092, SSL://PRIVATE-HOSTNAME-OF-THE-BROKER:9093 kafkaAdvertisedListeners=PLAINTEXT://127.0.0.1:9092, SSL://PUBLIC-HOSTNAME-OF-THE-BROKER:9093These settings enable TLS on the broker, and then Starlight for Kafka picks up the TLS certificates automatically.
-
To test your configuration, produce and consume some messages with Starlight for Kafka.
Create SSL configuration manually
The following example shows how to manually configure Starlight for Kafka with SSL.
Starlight for Kafka supports PLAINTEXT and SSL configuration types for Kafka listeners. SSL listeners are added to the comma-separated list of URIs in kafkaListeners, as follows:
kafkalisteners=PLAINTEXT://localhost:9092,SSL://localhost:9093
For more on generating SSL keys for Kafka brokers, see Kafka SSL.
-
Create SSL related keys. This example creates the related CA and JKS files:
# Input a password, for example "server-keystore". keytool -keystore server.keystore.jks -alias localhost -validity 365 -keyalg RSA -genkey # Input a password, for example "server". openssl req -new -x509 -keyout ca-key -out ca-cert -days 365 # Input a password, for example "server-truststore" keytool -keystore server.truststore.jks -alias CARoot -import -file ca-cert # Input a password, for example "client-truststore" keytool -keystore client.truststore.jks -alias CARoot -import -file ca-cert # Input the password of server.keystore.jks: "server-keystore" keytool -keystore server.keystore.jks -alias localhost -certreq -file cert-file # The password followed by `-passin pass:` is the password of ca-cert: "server" openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 365 -CAcreateserial -passin pass:server # You must input the password of server.keystore.jks: "server-keystore" keytool -keystore server.keystore.jks -alias CARoot -import -file ca-cert # You must input the password of server.keystore.jks: "server-keystore" keytool -keystore server.keystore.jks -alias localhost -import -file cert-signedIn the above example, there are four passwords provided:
-
server-keystoreforserver.keystore.jks -
serverforca-certandca-key -
server-truststoreforserver.truststore.jks -
client-truststoreforclient.truststore.jks
-
-
Configure the Pulsar broker. In
conf/broker.conf, add the related configurations using the JKS configurations created in the previous step:listeners=PLAINTEXT://localhost:9092,SSL://localhost:9093 # You need to use the full path of server.keystore.jks kopSslKeystoreLocation=server.keystore.jks kopSslKeystorePassword=server-keystore kopSslKeyPassword=server-keystore # You need to use the full path of server.truststore.jks kopSslTruststoreLocation=server.truststore.jks kopSslTruststorePassword=server-truststore -
Configure the Kafka client. Create a file named
client-ssl.propertiesinkafka/configwith the following configuration:security.protocol=SSL # Include the full path of client.truststore.jks ssl.truststore.location=client.truststore.jks ssl.truststore.password=client-truststore # The identification algorithm must be empty ssl.endpoint.identification.algorithm= -
Verify the console-producer and the console-consumer send messages when started with
client-ssl.properties:kafka-console-producer.sh --broker-list localhost:9093 --topic test --producer.config client-ssl.properties kafka-console-consumer.sh --bootstrap-server localhost:9093 --topic test --consumer.config client-ssl.properties
For more on configuring Kafka, see Configure Kafka client.
See also
For more on Starlight for Kafka, see: