Skip to content

Commit c0c6a99

Browse files
committed
Make s3 bucket lookup type configurable
Signed-off-by: Xiaochao Dong (@damnever) <[email protected]>
1 parent 2575a0a commit c0c6a99

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784
55
* [ENHANCEMENT] Querier/Ruler: Retry store-gateway in case of unexpected failure, instead of failing the query. #4532
66
* [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787
7+
* [FEATURE] Storage/Bucket: Added `-*.s3.bucket-lookup-type` allowing to configure the s3 bucket lookup type. #4787
78

89
## 1.13.0 2022-07-14
910
* [CHANGE] Changed default for `-ingester.min-ready-duration` from 1 minute to 15 seconds. #4539

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)