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

[Filebeat] Improve validation check for Azure configuration #20389

Merged
merged 2 commits into from
Aug 10, 2020
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 @@ -235,6 +235,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix `okta` geoip lookup in pipeline for `destination.ip` {pull}20454[20454]
- Fix mapping exception in the `googlecloud/audit` dataset pipeline. {issue}18465[18465] {pull}20465[20465]
- Fix `cisco` asa and ftd parsing of messages 106102 and 106103. {pull}20469[20469]
- Improve validation checks for Azure configuration {issue}20369[20369] {pull}20389[20389]

*Heartbeat*

Expand Down
27 changes: 27 additions & 0 deletions x-pack/filebeat/input/azureeventhub/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package azureeventhub
import (
"errors"
"fmt"
"unicode"
)

type azureInputConfig struct {
Expand Down Expand Up @@ -36,6 +37,32 @@ func (conf *azureInputConfig) Validate() error {
}
if conf.SAContainer == "" {
conf.SAContainer = fmt.Sprintf("%s-%s", ephContainerName, conf.EventHubName)

}
err := storageContainerValidate(conf.SAContainer)
if err != nil {
return err
}

return nil
}

func storageContainerValidate(name string) error {
runes := []rune(name)
length := len(runes)
if length < 3 {
return fmt.Errorf("storage_account_container (%s) must be 3 or more characters", name)
}
if length > 63 {
return fmt.Errorf("storage_account_container (%s) must be less than 63 characters", name)
}
if !unicode.IsLower(runes[0]) && !unicode.IsNumber(runes[0]) {
return fmt.Errorf("storage_account_container (%s) must start with a lowercase letter or number", name)
}
for i := 0; i < length; i++ {
if !unicode.IsLower(runes[i]) && !unicode.IsNumber(runes[i]) && !('-' == runes[i]) {
return fmt.Errorf("rune %d of storage_account_container (%s) is not a lowercase letter, number or dash", i, name)
}
}
return nil
}
29 changes: 29 additions & 0 deletions x-pack/filebeat/input/azureeventhub/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package azureeventhub

import (
"testing"
)

func TestStorageContainerValidate(t *testing.T) {
var tests = []struct {
input string
errIsNil bool
}{
{"a-valid-name", true},
{"a", false},
{"a-name-that-is-really-too-long-to-be-valid-and-should-never-be-used-no-matter-what", false},
{"-not-valid", false},
{"capital-A-not-valid", false},
{"no_underscores_either", false},
}
for _, test := range tests {
err := storageContainerValidate(test.input)
if (err == nil) != test.errIsNil {
t.Errorf("storageContainerValidate(%s) = %v", test.input, err)
}
}
}