Skip to content

Commit

Permalink
Improve validation check for Azure configuration (elastic#20389)
Browse files Browse the repository at this point in the history
A blob container name must be between 3 and 63 characters in length;
start with a letter or number; and contain only letters, numbers, and
the hyphen. All letters used in blob container names must be
lowercase.  Added validation to make sure the storage container name
meets those requirements.

Closes elastic#20369
  • Loading branch information
leehinman authored Aug 10, 2020
1 parent 368d31b commit 7913005
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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)
}
}
}

0 comments on commit 7913005

Please sign in to comment.