Skip to content

Commit

Permalink
Strip Azure EventHub connection string in debug logs (#25066)
Browse files Browse the repository at this point in the history
* Strip Azure EventHub connection string in debug logs
  • Loading branch information
Carlos Pérez-Aradros Herce authored Apr 14, 2021
1 parent f056efb commit 96fa570
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix a connection error in httpjson input. {pull}16123[16123]
- Fix integer overflow in S3 offsets when collecting very large files. {pull}22523[22523]
- Fix CredentialsJSON unpacking for `gcp-pubsub` and `httpjson` inputs. {pull}23277[23277]
- Strip Azure Eventhub connection string in debug logs. {pulll}[]

*Filebeat*

Expand Down
17 changes: 16 additions & 1 deletion x-pack/filebeat/input/azureeventhub/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -80,7 +81,7 @@ func NewInput(

in := &azureInput{
config: config,
log: logp.NewLogger(fmt.Sprintf("%s input", inputName)).With("connection string", config.ConnectionString),
log: logp.NewLogger(fmt.Sprintf("%s input", inputName)).With("connection string", stripConnectionString(config.ConnectionString)),
context: inputContext,
workerCtx: workerCtx,
workerCancel: workerCancel,
Expand Down Expand Up @@ -235,3 +236,17 @@ func (a *azureInput) parseMultipleMessages(bMessage []byte) []string {
}
return messages
}

// Strip connection string to remove sensitive information
// A connection string should look like this:
// Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=
// This code will remove everything after ';' so key information is stripped
func stripConnectionString(c string) string {
if parts := strings.SplitN(c, ";", 2); len(parts) == 2 {
return parts[0]
}

// We actually expect the string to have the documented format
// if we reach here something is wrong, so let's stay on the safe side
return "(redacted)"
}
24 changes: 24 additions & 0 deletions x-pack/filebeat/input/azureeventhub/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,30 @@ func TestNewInputDone(t *testing.T) {
inputtest.AssertNotStartedInputCanBeDone(t, NewInput, &config)
}

func TestStripConnectionString(t *testing.T) {
tests := []struct {
connectionString, expected string
}{
{
"Endpoint=sb://something",
"(redacted)",
},
{
"Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=",
"Endpoint=sb://dummynamespace.servicebus.windows.net/",
},
{
"Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=",
"Endpoint=sb://dummynamespace.servicebus.windows.net/",
},
}

for _, tt := range tests {
res := stripConnectionString(tt.connectionString)
assert.Equal(t, res, tt.expected)
}
}

type stubOutleter struct {
sync.Mutex
cond *sync.Cond
Expand Down

0 comments on commit 96fa570

Please sign in to comment.