Skip to content

Commit

Permalink
Merge pull request #13410 from mixja/s3-uri-gov-cloud
Browse files Browse the repository at this point in the history
Correctly detect GovCloud regions
  • Loading branch information
k8s-ci-robot committed Mar 26, 2022
2 parents f6e64c8 + 210d072 commit 65226b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions util/pkg/vfs/s3context.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ import (
"k8s.io/klog/v2"
)

// matches all regional naming conventions of S3:
// https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
// matches regional naming conventions of S3:
// https://docs.aws.amazon.com/general/latest/gr/s3.html
// TODO: match fips and S3 access point naming conventions
// TODO: perhaps make region regex more specific, i.e. (us|eu|ap|cn|ca|sa), to prevent matching bucket names that match region format?
// but that will mean updating this list when AWS introduces new regions
var s3UrlRegexp = regexp.MustCompile(`(s3([-.](?P<region>\w{2}-\w+-\d{1})|[-.](?P<bucket>[\w.\-\_]+)|)?|(?P<bucket>[\w.\-\_]+)[.]s3([.](?P<region>\w{2}-\w+-\d{1}))?)[.]amazonaws[.]com([.]cn)?(?P<path>.*)?`)
var s3UrlRegexp = regexp.MustCompile(`(s3([-.](?P<region>\w{2}(-gov)?-\w+-\d{1})|[-.](?P<bucket>[\w.\-\_]+)|)?|(?P<bucket>[\w.\-\_]+)[.]s3([.-](?P<region>\w{2}(-gov)?-\w+-\d{1}))?)[.]amazonaws[.]com([.]cn)?(?P<path>.*)?`)

type S3BucketDetails struct {
// context is the S3Context we are associated with
Expand Down
20 changes: 20 additions & 0 deletions util/pkg/vfs/s3context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func Test_VFSPath(t *testing.T) {
ExpectedResult: "s3://bucket/path",
ExpectError: false,
},
{
Input: "https://s3.us-gov-west-1.amazonaws.com/bucket",
ExpectedResult: "s3://bucket",
ExpectError: false,
},
{
Input: "https://s3.us-gov-west-1.amazonaws.com/bucket/path",
ExpectedResult: "s3://bucket/path",
ExpectError: false,
},
{
Input: "https://s3.amazonaws.com/bucket",
ExpectedResult: "s3://bucket",
Expand Down Expand Up @@ -124,6 +134,16 @@ func Test_VFSPath(t *testing.T) {
ExpectedResult: "s3://bucket-name/path",
ExpectError: false,
},
{
Input: "https://bucket-name.s3-us-gov-west-1.amazonaws.com",
ExpectedResult: "s3://bucket-name",
ExpectError: false,
},
{
Input: "https://bucket-name.s3-us-gov-west-1.amazonaws.com/path",
ExpectedResult: "s3://bucket-name/path",
ExpectError: false,
},
{
Input: "example.com/bucket",
ExpectedResult: "",
Expand Down

0 comments on commit 65226b1

Please sign in to comment.