Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

br: fix getting region failure with other s3 compatible storage #39653

Merged
merged 6 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions br/pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,18 @@ func NewS3Storage(backend *backuppb.S3, opts *ExternalStorageOptions) (obj *S3St
)
}
c := s3.New(ses, s3CliConfigs...)
// s3manager.GetBucketRegionWithClient will set credential anonymous, which works with s3.
// we need reassign credential to be compatible with minio authentication.
confCred := ses.Config.Credentials
setCredOpt := func(req *request.Request) {
// s3manager.GetBucketRegionWithClient will set credential anonymous, which works with s3.
// we need reassign credential to be compatible with minio authentication.
if confCred != nil {
req.Config.Credentials = confCred
}
// s3manager.GetBucketRegionWithClient use path style addressing default.
// we need set S3ForcePathStyle by our config if we set endpoint.
if qs.Endpoint != "" {
req.Config.S3ForcePathStyle = ses.Config.S3ForcePathStyle
}
}
region, err := s3manager.GetBucketRegionWithClient(context.Background(), c, qs.Bucket, setCredOpt)
if err != nil {
Expand Down
51 changes: 29 additions & 22 deletions br/pkg/storage/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,32 +314,35 @@ func TestS3Storage(t *testing.T) {
{
name: "no region",
s3: &backuppb.S3{
Region: "",
Endpoint: s.URL,
Bucket: "bucket",
Prefix: "prefix",
Region: "",
Endpoint: s.URL,
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: false,
sendCredential: true,
},
{
name: "wrong region",
s3: &backuppb.S3{
Region: "us-east-2",
Endpoint: s.URL,
Bucket: "bucket",
Prefix: "prefix",
Region: "us-east-2",
Endpoint: s.URL,
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: true,
sendCredential: true,
},
{
name: "right region",
s3: &backuppb.S3{
Region: "us-west-2",
Endpoint: s.URL,
Bucket: "bucket",
Prefix: "prefix",
Region: "us-west-2",
Endpoint: s.URL,
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: false,
sendCredential: true,
Expand All @@ -353,6 +356,7 @@ func TestS3Storage(t *testing.T) {
SecretAccessKey: "cd",
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: false,
sendCredential: true,
Expand All @@ -365,30 +369,33 @@ func TestS3Storage(t *testing.T) {
SecretAccessKey: "cd",
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: false,
sendCredential: true,
},
{
name: "no secret access key",
s3: &backuppb.S3{
Region: "us-west-2",
Endpoint: s.URL,
AccessKey: "ab",
Bucket: "bucket",
Prefix: "prefix",
Region: "us-west-2",
Endpoint: s.URL,
AccessKey: "ab",
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: false,
sendCredential: true,
},
{
name: "no secret access key",
s3: &backuppb.S3{
Region: "us-west-2",
Endpoint: s.URL,
AccessKey: "ab",
Bucket: "bucket",
Prefix: "prefix",
Region: "us-west-2",
Endpoint: s.URL,
AccessKey: "ab",
Bucket: "bucket",
Prefix: "prefix",
ForcePathStyle: true,
},
errReturn: false,
sendCredential: false,
Expand Down