Merge pull request #8342 from volodymyr-babak/ssl-option-kafka

[3.5] Add SSL option for Kafka queue connection
This commit is contained in:
Andrew Shvayka 2023-04-11 12:34:49 +03:00 committed by GitHub
commit bc5d6ea359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 0 deletions

View File

@ -988,6 +988,13 @@ queue:
print-interval-ms: "${TB_QUEUE_IN_MEMORY_STATS_PRINT_INTERVAL_MS:60000}"
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip

View File

@ -19,6 +19,7 @@ import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.common.config.SslConfigs;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
@ -49,6 +50,24 @@ public class TbKafkaSettings {
@Value("${queue.kafka.bootstrap.servers}")
private String servers;
@Value("${queue.kafka.ssl.enabled:false}")
private boolean sslEnabled;
@Value("${queue.kafka.ssl.truststore.location}")
private String sslTruststoreLocation;
@Value("${queue.kafka.ssl.truststore.password}")
private String sslTruststorePassword;
@Value("${queue.kafka.ssl.keystore.location}")
private String sslKeystoreLocation;
@Value("${queue.kafka.ssl.keystore.password}")
private String sslKeystorePassword;
@Value("${queue.kafka.ssl.key.password}")
private String sslKeyPassword;
@Value("${queue.kafka.acks}")
private String acks;
@ -115,6 +134,8 @@ public class TbKafkaSettings {
props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
props.put(AdminClientConfig.RETRIES_CONFIG, retries);
configureSSL(props);
return props;
}
@ -126,6 +147,8 @@ public class TbKafkaSettings {
props.put(ConsumerConfig.FETCH_MAX_BYTES_CONFIG, fetchMaxBytes);
props.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalMs);
configureSSL(props);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
@ -164,7 +187,21 @@ public class TbKafkaSettings {
if (other != null) {
other.forEach(kv -> props.put(kv.getKey(), kv.getValue()));
}
configureSSL(props);
return props;
}
private void configureSSL(Properties props) {
if (sslEnabled) {
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslTruststoreLocation);
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslTruststorePassword);
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslKeystoreLocation);
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslKeystorePassword);
props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, sslKeyPassword);
}
}
}

View File

@ -50,6 +50,13 @@ queue:
print-interval-ms: "${TB_QUEUE_IN_MEMORY_STATS_PRINT_INTERVAL_MS:60000}"
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip

View File

@ -151,6 +151,13 @@ queue:
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip

View File

@ -136,6 +136,13 @@ queue:
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip

View File

@ -217,6 +217,13 @@ queue:
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip

View File

@ -166,6 +166,13 @@ queue:
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip

View File

@ -112,6 +112,13 @@ queue:
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
kafka:
bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}"
ssl:
enabled: "${TB_KAFKA_SSL_ENABLED:false}"
truststore.location: "${TB_KAFKA_SSL_TRUSTSTORE_LOCATION:}"
truststore.password: "${TB_KAFKA_SSL_TRUSTSTORE_PASSWORD:}"
keystore.location: "${TB_KAFKA_SSL_KEYSTORE_LOCATION:}"
keystore.password: "${TB_KAFKA_SSL_KEYSTORE_PASSWORD:}"
key.password: "${TB_KAFKA_SSL_KEY_PASSWORD:}"
acks: "${TB_KAFKA_ACKS:all}"
retries: "${TB_KAFKA_RETRIES:1}"
compression.type: "${TB_KAFKA_COMPRESSION_TYPE:none}" # none or gzip