Skip to content

Commit

Permalink
additional bucket name validation for S3 bucket regex
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinaik1312 authored and rnaik-godaddy committed Sep 1, 2020
1 parent 587d7f8 commit cb291e3
Show file tree
Hide file tree
Showing 3 changed files with 37 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 @@ -352,6 +352,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
*Functionbeat*

- Fix timeout option of GCP functions. {issue}16282[16282] {pull}16287[16287]
- Fix catchall bucket config errors by adding more validation. {issue}17572[16282] {pull}20887[16287]

==== Added

Expand Down
6 changes: 6 additions & 0 deletions x-pack/functionbeat/provider/aws/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func (b *bucket) Unpack(s string) error {
return fmt.Errorf("bucket name '%s' is too short, name need to be at least %d chars long", s, min)
}

const bucketNamePattern = "^[a-z0-9][a-z0-9.\\-]{1,61}[a-z0-9]$"
var bucketRE = regexp.MustCompile(bucketNamePattern)
if !bucketRE.MatchString(s) {
return fmt.Errorf("invalid bucket name: '%s', bucket name must match pattern: '%s'", s, bucketNamePattern)
}

*b = bucket(s)
return nil
}
Expand Down
30 changes: 30 additions & 0 deletions x-pack/functionbeat/provider/aws/aws/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ func TestBucket(t *testing.T) {
err := b.Unpack("he")
assert.Error(t, err)
})

t.Run("bucket regex pattern, disallows semi-colon", func(t *testing.T) {
b := bucket("")
err := b.Unpack("asdfdaf;dfadsfadsf")
assert.Error(t, err)
})

t.Run("bucket regex pattern, disallows slash", func(t *testing.T) {
b := bucket("")
err := b.Unpack("asdfdaf/dfadsfadsf")
assert.Error(t, err)
})

t.Run("bucket regex pattern, allows dots", func(t *testing.T) {
b := bucket("")
err := b.Unpack("this.is.a.bucket")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, bucket("this.is.a.bucket"), b)
})

t.Run("bucket regex pattern, allows hyphens", func(t *testing.T) {
b := bucket("")
err := b.Unpack("this-is-a-bucket")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, bucket("this-is-a-bucket"), b)
})
}

func TestNormalize(t *testing.T) {
Expand Down

0 comments on commit cb291e3

Please sign in to comment.