Merge pull request #2973 from redmatter/support-ecs-instance-profile-in-s3-driver

Support ECS TaskRole in S3 storage driver
This commit is contained in:
Manish Tomar 2020-08-26 15:24:20 -07:00 committed by GitHub
commit 2800ab0224
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,8 +29,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds" "github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
@ -404,12 +403,8 @@ func New(params DriverParameters) (*Driver, error) {
return nil, fmt.Errorf("on Amazon S3 this storage driver can only be used with v4 authentication") return nil, fmt.Errorf("on Amazon S3 this storage driver can only be used with v4 authentication")
} }
awsConfig := aws.NewConfig() awsConfig := defaults.Config()
sess, err := session.NewSession() providers := []credentials.Provider{
if err != nil {
return nil, fmt.Errorf("failed to create new session: %v", err)
}
creds := credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{ &credentials.StaticProvider{
Value: credentials.Value{ Value: credentials.Value{
AccessKeyID: params.AccessKey, AccessKeyID: params.AccessKey,
@ -417,10 +412,9 @@ func New(params DriverParameters) (*Driver, error) {
SessionToken: params.SessionToken, SessionToken: params.SessionToken,
}, },
}, },
&credentials.EnvProvider{}, }
&credentials.SharedCredentialsProvider{}, providers = append(providers, defaults.CredProviders(awsConfig, defaults.Handlers())...)
&ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(sess)}, creds := credentials.NewChainCredentials(providers)
})
if params.RegionEndpoint != "" { if params.RegionEndpoint != "" {
awsConfig.WithS3ForcePathStyle(true) awsConfig.WithS3ForcePathStyle(true)
@ -449,7 +443,7 @@ func New(params DriverParameters) (*Driver, error) {
} }
} }
sess, err = session.NewSession(awsConfig) sess, err := session.NewSession(awsConfig)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create new session with aws config: %v", err) return nil, fmt.Errorf("failed to create new session with aws config: %v", err)
} }