Skip to content

Commit

Permalink
fix: add non-vhostable buckets to path when using legacy endpoint res…
Browse files Browse the repository at this point in the history
…olver (#2417)
  • Loading branch information
lucix-aws authored Dec 7, 2023
1 parent 0d643a8 commit 9b90af4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
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

0 comments on commit 9b90af4

Please sign in to comment.