From bce33756073562a462251dba7f2638aa0b393ca6 Mon Sep 17 00:00:00 2001 From: Dao Thanh Tung Date: Fri, 16 Jun 2023 19:32:57 +0800 Subject: [PATCH] Kafka Scaler: add back `strings.TrimSpace()` function for saslAuthType (#4693) --- CHANGELOG.md | 11 ++++++----- pkg/scalers/kafka_scaler.go | 2 +- pkg/scalers/kafka_scaler_test.go | 12 ++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ab2d6da1f..ecfb8153acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,19 +48,19 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio - **CPU/Memory scaler**: Add support for scale to zero if there are multiple triggers([#4269](https://github.com/kedacore/keda/issues/4269)) - **Redis Scalers**: Allow scaling using redis stream length ([#4277](https://github.com/kedacore/keda/issues/4277)) -- **General:** Introduce new Solr Scaler ([#4234](https://github.com/kedacore/keda/issues/4234)) +- **General**: Introduce new Solr Scaler ([#4234](https://github.com/kedacore/keda/issues/4234)) ### Improvements - **General**: Metrics Adapter: remove deprecated Prometheus Metrics and non-gRPC code ([#3930](https://github.com/kedacore/keda/issues/3930)) -- **AWS DynamoDB:** Add support for `indexName` ([#4680](https://github.com/kedacore/keda/issues/4680)) +- **AWS DynamoDB**: Add support for `indexName` ([#4680](https://github.com/kedacore/keda/issues/4680)) - **Azure Data Explorer Scaler**: Use azidentity SDK ([#4489](https://github.com/kedacore/keda/issues/4489)) - **External Scaler**: Add tls options in TriggerAuth metadata. ([#3565](https://github.com/kedacore/keda/issues/3565)) - **GCP PubSub Scaler**: Make it more flexible for metrics ([#4243](https://github.com/kedacore/keda/issues/4243)) -- **Kafka Scaler:** Add support for OAuth extensions ([#4544](https://github.com/kedacore/keda/issues/4544)) -- **NATS JetStream Scaler:** Add support for pulling AccountID from TriggerAuthentication ([#4586]https://github.com/kedacore/keda/issues/4586) +- **Kafka Scaler**: Add support for OAuth extensions ([#4544](https://github.com/kedacore/keda/issues/4544)) +- **NATS JetStream Scaler**: Add support for pulling AccountID from TriggerAuthentication ([#4586]https://github.com/kedacore/keda/issues/4586) - **Pulsar Scaler**: Improve error messages for unsuccessful connections ([#4563](https://github.com/kedacore/keda/issues/4563)) -- **Security:** Enable secret scanning in GitHub repo +- **Security**: Enable secret scanning in GitHub repo - **RabbitMQ Scaler**: Add support for `unsafeSsl` in trigger metadata ([#4448](https://github.com/kedacore/keda/issues/4448)) - **Prometheus Metrics**: Add new metric with KEDA build info ([#4647](https://github.com/kedacore/keda/issues/4647)) - **Prometheus Scaler**: Add support for Google Managed Prometheus ([#4675](https://github.com/kedacore/keda/pull/4675)) @@ -76,6 +76,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio - **Prometheus Metrics**: Create e2e tests for all exposed Prometheus metrics ([#4127](https://github.com/kedacore/keda/issues/4127)) - **Grafana Dashboard**: Fix HPA metrics panel to use range instead of instant ([#4513](https://github.com/kedacore/keda/pull/4513)) - **Grafana Dashboard**: Fix HPA metrics panel by replacing $namepsace to $exported_namespace due to label conflict ([#4539](https://github.com/kedacore/keda/pull/4539)) +- **Kafka Scaler**: Add back `strings.TrimSpace()` function for saslAuthType ([#4689](https://github.com/kedacore/keda/issues/4689)) ### Deprecations diff --git a/pkg/scalers/kafka_scaler.go b/pkg/scalers/kafka_scaler.go index 00de4af29ef..c13670f8d7d 100644 --- a/pkg/scalers/kafka_scaler.go +++ b/pkg/scalers/kafka_scaler.go @@ -134,7 +134,6 @@ func parseKafkaAuthParams(config *ScalerConfig, meta *kafkaMetadata) error { default: saslAuthType = "" } - if val, ok := config.AuthParams["sasl"]; ok { if saslAuthType != "" { return errors.New("unable to set `sasl` in both ScaledObject and TriggerAuthentication together") @@ -143,6 +142,7 @@ func parseKafkaAuthParams(config *ScalerConfig, meta *kafkaMetadata) error { } if saslAuthType != "" { + saslAuthType = strings.TrimSpace(saslAuthType) mode := kafkaSaslType(saslAuthType) if mode == KafkaSASLTypePlaintext || mode == KafkaSASLTypeSCRAMSHA256 || mode == KafkaSASLTypeSCRAMSHA512 || mode == KafkaSASLTypeOAuthbearer { diff --git a/pkg/scalers/kafka_scaler_test.go b/pkg/scalers/kafka_scaler_test.go index 31db0e98af7..32daa453830 100644 --- a/pkg/scalers/kafka_scaler_test.go +++ b/pkg/scalers/kafka_scaler_test.go @@ -222,6 +222,18 @@ var parseAuthParamsTestDataset = []parseAuthParamsTestDataSecondAuthMethod{ {map[string]string{"sasl": "scram_sha512", "bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "scram_sha512", "username": "admin", "password": "admin"}, true, false}, // failure, setting TLS values in both places {map[string]string{"tls": "enable", "bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"tls": "enable", "ca": "caaa", "cert": "ceert", "key": "keey"}, true, true}, + // success, setting SASL plaintext value with extra \n in TriggerAuthentication + {map[string]string{"bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "plaintext\n", "username": "admin", "password": "admin"}, false, true}, + // success, setting SASL plaintext value with extra space in TriggerAuthentication + {map[string]string{"bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "plaintext ", "username": "admin", "password": "admin"}, false, true}, + // success, setting SASL scram_sha256 value with extra \n in TriggerAuthentication + {map[string]string{"bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "scram_sha256\n", "username": "admin", "password": "admin"}, false, true}, + // success, setting SASL scram_sha256 value with extra space in TriggerAuthentication + {map[string]string{"bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "scram_sha256 ", "username": "admin", "password": "admin"}, false, true}, + // success, setting SASL scram_sha512 value with extra \n in TriggerAuthentication + {map[string]string{"bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "scram_sha512\n", "username": "admin", "password": "admin"}, false, true}, + // success, setting SASL scram_sha512 value with extra space in TriggerAuthentication + {map[string]string{"bootstrapServers": "foobar:9092", "consumerGroup": "my-group", "topic": "my-topic", "allowIdleConsumers": "true", "version": "1.0.0"}, map[string]string{"sasl": "scram_sha512 ", "username": "admin", "password": "admin"}, false, true}, } var parseKafkaOAuthbrearerAuthParamsTestDataset = []parseKafkaAuthParamsTestData{