Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip Azure EventHub connection string in debug logs #25066

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
}
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)",
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
},
{
"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