From 1d4e317e8396314770f721dd5b3173d811e047fe Mon Sep 17 00:00:00 2001 From: Christian Leinweber Date: Mon, 30 May 2022 08:38:51 +0200 Subject: [PATCH] prevent operator from panic on invalid characters within eventhub-storage path Signed-off-by: Christian Leinweber --- CHANGELOG.md | 4 +--- pkg/scalers/azure/azure_eventhub_checkpoint.go | 16 +++++++++++++--- pkg/scalers/azure/azure_eventhub_test.go | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66cc2a53f19..ea1bfedd190 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,10 +47,8 @@ To learn more about our roadmap, we recommend reading [this document](ROADMAP.md ### Fixes - **General:** Use metricName from GetMetricsSpec in ScaledJobs instead of `queueLength` ([#3032](https://github.com/kedacore/keda/issue/3032)) - -### Fixes - - **General:** Refactor adapter startup to ensure proper log initilization. ([2316](https://github.com/kedacore/keda/issues/2316)) +- **Azure Eventhub Scaler:** KEDA operator crashes on nil memory panic if the eventhub connectionstring for Azure Eventhub Scaler contains an invalid character ([#3082](https://github.com/kedacore/keda/issues/3082)) ### Deprecations diff --git a/pkg/scalers/azure/azure_eventhub_checkpoint.go b/pkg/scalers/azure/azure_eventhub_checkpoint.go index 3fccadf938d..21da44f8737 100644 --- a/pkg/scalers/azure/azure_eventhub_checkpoint.go +++ b/pkg/scalers/azure/azure_eventhub_checkpoint.go @@ -125,7 +125,10 @@ func (checkpointer *azureFunctionCheckpointer) resolvePath(info EventHubInfo) (* return nil, err } - path, _ := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/%s", checkpointer.containerName, eventHubNamespace, eventHubName, info.EventHubConsumerGroup, checkpointer.partitionID)) + path, err := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/%s", checkpointer.containerName, eventHubNamespace, eventHubName, info.EventHubConsumerGroup, checkpointer.partitionID)) + if err != nil { + return nil, err + } return path, nil } @@ -148,7 +151,11 @@ func (checkpointer *blobMetadataCheckpointer) resolvePath(info EventHubInfo) (*u return nil, err } - path, _ := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/checkpoint/%s", checkpointer.containerName, eventHubNamespace, eventHubName, strings.ToLower(info.EventHubConsumerGroup), checkpointer.partitionID)) + path, err := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/checkpoint/%s", checkpointer.containerName, eventHubNamespace, eventHubName, strings.ToLower(info.EventHubConsumerGroup), checkpointer.partitionID)) + if err != nil { + return nil, err + } + return path, nil } @@ -159,7 +166,10 @@ func (checkpointer *blobMetadataCheckpointer) extractCheckpoint(get *azblob.Down // resolve path for goSdkCheckpointer func (checkpointer *goSdkCheckpointer) resolvePath(info EventHubInfo) (*url.URL, error) { - path, _ := url.Parse(fmt.Sprintf("/%s/%s", info.BlobContainer, checkpointer.partitionID)) + path, err := url.Parse(fmt.Sprintf("/%s/%s", info.BlobContainer, checkpointer.partitionID)) + if err != nil { + return nil, err + } return path, nil } diff --git a/pkg/scalers/azure/azure_eventhub_test.go b/pkg/scalers/azure/azure_eventhub_test.go index 2f7f2f30dd3..76aeb4be1f4 100644 --- a/pkg/scalers/azure/azure_eventhub_test.go +++ b/pkg/scalers/azure/azure_eventhub_test.go @@ -322,6 +322,22 @@ func TestShouldParseCheckpointForBlobMetadata(t *testing.T) { assert.Equal(t, url.Path, "/containername/eventhubnamespace.servicebus.windows.net/hub-test/$default/checkpoint/0") } +func TestShouldParseCheckpointForBlobMetadataWithError(t *testing.T) { + eventHubInfo := EventHubInfo{ + EventHubConnection: "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub-test\n", + EventHubConsumerGroup: "$Default", + BlobContainer: "containername", + CheckpointStrategy: "blobMetadata", + } + + cp := newCheckpointer(eventHubInfo, "0") + _, err := cp.resolvePath(eventHubInfo) + + if err == nil { + t.Errorf("Should have return an err on invalid url characters") + } +} + func TestShouldParseCheckpointForBlobMetadataWithPodIdentity(t *testing.T) { eventHubInfo := EventHubInfo{ Namespace: "eventhubnamespace",