diff --git a/pkg/cloudprovider/aws/helpers.go b/pkg/cloudprovider/aws/helpers.go index b7747c73b6..2bdda3d864 100644 --- a/pkg/cloudprovider/aws/helpers.go +++ b/pkg/cloudprovider/aws/helpers.go @@ -18,6 +18,7 @@ package aws import ( "context" + "net/url" "github.com/pkg/errors" @@ -51,3 +52,16 @@ func GetBucketRegion(bucket string) (string, error) { return "", errors.New("unable to determine bucket's region") } + +// IsValidS3URLScheme returns true if the scheme is http:// or https:// +// and the url parses correctly, otherwise, return false +func IsValidS3URLScheme(s3URL string) bool { + u, err := url.Parse(s3URL) + if err != nil { + return false + } + if u.Scheme != "http" && u.Scheme != "https" { + return false + } + return true +} diff --git a/pkg/cloudprovider/aws/helpers_test.go b/pkg/cloudprovider/aws/helpers_test.go new file mode 100644 index 0000000000..0f3f652942 --- /dev/null +++ b/pkg/cloudprovider/aws/helpers_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 the Heptio Ark contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package aws + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestS3URL(t *testing.T) { + assert.True(t, IsValidS3URLScheme("http://foo")) + assert.True(t, IsValidS3URLScheme("https://foo")) + assert.False(t, IsValidS3URLScheme("httpd://foo")) + assert.False(t, IsValidS3URLScheme("")) +} diff --git a/pkg/cloudprovider/aws/object_store.go b/pkg/cloudprovider/aws/object_store.go index ba8ee5b55c..7784c205c0 100644 --- a/pkg/cloudprovider/aws/object_store.go +++ b/pkg/cloudprovider/aws/object_store.go @@ -85,6 +85,10 @@ func (o *objectStore) Init(config map[string]string) error { WithS3ForcePathStyle(s3ForcePathStyle) if s3URL != "" { + if !IsValidS3URLScheme(s3URL) { + return errors.Errorf("Invalid s3Url: %s", s3URL) + } + awsConfig = awsConfig.WithEndpointResolver( endpoints.ResolverFunc(func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) { if service == endpoints.S3ServiceID {