Skip to content

Commit 9b90af4

Browse files
authored
fix: add non-vhostable buckets to path when using legacy endpoint resolver (#2417)
1 parent 0d643a8 commit 9b90af4

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "422df6b2-a00a-43a6-a0ee-ac3c4f27c1a9",
3+
"type": "bugfix",
4+
"description": "Add non-vhostable buckets to request path when using legacy V1 endpoint resolver.",
5+
"modules": [
6+
"service/s3"
7+
]
8+
}

service/s3/internal/customizations/update_endpoint_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ func Test_UpdateEndpointBuild(t *testing.T) {
5555
{"abc", "k:e,y", "https://abc.s3.mock-region.amazonaws.com/k%3Ae%2Cy?x-id=GetObject", ""},
5656
},
5757
},
58+
"VirtualHostStyleBucketV1EndpointHTTPS": {
59+
customEndpoint: &aws.Endpoint{
60+
URL: "https://foo.bar",
61+
},
62+
tests: []s3BucketTest{
63+
{"abc", "key", "https://abc.foo.bar/key?x-id=GetObject", ""},
64+
{"a.b.c", "key", "https://foo.bar/a.b.c/key?x-id=GetObject", ""},
65+
},
66+
},
67+
"VirtualHostStyleBucketV1EndpointHTTP": {
68+
customEndpoint: &aws.Endpoint{
69+
URL: "http://foo.bar",
70+
},
71+
tests: []s3BucketTest{
72+
{"abc", "key", "http://abc.foo.bar/key?x-id=GetObject", ""},
73+
{"a.b.c", "key", "http://a.b.c.foo.bar/key?x-id=GetObject", ""},
74+
},
75+
},
5876
"Accelerate": {
5977
useAccelerate: true,
6078
tests: []s3BucketTest{

service/s3/serialize_immutable_hostname_bucket.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package s3
33
import (
44
"context"
55
"fmt"
6-
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
76
"path"
87

8+
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9+
910
"github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn"
1011
smithy "github.com/aws/smithy-go"
1112
"github.com/aws/smithy-go/encoding/httpbinding"
@@ -38,16 +39,20 @@ func (m *serializeImmutableHostnameBucketMiddleware) HandleSerialize(
3839
if !ok {
3940
return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)}
4041
}
41-
if !smithyhttp.GetHostnameImmutable(ctx) &&
42-
!(awsmiddleware.GetRequiresLegacyEndpoints(ctx) && m.UsePathStyle) {
43-
return next.HandleSerialize(ctx, in)
44-
}
4542

4643
bucket, ok := bucketFromInput(in.Parameters)
4744
if !ok {
4845
return next.HandleSerialize(ctx, in)
4946
}
5047

48+
// a bucket being un-vhostable will also force us to use path style
49+
usePathStyle := m.UsePathStyle || !awsrulesfn.IsVirtualHostableS3Bucket(bucket, request.URL.Scheme != "https")
50+
51+
if !smithyhttp.GetHostnameImmutable(ctx) &&
52+
!(awsmiddleware.GetRequiresLegacyEndpoints(ctx) && usePathStyle) {
53+
return next.HandleSerialize(ctx, in)
54+
}
55+
5156
parsedBucket := awsrulesfn.ParseARN(bucket)
5257

5358
// disallow ARN buckets except for MRAP arns

0 commit comments

Comments
 (0)