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

Set hinting region to use for GetBucketRegion() #210

Merged

Conversation

kaovilai
Copy link
Member

@kaovilai kaovilai commented Jul 16, 2024

Fixes: vmware-tanzu/velero#8022

Adds back region hinting removed in https://github.com/vmware-tanzu/velero-plugin-for-aws/pull/177/files#diff-7ba4f8953b70f82b66f6ba15ea753c9bb847d2e01173baaef65574f60e57d86cL40-L41

Per following
https://github.com/aws/aws-sdk-go-v2/blob/4599f78694cabb6853addabc6f92cb197fdb5647/feature/s3/manager/bucket_region.go#L45-L47
AWS will make a request to bucketname.s3.<regionHint>.amazonaws.com/
Where region hint is obtained via config which in local dev machine could be loaded from ~/.aws/credentials so unit tests if any won't fail but in a container/k8s environment where cred file is not available it may not work.

Related to fixes at openshift/oadp-operator#1470
Signed-off-by: Tiger Kaovilai [email protected]

test image:

ghcr.io/kaovilai/velero-plugin-for-aws:bucket-region-hinting-anonymous-creds
Test image builds

❯ alias ghcr_tag 
ghcr_tag='echo ghcr.io/kaovilai/$(basename $PWD):$(git branch --show-current)'

~/git/velero-plugin-for-aws bucket-region-hinting-anonymous-creds
❯ IMAGE_TAGS=$(ghcr_tag) make container && docker push $(ghcr_tag) 

❯ ghcr_tag 
ghcr.io/kaovilai/velero-plugin-for-aws:bucket-region-hinting-anonymous-creds

❯ docker image inspect $(ghcr_tag) | grep Arch
        "Architecture": "amd64",

@kaovilai kaovilai force-pushed the bucket-region-hinting-anonymous-creds branch from 2183997 to 627b11d Compare July 16, 2024 20:53
@kaovilai kaovilai changed the title Set hinting region to use from GetBucketRegion() Set hinting region to use for GetBucketRegion() Jul 16, 2024
@blackpiglet blackpiglet requested a review from reasonerjt July 17, 2024 02:10
// configures anonymous credentials
WithAnonymousCredentials().
// configures region for GetBucketRegion to query from
WithRegion("us-east-1").
Copy link
Contributor

@blackpiglet blackpiglet Jul 17, 2024

Choose a reason for hiding this comment

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

I'm a little confused here.
Line 159 calls function manager.GetBucketRegion to determine the bucket's region. Do we need to set the default value as us-east-1 before that?

Copy link
Member Author

Choose a reason for hiding this comment

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

The region in config here is only set for getting bucket region. Essentially so aws can form bucketname.s3.<regionHint>.amazonaws.com where regionHint was previously in aws-sdk-go-v1 set to the first region retuned here.
It has to be in config before it can call GetBucketRegion otherwise you would get an error like this.

time="2024-07-12T17:30:17Z" level=error msg="Failed to determine bucket's region bucket: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, error: operation error S3: HeadBucket, resolve auth scheme: resolve endpoint: endpoint rule error, Invalid region: region was not a valid DNS name." backup-storage-location=openshift-adp/ts-velero-test-1 cmd=/plugins/velero-plugin-for-aws controller=backup-storage-location logSource="/opt/app-root/src/velero-plugin-for-aws/velero-plugin-for-aws/object_store.go:153" pluginName=velero-plugin-for-aws

This regionCfg is only used when if s3URL == "" && region == "" and is thrown away after correct region is obtained.

Alternatively I can set the region I believe in latter steps, such as in newS3client or as part of GetBucketRegion() opts.

sseago
sseago previously approved these changes Jul 17, 2024
@kaovilai kaovilai force-pushed the bucket-region-hinting-anonymous-creds branch from 71d4a94 to f62c75c Compare July 25, 2024 16:23
@kaovilai
Copy link
Member Author

Before fix

spec:
  credential:
    key: cloud
    name: cloud-credentials
  default: true
  objectStorage:
    bucket: <bucket>
    prefix: <prefix>
  provider: aws
status:
  lastValidationTime: '2024-07-25T18:16:35Z'
  message: 'BackupStorageLocation "default" is unavailable: rpc error: code = Unknown desc = operation error S3: HeadBucket, resolve auth scheme: resolve endpoint: endpoint rule error, Invalid region: region was not a valid DNS name.'
  phase: Unavailable

After fix

spec:
  credential:
    key: cloud
    name: cloud-credentials
  default: true
  objectStorage:
    bucket: <bucket>
    prefix: <prefix>
  provider: aws
status:
  lastSyncedTime: '2024-07-25T18:28:08Z'
  lastValidationTime: '2024-07-25T18:27:18Z'
  phase: Available

@kaovilai kaovilai requested a review from sseago July 25, 2024 18:34
sseago
sseago previously approved these changes Jul 25, 2024
@kaovilai kaovilai force-pushed the bucket-region-hinting-anonymous-creds branch from f62c75c to 156fb10 Compare July 25, 2024 18:51
Copy link
Contributor

@reasonerjt reasonerjt left a comment

Choose a reason for hiding this comment

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

lgtm

@sseago sseago merged commit add8312 into vmware-tanzu:main Jul 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regression: aws-sdk-go-v2 bump removed region hint breaking GetBucketRegion
4 participants