Skip to content

Commit

Permalink
Mask Azure SharedAccessKey in connection URL
Browse files Browse the repository at this point in the history
Signed-off-by: Renuka Fernando <[email protected]>
  • Loading branch information
renuka-fernando committed Feb 19, 2024
1 parent d72f32f commit 4aad92a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion adapter/pkg/messaging/azure_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (
"context"
"errors"
"os"
"regexp"
"strconv"
"time"

asb "github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus"
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus/admin"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
logger "github.com/wso2/product-microgateway/adapter/pkg/loggers"
)

Expand Down Expand Up @@ -83,7 +85,9 @@ func InitiateBrokerConnectionAndValidate(connectionString string, componentName
_, err := asb.NewClientFromConnectionString(connectionString, nil)

if err == nil {
logger.LoggerMsg.Debugf("ASB client initialized for connection url: %s", connectionString)
if logger.LoggerMsg.IsLevelEnabled(logrus.DebugLevel) {
logger.LoggerMsg.Debugf("ASB client initialized for connection url: %s", maskSharedAccessKey(connectionString))
}

for j := 0; j < reconnectRetryCount || reconnectRetryCount == -1; j++ {
err = nil
Expand Down Expand Up @@ -169,3 +173,9 @@ func logError(reconnectRetryCount int, reconnectInterval time.Duration, errVal e
}
logger.LoggerMsg.Errorf("%v. %s .Retrying after %s seconds", errVal, retryAttemptMessage, reconnectInterval)
}

func maskSharedAccessKey(endpoint string) string {
re := regexp.MustCompile(`(SharedAccessKey=)([^;]+)`)
maskedEndpoint := re.ReplaceAllString(endpoint, "${1}************")
return maskedEndpoint
}

0 comments on commit 4aad92a

Please sign in to comment.