Skip to content

Commit

Permalink
br: fix backup to aliyum OSS not support ak/sk as env (#54150) (#54994)
Browse files Browse the repository at this point in the history
close #45551
  • Loading branch information
ti-chi-bot authored Aug 5, 2024
1 parent e0ab246 commit 5863a6f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions br/pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,22 @@ func autoNewCred(qs *backuppb.S3) (cred *credentials.Credentials, err error) {
func createOssRAMCred() (*credentials.Credentials, error) {
cred, err := aliproviders.NewInstanceMetadataProvider().Retrieve()
if err != nil {
return nil, errors.Annotate(err, "Alibaba RAM Provider Retrieve")
log.Warn("failed to get aliyun ram credential", zap.Error(err))
return nil, nil
}
var aliCred, ok = cred.(*alicred.StsTokenCredential)
if !ok {
return nil, errors.Errorf("invalid credential type %T", cred)
}
newCred := credentials.NewChainCredentials([]credentials.Provider{
&credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{},
&credentials.StaticProvider{Value: credentials.Value{AccessKeyID: aliCred.AccessKeyId, SecretAccessKey: aliCred.AccessKeySecret, SessionToken: aliCred.AccessKeyStsToken, ProviderName: ""}},
})
if _, err := newCred.Get(); err != nil {
return nil, errors.Trace(err)
}
ncred := cred.(*alicred.StsTokenCredential)
return credentials.NewStaticCredentials(ncred.AccessKeyId, ncred.AccessKeySecret, ncred.AccessKeyStsToken), nil
return newCred, nil
}

// NewS3Storage initialize a new s3 storage for metadata.
Expand Down

0 comments on commit 5863a6f

Please sign in to comment.