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 1 commit
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 @@ -231,6 +231,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix millisecond timestamp normalization issues in CrowdStrike module {issue}20035[20035], {pull}20138[20138]
- Fix support for message code 106100 in Cisco ASA and FTD. {issue}19350[19350] {pull}20245[20245]
- Fix `fortinet` setting `event.timezone` to the system one when no `tz` field present {pull}20273[20273]
- 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)
}
}
}