If you enable ciphertext access when creating an instance, SASL authentication will be required when your client connects to a Kafka instance.
For security purposes, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 is supported.
This section describes how to use an open-source Kafka client to access a Kafka instance if ciphertext access has been enabled for the instance. There are two scenarios. To access a Kafka instance across VPCs, see Accessing Kafka Using a VPC Endpoint Across VPCs. To access a Kafka instance using DNAT, see Accessing Kafka in a Public Network Using DNAT. To access an instance in your service code, see the Distributed Message Service Developer Guide.
Each Kafka broker allows a maximum of 1000 connections from each IP address by default. Excess connections will be rejected. You can change the limit by referring to Modifying Kafka Instance Configuration Parameters, that is, to modify parameter max.connections.per.ip.
To access a Kafka instance with ciphertext access enabled, configure proper security group rules. For details about security group configuration requirements, see Table 2.
In the Connection area on the Kafka instance details page, view SASL Mechanism. If both SCRAM-SHA-512 and PLAIN are enabled, use either of them in connection configurations. For instances that were created much earlier, if SASL Mechanism is not displayed on the instance details page, PLAIN is used by default.
In the Connection area on the Kafka instance details page, view Security Protocol. For instances that were created much earlier, if Security Protocol is not displayed on the instance details page, SASL_SSL is used by default.
Later instances use the new certificate client.jks, and earlier ones use the old certificate client.truststore.jks. Later instances are incompatible with the old certificate, and earlier ones are incompatible with the new certificate.
To determine whether a certificate is new, download it on the console and check its name.
Add the following lines to the .bash_profile file in the home directory as an authorized user. In this command, /opt/java/jdk1.8.0_151 is the JDK installation path. Change it to the path where you install JDK.
export JAVA_HOME=/opt/java/jdk1.8.0_151 export PATH=$JAVA_HOME/bin:$PATH
Run the source .bash_profile command for the modification to take effect.
The following uses Linux as an example.
Set IP addresses to the instance connection addresses obtained in Prerequisites. Set hosts to the names of instance hosts. Specify a unique name for each host.
For example:
10.154.48.120 server01
10.154.48.121 server02
10.154.48.122 server03
Access the directory where the CLI package is stored and run the following command to decompress the package:
tar -zxf [kafka_tar]
In the preceding command, [kafka_tar] indicates the name of the CLI package.
For example:
tar -zxf kafka_2.12-2.7.2.tgz
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \ username="**********" \ password="**********"; sasl.mechanism=PLAIN
Parameter description:
username and password: username and password you set when enabling ciphertext access for the first time or when creating a user.
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \ username="**********" \ password="**********"; sasl.mechanism=SCRAM-SHA-512
Parameter description:
username and password: username and password you set when enabling ciphertext access for the first time or when creating a user.
security.protocol=SASL_SSL ssl.truststore.location={ssl_truststore_path} ssl.truststore.password=dms@kafka ssl.endpoint.identification.algorithm=
Parameter description:
security.protocol=SASL_PLAINTEXT
In Windows, you need to access the /bin/windows directory.
./kafka-console-producer.sh --broker-list ${connection addr} --topic ${topic name} --producer.config ../config/producer.properties
Parameter description:
The following example uses connection addresses 10.xx.xx.45:9095,10.xx.xx.127:9095,10.xx.xx.103:9095.
After running the preceding command, you can send a message to the Kafka instance by writing it and pressing Enter. Each line of content is sent as a message.
[root@ecs-kafka bin]#./kafka-console-producer.sh --broker-list 10.xx.xx.45:9095,10.xx.xx.127:9095,10.xx.xx.103:9095 --topic topic-demo --producer.config ../config/producer.properties >Hello >DMS >Kafka! >^C[root@ecs-kafka bin]#
To stop creating messages, press Ctrl+C to exit.
./kafka-console-consumer.sh --bootstrap-server ${connection-address} --topic ${topic-name} --group ${consumer-group-name} --from-beginning --consumer.config ../config/consumer.properties
Parameter description:
Example:
[root@ecs-kafka bin]# ./kafka-console-consumer.sh --bootstrap-server 10.xx.xx.45:9095,10.xx.xx.127:9095,10.xx.xx.103:9095 --topic topic-demo --group order-test --from-beginning --consumer.config ../config/consumer.properties Hello DMS Kafka! ^CProcessed a total of 3 messages [root@ecs-kafka bin]#
To stop retrieving messages, press Ctrl+C to exit.