Skip to content

Commit

Permalink
Add support for STS credentials (#4744)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaldivia authored Nov 6, 2023
1 parent b7dc9cc commit 011c61b
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions cmd/client-s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"sync"
"time"

"github.com/minio/pkg/v2/env"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/encrypt"
Expand Down Expand Up @@ -158,12 +160,6 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
var api *minio.Client
var found bool
if api, found = clientCache[confSum]; !found {
// if Signature version '4' use NewV4 directly.
creds := credentials.NewStaticV4(config.AccessKey, config.SecretKey, config.SessionToken)
// if Signature version '2' use NewV2 directly.
if strings.ToUpper(config.Signature) == "S3V2" {
creds = credentials.NewStaticV2(config.AccessKey, config.SecretKey, "")
}

var transport http.RoundTripper

Expand Down Expand Up @@ -223,6 +219,51 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
}
}

var credsChain []credentials.Provider

// if an STS endpoint is set, we will add that to the chain
if stsEndpoint := env.Get("MC_STS_ENDPOINT", ""); stsEndpoint != "" {
// set AWS_WEB_IDENTITY_TOKEN_FILE is MC_WEB_IDENTITY_TOKEN_FILE is set
if val := env.Get("MC_WEB_IDENTITY_TOKEN_FILE", ""); val != "" {
os.Setenv("AWS_WEB_IDENTITY_TOKEN_FILE", val)
}

stsEndpointURL, err := url.Parse(stsEndpoint)
if err != nil {
return nil, probe.NewError(fmt.Errorf("Error parsing sts endpoint: %v", err))
}
credsSts := &credentials.IAM{
Client: &http.Client{
Transport: transport,
},
Endpoint: stsEndpointURL.String(),
}
credsChain = append(credsChain, credsSts)
}

// V4 Credentials
credsV4 := &credentials.Static{
Value: credentials.Value{
AccessKeyID: config.AccessKey,
SecretAccessKey: config.SecretKey,
SessionToken: config.SessionToken,
SignerType: credentials.SignatureV4,
},
}
credsChain = append(credsChain, credsV4)
// V2 Credentials
credsV2 := &credentials.Static{
Value: credentials.Value{
AccessKeyID: config.AccessKey,
SecretAccessKey: config.SecretKey,
SessionToken: "",
SignerType: credentials.SignatureV2,
},
}
credsChain = append(credsChain, credsV2)

creds := credentials.NewChainCredentials(credsChain)

// Not found. Instantiate a new MinIO
var e error

Expand Down

0 comments on commit 011c61b

Please sign in to comment.