awslabs / aws-servicebroker

AWS Service Broker
Apache License 2.0
468 stars 131 forks source link

Provisioning fails if helm chart installed with `aws.key=""` #252

Open mkhattab opened 2 years ago

mkhattab commented 2 years ago

Describe the bug

The following assumes the service broker is configured to use a custom S3 bucket. If the aws.key field during helm install is set to an empty string, i.e.

helm install aws-sb aws-sb/aws-servicebroker \
    # other options ...
    --set aws.key=""

Provisioning will fail with the following message (in the logs):

Failed to create the CloudFormation stack: ValidationError: S3 error: Access Denied

I believe I have narrowed to this specific line:

bl := AwsBroker{
        ...
    s3key:   addTrailingSlash(o.S3Key),   // This sets s3key: "/" if o.S3Key = ""
        ...
}

I think the fix in addTrailingSlash should check if the string is empty before adding a trailing slash.

func addTrailingSlash(s string) string {
    if s != "" && strings.HasSuffix(s, "/") == false {  // add check to make sure `s` is not empty
        s = s + "/"
    }
    return s
}

It's probably a good idea to trim whitespace here as well, although not sure if it's necessary (just thinking defensively).

To Reproduce

Install helm chart with --set aws.key=""

Expected behavior

Should provision resources normally.

Screenshots

None

Environment (please complete the following information):

Additional context

Nope