Skip to content

Commit 4ef5e61

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

File tree

7 files changed

+59
-1
lines changed

7 files changed

+59
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* [FEATURE] Create OpenTelemetry Bridge for Tracing. Now cortex can send traces to multiple destinations using OTEL Collectors. #4834
5353
* [FEATURE] Added `-api.http-request-headers-to-log` allowing for the addition of HTTP Headers to logs #4803
5454
* [FEATURE] Distributor: Added a new limit `-validation.max-labels-size-bytes` allowing to limit the combined size of labels for each timeseries. #4848
55+
* [FEATURE] Storage/Bucket: Added `-*.s3.bucket-lookup-type` allowing to configure the s3 bucket lookup type. #4794
5556
* [BUGFIX] Memberlist: Add join with no retrying when starting service. #4804
5657
* [BUGFIX] Ruler: Fix /ruler/rule_groups returns YAML with extra fields. #4767
5758

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
@@ -1397,6 +1397,11 @@ s3:
13971397
# CLI flag: -ruler-storage.s3.signature-version
13981398
[signature_version: <string> | default = "v4"]
13991399
1400+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
1401+
# path.
1402+
# CLI flag: -ruler-storage.s3.bucket-lookup-type
1403+
[bucket_lookup_type: <string> | default = "auto"]
1404+
14001405
# The s3_sse_config configures the S3 server-side encryption.
14011406
# The CLI flags prefix for this block config is: ruler-storage
14021407
[sse: <s3_sse_config>]
@@ -1839,6 +1844,11 @@ s3:
18391844
# CLI flag: -alertmanager-storage.s3.signature-version
18401845
[signature_version: <string> | default = "v4"]
18411846
1847+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
1848+
# path.
1849+
# CLI flag: -alertmanager-storage.s3.bucket-lookup-type
1850+
[bucket_lookup_type: <string> | default = "auto"]
1851+
18421852
# The s3_sse_config configures the S3 server-side encryption.
18431853
# The CLI flags prefix for this block config is: alertmanager-storage
18441854
[sse: <s3_sse_config>]
@@ -3081,6 +3091,11 @@ s3:
30813091
# CLI flag: -blocks-storage.s3.signature-version
30823092
[signature_version: <string> | default = "v4"]
30833093
3094+
# The s3 bucket lookup style. Supported values are: auto, virtual-hosted,
3095+
# path.
3096+
# CLI flag: -blocks-storage.s3.bucket-lookup-type
3097+
[bucket_lookup_type: <string> | default = "auto"]
3098+
30843099
# The s3_sse_config configures the S3 server-side encryption.
30853100
# The CLI flags prefix for this block config is: blocks-storage
30863101
[sse: <s3_sse_config>]

pkg/storage/bucket/s3/bucket_client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func newS3Config(cfg Config) (s3.Config, error) {
3232
if err != nil {
3333
return s3.Config{}, err
3434
}
35+
bucketLookupType, err := cfg.bucketLookupType()
36+
if err != nil {
37+
return s3.Config{}, err
38+
}
3539

3640
return s3.Config{
3741
Bucket: cfg.BucketName,
@@ -53,6 +57,7 @@ func newS3Config(cfg Config) (s3.Config, error) {
5357
Transport: cfg.HTTP.Transport,
5458
},
5559
// Enforce signature version 2 if CLI flag is set
56-
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
60+
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
61+
BucketLookupType: bucketLookupType,
5762
}, nil
5863
}

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, error) {
110+
switch cfg.BucketLookupType {
111+
case BucketVirtualHostLookup:
112+
return s3.VirtualHostLookup, nil
113+
case BucketPathLookup:
114+
return s3.PathLookup, nil
115+
case BucketAutoLookup:
116+
return s3.AutoLookup, nil
117+
default:
118+
return s3.AutoLookup, errInvalidBucketLookupType
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)