Skip to content

Commit 2670896

Browse files
authored
Add option to use v2 signatures for S3 blocks store (#3540)
* Add option to use v2 signatures for S3 blocks store This allow to configure the block store client to use V2 signatures for S3 authentication. Signed-off-by: Christian Simon <[email protected]> * Use an option parameter for the S3 signature version Signed-off-by: Christian Simon <[email protected]>
1 parent 08256a9 commit 2670896

File tree

11 files changed

+88
-22
lines changed

11 files changed

+88
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* [ENHANCEMENT] Compactor: added a config validation check to fail fast if the compactor has been configured invalid block range periods (each period is expected to be a multiple of the previous one). #3534
3131
* [ENHANCEMENT] Blocks storage: concurrently fetch deletion marks from object storage. #3538
3232
* [ENHANCEMENT] Blocks storage ingester: ingester can now close idle TSDB and delete local data. #3491
33+
* [ENHANCEMENT] Blocks storage: add option to use V2 signatures for S3 authentication. #3540
3334
* [BUGFIX] Blocks storage ingester: fixed some cases leading to a TSDB WAL corruption after a partial write to disk. #3423
3435
* [BUGFIX] Blocks storage: Fix the race between ingestion and `/flush` call resulting in overlapping blocks. #3422
3536
* [BUGFIX] Querier: fixed `-querier.max-query-into-future` which wasn't correctly enforced on range queries. #3452

docs/blocks-storage/querier.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ blocks_storage:
225225
# CLI flag: -blocks-storage.s3.insecure
226226
[insecure: <boolean> | default = false]
227227
228+
# The signature version to use for authenticating against S3. Supported
229+
# values are: v4, v2.
230+
# CLI flag: -blocks-storage.s3.signature-version
231+
[signature_version: <string> | default = "v4"]
232+
228233
http:
229234
# The time an idle connection will remain idle before closing.
230235
# CLI flag: -blocks-storage.s3.http.idle-conn-timeout

docs/blocks-storage/store-gateway.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ blocks_storage:
275275
# CLI flag: -blocks-storage.s3.insecure
276276
[insecure: <boolean> | default = false]
277277
278+
# The signature version to use for authenticating against S3. Supported
279+
# values are: v4, v2.
280+
# CLI flag: -blocks-storage.s3.signature-version
281+
[signature_version: <string> | default = "v4"]
282+
278283
http:
279284
# The time an idle connection will remain idle before closing.
280285
# CLI flag: -blocks-storage.s3.http.idle-conn-timeout

docs/configuration/config-file-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,11 @@ s3:
34293429
# CLI flag: -blocks-storage.s3.insecure
34303430
[insecure: <boolean> | default = false]
34313431
3432+
# The signature version to use for authenticating against S3. Supported values
3433+
# are: v4, v2.
3434+
# CLI flag: -blocks-storage.s3.signature-version
3435+
[signature_version: <string> | default = "v4"]
3436+
34323437
http:
34333438
# The time an idle connection will remain idle before closing.
34343439
# CLI flag: -blocks-storage.s3.http.idle-conn-timeout

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require (
5353
github.com/sony/gobreaker v0.4.1
5454
github.com/spf13/afero v1.2.2
5555
github.com/stretchr/testify v1.6.1
56-
github.com/thanos-io/thanos v0.13.1-0.20201125083044-ca8be00eaf6e
56+
github.com/thanos-io/thanos v0.13.1-0.20201125124348-2008ef009e88
5757
github.com/uber/jaeger-client-go v2.25.0+incompatible
5858
github.com/weaveworks/common v0.0.0-20201119133501-0619918236ec
5959
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,8 @@ github.com/thanos-io/thanos v0.13.1-0.20200807203500-9b578afb4763/go.mod h1:KyW0
11461146
github.com/thanos-io/thanos v0.13.1-0.20201019130456-f41940581d9a/go.mod h1:A3qUEEbsVkplJnxyDLwuIuvTDaJPByTH+hMdTl9ujAA=
11471147
github.com/thanos-io/thanos v0.13.1-0.20201030101306-47f9a225cc52 h1:z3hglXVwJ4HgU0OoDS+8+MvEipv/U83IQ+fMsDr00YQ=
11481148
github.com/thanos-io/thanos v0.13.1-0.20201030101306-47f9a225cc52/go.mod h1:OqqX4x21cg5N5MMHd/yGQAc/V3wg8a7Do4Jk8HfaFZQ=
1149-
github.com/thanos-io/thanos v0.13.1-0.20201125083044-ca8be00eaf6e h1:cf/9Osa+ledD0KrP+STooekIFgIp+XUx7tl14jXYni8=
1150-
github.com/thanos-io/thanos v0.13.1-0.20201125083044-ca8be00eaf6e/go.mod h1:ffr9z+gefM664JBH/CEMHyHvShq2BQTejT/Ws+V+80Q=
1149+
github.com/thanos-io/thanos v0.13.1-0.20201125124348-2008ef009e88 h1:r3lyiYA58zA6yE4CqE0ncavgI2rHgyhLQom5z0usbNM=
1150+
github.com/thanos-io/thanos v0.13.1-0.20201125124348-2008ef009e88/go.mod h1:ffr9z+gefM664JBH/CEMHyHvShq2BQTejT/Ws+V+80Q=
11511151
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
11521152
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
11531153
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=

pkg/storage/backend/s3/bucket_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ func newS3Config(cfg Config) s3.Config {
3030
InsecureSkipVerify: cfg.HTTP.InsecureSkipVerify,
3131
Transport: cfg.HTTP.Transport,
3232
},
33+
// Enforce signature version 2 if CLI flag is set
34+
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
3335
}
3436
}

pkg/storage/backend/s3/config.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
package s3
22

33
import (
4+
"errors"
45
"flag"
6+
"fmt"
57
"net/http"
8+
"strings"
69
"time"
710

11+
"github.com/cortexproject/cortex/pkg/util"
812
"github.com/cortexproject/cortex/pkg/util/flagext"
913
)
1014

15+
const (
16+
SignatureVersionV4 = "v4"
17+
SignatureVersionV2 = "v2"
18+
)
19+
20+
var (
21+
supportedSignatureVersions = []string{SignatureVersionV4, SignatureVersionV2}
22+
errUnsupportedSignatureVersion = errors.New("unsupported signature version")
23+
)
24+
1125
// HTTPConfig stores the http.Transport configuration for the s3 minio client.
1226
type HTTPConfig struct {
1327
IdleConnTimeout time.Duration `yaml:"idle_conn_timeout"`
@@ -27,11 +41,12 @@ func (cfg *HTTPConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
2741

2842
// Config holds the config options for an S3 backend
2943
type Config struct {
30-
Endpoint string `yaml:"endpoint"`
31-
BucketName string `yaml:"bucket_name"`
32-
SecretAccessKey flagext.Secret `yaml:"secret_access_key"`
33-
AccessKeyID string `yaml:"access_key_id"`
34-
Insecure bool `yaml:"insecure"`
44+
Endpoint string `yaml:"endpoint"`
45+
BucketName string `yaml:"bucket_name"`
46+
SecretAccessKey flagext.Secret `yaml:"secret_access_key"`
47+
AccessKeyID string `yaml:"access_key_id"`
48+
Insecure bool `yaml:"insecure"`
49+
SignatureVersion string `yaml:"signature_version"`
3550

3651
HTTP HTTPConfig `yaml:"http"`
3752
}
@@ -48,5 +63,14 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
4863
f.StringVar(&cfg.BucketName, prefix+"s3.bucket-name", "", "S3 bucket name")
4964
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.")
5065
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.")
66+
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, ", ")))
5167
cfg.HTTP.RegisterFlagsWithPrefix(prefix, f)
5268
}
69+
70+
// Validate config and returns error on failure
71+
func (cfg *Config) Validate() error {
72+
if !util.StringsContain(supportedSignatureVersions, cfg.SignatureVersion) {
73+
return errUnsupportedSignatureVersion
74+
}
75+
return nil
76+
}

pkg/storage/tsdb/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ func (cfg *BucketConfig) Validate() error {
151151
return errUnsupportedStorageBackend
152152
}
153153

154+
if cfg.Backend == BackendS3 {
155+
if err := cfg.S3.Validate(); err != nil {
156+
return err
157+
}
158+
}
159+
154160
return nil
155161
}
156162

vendor/github.com/thanos-io/thanos/pkg/objstore/s3/s3.go

Lines changed: 31 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)