Skip to main content

Kafka Connection Security Configuration Guide

Tips

Kafka is used in the two images of this product, hdp and flink. Adjusting the security configuration requires overall modification.

Description of connection configuration parameters

Environment variablesDescriptionDefault value
ENV_KAFKA_ENDPOINTSKafka Broker address list, multiple addresses separated by commas127.0.0.1:9092
ENV_KAFKA_SECURITY_PROTOCOLKafka security protocol modeempty
ENV_KAFKA_SASL_MECHANISMSASL authentication mechanismempty
ENV_KAFKA_SASL_USERNAMESASL usernameempty
ENV_KAFKA_SASL_PASSWORDSASL passwordempty
ENV_KAFKA_SSL_CA_LOCATIONKafka CA certificate pathEmpty
ENV_KAFKA_SSL_CLIENT_CA_LOCATIONKafka client certificate pathempty
ENV_KAFKA_SSL_CLIENT_KEY_LOCATIONKafka client private key pathEmpty

Security protocol mode description

Kafka supports multiple security authentication modes, including Plaintext, SaslPlaintext, Ssl, SaslSsl.

1. Plaintext (default mode)

No security authentication mechanism is enabled, only clear text communication is used, and no SASL or SSL related parameters need to be configured.

2. SaslPlaintext (enable SASL authentication)

Authentication is performed using the SASL mechanism, but data transmission remains clear text.

The configuration file needs to add the following environment variables:

Environment variablesDescription
ENV_KAFKA_SECURITY_PROTOCOLSet to SaslPlaintext
ENV_KAFKA_SASL_MECHANISMSASL authentication mechanism, fixed to PLAIN
ENV_KAFKA_SASL_USERNAMESASL username
ENV_KAFKA_SASL_PASSWORDSASL password

3. Ssl (enable TLS encryption)

Encrypt communications using TLS/SSL, but do not enable SASL authentication.

The configuration file needs to add the following environment variables:

Environment variablesDescription
ENV_KAFKA_SECURITY_PROTOCOLSet to Ssl
ENV_KAFKA_SSL_CA_LOCATIONCA root certificate path
ENV_KAFKA_SSL_CLIENT_CA_LOCATIONClient certificate path
ENV_KAFKA_SSL_CLIENT_KEY_LOCATIONClient private key path

4. SaslSsl (enable SASL + TLS)

Enable both SASL authentication and SSL encrypted communication (recommended security mode).

The configuration file needs to add the following environment variables:

Environment variablesDescription
ENV_KAFKA_SECURITY_PROTOCOLSet to SaslSsl
ENV_KAFKA_SASL_MECHANISMSASL authentication mechanism, fixed to PLAIN
ENV_KAFKA_SASL_USERNAMESASL username
ENV_KAFKA_SASL_PASSWORDSASL password
ENV_KAFKA_SSL_CA_LOCATIONCA root certificate (PEM format)
ENV_KAFKA_SSL_CLIENT_CA_LOCATIONClient certificate (PEM format)
ENV_KAFKA_SSL_CLIENT_KEY_LOCATIONClient private key (PEM format)

TLS certificate configuration

When using Ssl or SaslSsl, a TLS certificate is required in the container.

Certificate File

The following PEM certificates need to be prepared:

DocumentationDescription
ca.crtKafka CA root certificate
client.crtClient Certificate
client.keyClient private key

Directory example:

volume/kafka/
├─ ca.crt
├─ client.crt
└─ client.key

Docker mounting certificate example

The certificate needs to be mounted inside the container:

volumes:
- ./volume/kafka/ca.crt:/usr/local/kafka/ca.crt
- ./volume/kafka/client.crt:/usr/local/kafka/client.crt
- ./volume/kafka/client.key:/usr/local/kafka/client.key

The corresponding environment variable values ​​are as follows (the environment variable path must be consistent with the internal path of the container):

ENV_KAFKA_SSL_CA_LOCATION: "/usr/local/kafka/ca.crt"
ENV_KAFKA_SSL_CLIENT_CA_LOCATION: "/usr/local/kafka/client.crt"
ENV_KAFKA_SSL_CLIENT_KEY_LOCATION: "/usr/local/kafka/client.key"