Skip to content

Commit

Permalink
fix AWS IRSA environments handler, fix #798
Browse files Browse the repository at this point in the history
  • Loading branch information
Slach committed Dec 13, 2023
1 parent d510c4c commit 17dcdc2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v2.4.13
BUG FIXES
- fix object_disk.CopyObject during restore to allow use properly S3 endpoint
- fix AWS IRSA environments handler, fix [798](https://github.com/Altinity/clickhouse-backup/issues/798)

# v2.4.12
BUG FIXES
Expand Down
16 changes: 6 additions & 10 deletions pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,18 @@ func (s *S3) Connect(ctx context.Context) error {
if s.Config.Region != "" {
awsConfig.Region = s.Config.Region
}
// AWS IRSA handling, look https://github.com/Altinity/clickhouse-backup/issues/798
awsRoleARN := os.Getenv("AWS_ROLE_ARN")
if s.Config.AssumeRoleARN != "" || awsRoleARN != "" {
stsClient := sts.NewFromConfig(awsConfig)
if awsRoleARN != "" {
awsConfig.Credentials = stscreds.NewAssumeRoleProvider(stsClient, awsRoleARN)
} else {
awsConfig.Credentials = stscreds.NewAssumeRoleProvider(stsClient, s.Config.AssumeRoleARN)
}
}

awsWebIdentityTokenFile := os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE")
stsClient := sts.NewFromConfig(awsConfig)
if awsRoleARN != "" && awsWebIdentityTokenFile != "" {
stsClient := sts.NewFromConfig(awsConfig)
awsConfig.Credentials = stscreds.NewWebIdentityRoleProvider(
stsClient, awsRoleARN, stscreds.IdentityTokenFile(awsWebIdentityTokenFile),
)
} else if awsRoleARN != "" {
awsConfig.Credentials = stscreds.NewAssumeRoleProvider(stsClient, awsRoleARN)
} else if s.Config.AssumeRoleARN != "" {
awsConfig.Credentials = stscreds.NewAssumeRoleProvider(stsClient, s.Config.AssumeRoleARN)
}

if s.Config.AccessKey != "" && s.Config.SecretKey != "" {
Expand Down

0 comments on commit 17dcdc2

Please sign in to comment.