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: Skip verify region if the provider is ceph or minio #42366

Closed
wants to merge 2 commits into from
Closed
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
60 changes: 34 additions & 26 deletions br/pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (options *S3BackendOptions) Apply(s3 *backuppb.S3) error {
}

s3.Endpoint = strings.TrimSuffix(options.Endpoint, "/")
s3.Provider = options.Provider
s3.Region = options.Region
// StorageClass, SSE and ACL are acceptable to be empty
s3.StorageClass = options.StorageClass
Expand Down Expand Up @@ -358,38 +359,45 @@ func NewS3Storage(ctx context.Context, backend *backuppb.S3, opts *ExternalStora
)
}
c := s3.New(ses, s3CliConfigs...)
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 failed to get region from client if the client is ceph or minio
// It defaults back to us-west-1 which breaks the code if a region is already set
if qs.Provider != "ceph" && qs.Provider != "minio" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Not sure if excluding ceph and minio is the right solution, maybe we should check if qs.Provider == "s3" (or GCS?)
  2. Maybe we should separate the provider config from the logic here. And check if ProviderConfig.check_bucket_with_region == true and then elsewhere store the config for each provider.

These are just ideas, I have no objections on merging this as-is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 . I'm not sure about the list. We add ceph and minio because it's what we are working with and had troubles, but the issues may be wider.
2 Would it be simpler to add a parameter like qs.SkipBucketRegionCheck and a tag --skip-bucket-region-check when we launch br ? ( the wording is a bit long ^^")


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

From the CI checks:

br/pkg/storage/s3.go:365:53: empty-lines: extra empty line at the start of a block (all_revive)

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
}
}
// 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(ctx, c, qs.Bucket, setCredOpt)
if err != nil {
return nil, errors.Annotatef(err, "failed to get region of bucket %s", qs.Bucket)
}
}
region, err := s3manager.GetBucketRegionWithClient(ctx, c, qs.Bucket, setCredOpt)
if err != nil {
return nil, errors.Annotatef(err, "failed to get region of bucket %s", qs.Bucket)
}

if qs.Region != region {
if qs.Region != "" {
return nil, errors.Trace(fmt.Errorf("s3 bucket and region are not matched, bucket=%s, input region=%s, real region=%s",
qs.Bucket, qs.Region, region))
}
if qs.Region != region {
if qs.Region != "" {
return nil, errors.Trace(fmt.Errorf("s3 bucket and region are not matched, bucket=%s, input region=%s, real region=%s",
qs.Bucket, qs.Region, region))
}

qs.Region = region
backend.Region = region
if region != defaultRegion {
s3CliConfigs = append(s3CliConfigs, aws.NewConfig().WithRegion(region))
c = s3.New(ses, s3CliConfigs...)
qs.Region = region
backend.Region = region
if region != defaultRegion {
s3CliConfigs = append(s3CliConfigs, aws.NewConfig().WithRegion(region))
c = s3.New(ses, s3CliConfigs...)
}
}

log.Info("succeed to get bucket region from s3", zap.String("bucket region", region))
}
log.Info("succeed to get bucket region from s3", zap.String("bucket region", region))

if len(qs.Prefix) > 0 && !strings.HasSuffix(qs.Prefix, "/") {
qs.Prefix += "/"
Expand Down