Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add non-vhostable buckets to path when using endpoints v1 #2417

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/422df6b2a00a43a6a0eeac3c4f27c1a9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "422df6b2-a00a-43a6-a0ee-ac3c4f27c1a9",
"type": "bugfix",
"description": "Add non-vhostable buckets to request path when using legacy V1 endpoint resolver.",
"modules": [
"service/s3"
]
}
18 changes: 18 additions & 0 deletions service/s3/internal/customizations/update_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ func Test_UpdateEndpointBuild(t *testing.T) {
{"abc", "k:e,y", "https://abc.s3.mock-region.amazonaws.com/k%3Ae%2Cy?x-id=GetObject", ""},
},
},
"VirtualHostStyleBucketV1EndpointHTTPS": {
customEndpoint: &aws.Endpoint{
URL: "https://foo.bar",
},
tests: []s3BucketTest{
{"abc", "key", "https://abc.foo.bar/key?x-id=GetObject", ""},
{"a.b.c", "key", "https://foo.bar/a.b.c/key?x-id=GetObject", ""},
},
},
"VirtualHostStyleBucketV1EndpointHTTP": {
customEndpoint: &aws.Endpoint{
URL: "http://foo.bar",
},
tests: []s3BucketTest{
{"abc", "key", "http://abc.foo.bar/key?x-id=GetObject", ""},
{"a.b.c", "key", "http://a.b.c.foo.bar/key?x-id=GetObject", ""},
},
},
"Accelerate": {
useAccelerate: true,
tests: []s3BucketTest{
Expand Down
15 changes: 10 additions & 5 deletions service/s3/serialize_immutable_hostname_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package s3
import (
"context"
"fmt"
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"path"

awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"

"github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn"
smithy "github.com/aws/smithy-go"
"github.com/aws/smithy-go/encoding/httpbinding"
Expand Down Expand Up @@ -38,16 +39,20 @@ func (m *serializeImmutableHostnameBucketMiddleware) HandleSerialize(
if !ok {
return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)}
}
if !smithyhttp.GetHostnameImmutable(ctx) &&
!(awsmiddleware.GetRequiresLegacyEndpoints(ctx) && m.UsePathStyle) {
return next.HandleSerialize(ctx, in)
}

bucket, ok := bucketFromInput(in.Parameters)
if !ok {
return next.HandleSerialize(ctx, in)
}

// a bucket being un-vhostable will also force us to use path style
usePathStyle := m.UsePathStyle || !awsrulesfn.IsVirtualHostableS3Bucket(bucket, request.URL.Scheme != "https")

if !smithyhttp.GetHostnameImmutable(ctx) &&
!(awsmiddleware.GetRequiresLegacyEndpoints(ctx) && usePathStyle) {
return next.HandleSerialize(ctx, in)
}

parsedBucket := awsrulesfn.ParseARN(bucket)

// disallow ARN buckets except for MRAP arns
Expand Down
Loading