Skip to content

Commit d236e40

Browse files
committed
Make s3 bucket lookup type configurable
Signed-off-by: Xiaochao Dong (@damnever) <the.xcdong@gmail.com>
1 parent a795d53 commit d236e40

File tree

7 files changed

+55
-1
lines changed

7 files changed

+55
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* [FEATURE] Ruler: Add support to pass custom implementations of queryable and pusher. #4782
5151
* [FEATURE] Create OpenTelemetry Bridge for Tracing. Now cortex can send traces to multiple destinations using OTEL Collectors. #4834
5252
* [FEATURE] Added `-api.http-request-headers-to-log` allowing for the addition of HTTP Headers to logs #4803
53+
* [FEATURE] Storage/Bucket: Added `-*.s3.bucket-lookup-type` allowing to configure the s3 bucket lookup type. #4794
5354
* [BUGFIX] Memberlist: Add join with no retrying when starting service. #4804
5455
* [BUGFIX] Ruler: Fix /ruler/rule_groups returns YAML with extra fields. #4767
5556

docs/blocks-storage/querier.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ blocks_storage:
264264
# CLI flag: -blocks-storage.s3.signature-version
265265
[signature_version: <string> | default = "v4"]
266266
267+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
268+
# path.
269+
# CLI flag: -blocks-storage.s3.bucket-lookup-type
270+
[bucket_lookup_type: <string> | default = "auto"]
271+
267272
# The s3_sse_config configures the S3 server-side encryption.
268273
# The CLI flags prefix for this block config is: blocks-storage
269274
[sse: <s3_sse_config>]

docs/blocks-storage/store-gateway.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ blocks_storage:
329329
# CLI flag: -blocks-storage.s3.signature-version
330330
[signature_version: <string> | default = "v4"]
331331
332+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
333+
# path.
334+
# CLI flag: -blocks-storage.s3.bucket-lookup-type
335+
[bucket_lookup_type: <string> | default = "auto"]
336+
332337
# The s3_sse_config configures the S3 server-side encryption.
333338
# The CLI flags prefix for this block config is: blocks-storage
334339
[sse: <s3_sse_config>]

docs/configuration/config-file-reference.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,11 @@ s3:
13931393
# CLI flag: -ruler-storage.s3.signature-version
13941394
[signature_version: <string> | default = "v4"]
13951395
1396+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
1397+
# path.
1398+
# CLI flag: -ruler-storage.s3.bucket-lookup-type
1399+
[bucket_lookup_type: <string> | default = "auto"]
1400+
13961401
# The s3_sse_config configures the S3 server-side encryption.
13971402
# The CLI flags prefix for this block config is: ruler-storage
13981403
[sse: <s3_sse_config>]
@@ -1835,6 +1840,11 @@ s3:
18351840
# CLI flag: -alertmanager-storage.s3.signature-version
18361841
[signature_version: <string> | default = "v4"]
18371842
1843+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
1844+
# path.
1845+
# CLI flag: -alertmanager-storage.s3.bucket-lookup-type
1846+
[bucket_lookup_type: <string> | default = "auto"]
1847+
18381848
# The s3_sse_config configures the S3 server-side encryption.
18391849
# The CLI flags prefix for this block config is: alertmanager-storage
18401850
[sse: <s3_sse_config>]
@@ -3072,6 +3082,11 @@ s3:
30723082
# CLI flag: -blocks-storage.s3.signature-version
30733083
[signature_version: <string> | default = "v4"]
30743084
3085+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
3086+
# path.
3087+
# CLI flag: -blocks-storage.s3.bucket-lookup-type
3088+
[bucket_lookup_type: <string> | default = "auto"]
3089+
30753090
# The s3_sse_config configures the S3 server-side encryption.
30763091
# The CLI flags prefix for this block config is: blocks-storage
30773092
[sse: <s3_sse_config>]

pkg/storage/bucket/s3/bucket_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func newS3Config(cfg Config) (s3.Config, error) {
5353
Transport: cfg.HTTP.Transport,
5454
},
5555
// Enforce signature version 2 if CLI flag is set
56-
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
56+
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
57+
BucketLookupType: cfg.bucketLookupType(),
5758
}, nil
5859
}

pkg/storage/bucket/s3/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ const (
2727
// SSES3 config type constant to configure S3 server side encryption with AES-256
2828
// https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html
2929
SSES3 = "SSE-S3"
30+
31+
BucketAutoLookup = "auto"
32+
BucketVirtualHostLookup = "virtual-hosted"
33+
BucketPathLookup = "path"
3034
)
3135

3236
var (
3337
supportedSignatureVersions = []string{SignatureVersionV4, SignatureVersionV2}
3438
supportedSSETypes = []string{SSEKMS, SSES3}
39+
supportedBucketLookupTypes = []string{BucketAutoLookup, BucketVirtualHostLookup, BucketPathLookup}
3540
errUnsupportedSignatureVersion = errors.New("unsupported signature version")
3641
errUnsupportedSSEType = errors.New("unsupported S3 SSE type")
3742
errInvalidSSEContext = errors.New("invalid S3 SSE encryption context")
43+
errInvalidBucketLookupType = errors.New("invalid bucket lookup type")
3844
)
3945

4046
// HTTPConfig stores the http.Transport configuration for the s3 minio client.
@@ -59,6 +65,7 @@ type Config struct {
5965
AccessKeyID string `yaml:"access_key_id"`
6066
Insecure bool `yaml:"insecure"`
6167
SignatureVersion string `yaml:"signature_version"`
68+
BucketLookupType string `yaml:"bucket_lookup_type"`
6269

6370
SSE SSEConfig `yaml:"sse"`
6471
HTTP HTTPConfig `yaml:"http"`
@@ -78,6 +85,7 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
7885
f.StringVar(&cfg.Endpoint, prefix+"s3.endpoint", "", "The S3 bucket endpoint. It could be an AWS S3 endpoint listed at https://docs.aws.amazon.com/general/latest/gr/s3.html or the address of an S3-compatible service in hostname:port format.")
7986
f.BoolVar(&cfg.Insecure, prefix+"s3.insecure", false, "If enabled, use http:// for the S3 endpoint instead of https://. This could be useful in local dev/test environments while using an S3-compatible backend storage, like Minio.")
8087
f.StringVar(&cfg.SignatureVersion, prefix+"s3.signature-version", SignatureVersionV4, fmt.Sprintf("The signature version to use for authenticating against S3. Supported values are: %s.", strings.Join(supportedSignatureVersions, ", ")))
88+
f.StringVar(&cfg.BucketLookupType, prefix+"s3.bucket-lookup-type", BucketAutoLookup, fmt.Sprintf("The s3 bucket lookup style. Supported values are: %s.", strings.Join(supportedBucketLookupTypes, ", ")))
8189
cfg.SSE.RegisterFlagsWithPrefix(prefix+"s3.sse.", f)
8290
cfg.HTTP.RegisterFlagsWithPrefix(prefix, f)
8391
}
@@ -87,6 +95,9 @@ func (cfg *Config) Validate() error {
8795
if !util.StringsContain(supportedSignatureVersions, cfg.SignatureVersion) {
8896
return errUnsupportedSignatureVersion
8997
}
98+
if !util.StringsContain(supportedBucketLookupTypes, cfg.BucketLookupType) {
99+
return errInvalidBucketLookupType
100+
}
90101

91102
if err := cfg.SSE.Validate(); err != nil {
92103
return err
@@ -95,6 +106,19 @@ func (cfg *Config) Validate() error {
95106
return nil
96107
}
97108

109+
func (cfg *Config) bucketLookupType() s3.BucketLookupType {
110+
switch cfg.BucketLookupType {
111+
case BucketVirtualHostLookup:
112+
return s3.VirtualHostLookup
113+
case BucketPathLookup:
114+
return s3.PathLookup
115+
default:
116+
fallthrough
117+
case BucketAutoLookup:
118+
return s3.AutoLookup
119+
}
120+
}
121+
98122
// SSEConfig configures S3 server side encryption
99123
// struct that is going to receive user input (through config file or CLI)
100124
type SSEConfig struct {

pkg/storage/bucket/s3/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// defaultConfig should match the default flag values defined in RegisterFlagsWithPrefix.
1818
var defaultConfig = Config{
1919
SignatureVersion: SignatureVersionV4,
20+
BucketLookupType: BucketAutoLookup,
2021
HTTP: HTTPConfig{
2122
Config: bucket_http.Config{
2223
IdleConnTimeout: 90 * time.Second,
@@ -53,6 +54,7 @@ secret_access_key: test-secret-access-key
5354
access_key_id: test-access-key-id
5455
insecure: true
5556
signature_version: test-signature-version
57+
bucket_lookup_type: virtual-hosted
5658
sse:
5759
type: test-type
5860
kms_key_id: test-kms-key-id
@@ -75,6 +77,7 @@ http:
7577
AccessKeyID: "test-access-key-id",
7678
Insecure: true,
7779
SignatureVersion: "test-signature-version",
80+
BucketLookupType: BucketVirtualHostLookup,
7881
SSE: SSEConfig{
7982
Type: "test-type",
8083
KMSKeyID: "test-kms-key-id",

0 commit comments

Comments
 (0)