Skip to content

Commit

Permalink
s3: Respect SignatureV2 flag for all credential providers
Browse files Browse the repository at this point in the history
Thanos currently only supports V2 signatures when the credentials are
statically specified in its configuration. This change supports
requesting signature V2 on other credential sources.

Signed-off-by: Christian Simon <[email protected]>
  • Loading branch information
simonswine committed Nov 23, 2020
1 parent 47a25a4 commit a320463
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re

### Changed

-
- [#3496](https://github.com/thanos-io/thanos/pull/3496) s3: Respect SignatureV2 flag for all credential providers.

## [v0.17.0](https://github.com/thanos-io/thanos/releases/tag/v0.17.0) - 2020.11.18

Expand Down
47 changes: 34 additions & 13 deletions pkg/objstore/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,57 @@ func NewBucket(logger log.Logger, conf []byte, component string) (*Bucket, error
return NewBucketWithConfig(logger, config, component)
}

type overrideSignerType struct {
signerType credentials.SignatureType
upstream credentials.Provider
}

func (s *overrideSignerType) Retrieve() (credentials.Value, error) {
v, err := s.upstream.Retrieve()
if err != nil {
return v, err
}
if !v.SignerType.IsAnonymous() {
v.SignerType = s.signerType
}
return v, nil
}

func (s *overrideSignerType) IsExpired() bool {
return s.upstream.IsExpired()
}

// NewBucketWithConfig returns a new Bucket using the provided s3 config values.
func NewBucketWithConfig(logger log.Logger, config Config, component string) (*Bucket, error) {
var chain []credentials.Provider

wrapCredentialsProvider := func(p credentials.Provider) credentials.Provider {
if config.SignatureV2 {
return &overrideSignerType{signerType: credentials.SignatureV2, upstream: p}
}
return p
}

if err := validate(config); err != nil {
return nil, err
}
if config.AccessKey != "" {
signature := credentials.SignatureV4
// TODO(bwplotka): Don't do flags, use actual v2, v4 params.
if config.SignatureV2 {
signature = credentials.SignatureV2
}

chain = []credentials.Provider{&credentials.Static{
chain = []credentials.Provider{wrapCredentialsProvider(&credentials.Static{
Value: credentials.Value{
AccessKeyID: config.AccessKey,
SecretAccessKey: config.SecretKey,
SignerType: signature,
SignerType: credentials.SignatureV4,
},
}}
})}
} else {
chain = []credentials.Provider{
&credentials.EnvAWS{},
&credentials.FileAWSCredentials{},
&credentials.IAM{
wrapCredentialsProvider(&credentials.EnvAWS{}),
wrapCredentialsProvider(&credentials.FileAWSCredentials{}),
wrapCredentialsProvider(&credentials.IAM{
Client: &http.Client{
Transport: http.DefaultTransport,
},
},
}),
}
}

Expand Down

0 comments on commit a320463

Please sign in to comment.