Skip to content

Commit

Permalink
UPSTREAM:<carry>:fix:Endpoint fix for AWS S3 Bucket Session
Browse files Browse the repository at this point in the history
Signed-off-by: Achyut Madhusudan <amadhusu@redhat.com>
  • Loading branch information
Achyut Madhusudan committed Apr 8, 2024
1 parent 680e445 commit 1b550d6
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions backend/src/v2/objectstore/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,30 @@ func createBucketSession(ctx context.Context, namespace string, sessionInfo *Ses
if err != nil {
return nil, err
}
sess, err := session.NewSession(&aws.Config{
Credentials: creds,
Region: aws.String(sessionInfo.Region),
Endpoint: aws.String(sessionInfo.Endpoint),
DisableSSL: aws.Bool(sessionInfo.DisableSSL),
S3ForcePathStyle: aws.Bool(true),
})
var sess *session.Session
// AWS Specific:
// Path-style S3 endpoints, which are commonly used, may fall into either of two subdomains:
// 1) s3.amazonaws.com
// 2) s3.<AWS Region>.amazonaws.com
// for (1) the endpoint is not required, thus we skip it, otherwise the writer will fail to close due to region mismatch.
// https://aws.amazon.com/blogs/infrastructure-and-automation/best-practices-for-using-amazon-s3-endpoints-in-aws-cloudformation-templates/
// https://docs.aws.amazon.com/sdk-for-go/api/aws/session/
if strings.ToLower(sessionInfo.Endpoint) != "s3.amazonaws.com" {
sess, err = session.NewSession(&aws.Config{
Credentials: creds,
Region: aws.String(sessionInfo.Region),
Endpoint: aws.String(sessionInfo.Endpoint),
DisableSSL: aws.Bool(sessionInfo.DisableSSL),
S3ForcePathStyle: aws.Bool(true),
})
} else {
sess, err = session.NewSession(&aws.Config{
Credentials: creds,
Region: aws.String(sessionInfo.Region),
DisableSSL: aws.Bool(sessionInfo.DisableSSL),
S3ForcePathStyle: aws.Bool(true),
})
}
if err != nil {
return nil, fmt.Errorf("Failed to create session to access minio: %v", err)
}
Expand Down

0 comments on commit 1b550d6

Please sign in to comment.