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

generate_presigned_url results in SignatureDoesNotMatch #2989

Closed
viktormill opened this issue Sep 6, 2021 · 5 comments
Closed

generate_presigned_url results in SignatureDoesNotMatch #2989

viktormill opened this issue Sep 6, 2021 · 5 comments
Assignees
Labels
guidance Question that needs advice or information.

Comments

@viktormill
Copy link

viktormill commented Sep 6, 2021

Describe the bug
Calling generate_presigned_url in AWS region 'eu-north-1' results in error 'SignatureDoesNotMatch. The request signature we calculated does not match the signature you provided. Check your key and signing method.'

If calling generate_presigned_url in AWS region 'eu-west-1' this works fine.

The presigned url looks like this
https://my-bucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm...

Steps to reproduce
Using Boto3 version 1.17.78 and calling generate_presigned_url

s3_client = boto3.client('s3')
s3_source_signed_url = s3_client.generate_presigned_url(
  'get_object',
  Params={
  'Bucket': 'my-bucket,
  'Key': 'my-key'
  },
  ExpiresIn=3600
)

Expected behavior
generate_presigned_url to include region in the presigned url e.g. https://my-bucket.s3.eu-north-1.amazonaws.com/test.txt?X-Amz-Algorithm...

Debug logs
'SignatureDoesNotMatch. The request signature we calculated does not match the signature you provided. Check your key and signing method.'

@viktormill viktormill added the needs-triage This issue or PR still needs to be triaged. label Sep 6, 2021
@tim-finnigan tim-finnigan self-assigned this Sep 7, 2021
@tim-finnigan tim-finnigan added guidance Question that needs advice or information. investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 7, 2021
@tim-finnigan
Copy link
Contributor

Hi @viktormill, thanks for reaching out. By default, the region is not included in the presigned URL as noted here: #1982 (comment). But some users have provided workarounds in that issue by setting endpoint_url like this: #1982 (comment).

In regard to the error your seeing, many people have suggested that setting the Config like this will solve the problem:
#1644 (comment)

Can you let us know if that worked? If you’re still seeing an issue, please send us the full debug logs (with sensitive information redacted) by adding boto3.set_stream_logger('') to your code.

@tim-finnigan tim-finnigan added response-requested Waiting on additional information or feedback. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 7, 2021
@viktormill
Copy link
Author

viktormill commented Sep 8, 2021

@tim-finnigan I think this is a DNS bug on AWS on bucket creation,
If I immediately create a bucket on S3 in e.g. eu-north-1, this bug happen.
To solve it, both of your links to solutions works:
Virtual-based:

boto3.client(
  's3',
  endpoint_url=f'https://s3.{region}.amazonaws.com',
  config=boto3.session.Config(s3={'addressing_style': 'virtual'})
)

Or
Path-based:

boto3.client('s3', config=boto3.session.Config(s3={'addressing_style': 'path'}, signature_version='s3v4'))

Though If I wait for a few hours up to one day, the above fixes aren't needed.
Also this bug seems to never happen on eu-west-1.

I also read that aws are planning to deprecate s3 path based urls: https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/

So I assume that virtual based would be recommended?

@github-actions github-actions bot removed the response-requested Waiting on additional information or feedback. label Sep 8, 2021
@tim-finnigan
Copy link
Contributor

Hi @viktormill, thanks for your response. I was able to reproduce the SignatureDoesNotMatch error for objects in both eu-north-1 and eu-west-1 buckets. The easiest solution was just to provide the region_name and endpoint_url as noted in this comment: #1149 (comment)

s3_client = session.client(
    's3', region_name='eu-central-1', endpoint_url='https://s3.eu-central-1.amazonaws.com'
)

Thanks again for raising visibility to this. I will discuss with the team and see if we can better document this scenario. Please let us know if you have any more questions or feedback.

@github-actions
Copy link

github-actions bot commented Sep 8, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually. To
workaround this, one can explicitly specify the bucket endpoint.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation
kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually. To
workaround this, one can explicitly specify the bucket endpoint.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation
kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can explicitly specify the bucket endpoint,
either explicitly via endpoint_url, or by setting s3_region, which
will be used to generate the bucket's virtual address.
kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
kleesc added a commit to kleesc/quay that referenced this issue Feb 3, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
kleesc added a commit to quay/quay that referenced this issue Feb 3, 2022
…JQUAY-3082) (#1081)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/quay that referenced this issue Feb 7, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/quay that referenced this issue Feb 8, 2022
…JQUAY-3082)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.
kleesc added a commit to quay/quay that referenced this issue Feb 14, 2022
…JQUAY-3082) (#1096)

Boto3 behaves unexpectedly when the resource client is not set to use
the correct region. Boto3 can't seem to correctly set the
X-Amz-Credential header when generating presigned urls if the region
name is not explicitly set, and will always fall back to us-east-1.
To reproduce this:
- Create a bucket in a different region from us-east-1 (e.g
eu-north-1)
- Create a boto3 client/resource without specifying the region
- Generate a presigned url

This seems to be a DNS issue with AWS that only happens shortly after
a bucket has been created, and resolves itself eventually.
Ref:
- boto/boto3#2989
- https://stackoverflow.com/questions/56517156/s3-presigned-url-works-90-minutes-after-bucket-creation

To workaround this, one can specify the bucket endpoint, either
explicitly via endpoint_url, or by setting s3_region, which will be
used to generate the bucket's virtual address.

Co-authored-by: Kenny Lee Sin Cheong <kenny.lee28@gmail.com>
lbac-redhat added a commit to lbac-redhat/quay-docs that referenced this issue Mar 15, 2024
Due to the boto3 issues (boto/boto3#2989) setting the X-Amz-Credential header,
it is recommended to set either the `s3_region` or the `endpoint_url`
when configuring an S3Storage provider.

This commit adds a the `s3_region` field to all documented S3Storage
examples.
lbac-redhat added a commit to lbac-redhat/quay-docs that referenced this issue Mar 15, 2024
Due to the boto3 issues (boto/boto3#2989) setting the X-Amz-Credential header,
it is recommended to set either the `s3_region` or the `endpoint_url`
when configuring an S3Storage provider.

This commit adds the `s3_region` field to all documented S3Storage
examples in the documentation.
lbac-redhat added a commit to lbac-redhat/quay-docs that referenced this issue Mar 15, 2024
Due to the boto3 issues (boto/boto3#2989) setting the X-Amz-Credential header,
it is recommended to set either the `s3_region` or the `endpoint_url`
field when configuring an S3Storage provider.

This commit adds the `s3_region` field to all documented S3Storage
examples in the documentation.
@Ling-Jun
Copy link

Ling-Jun commented May 23, 2024

This is still happening in 2024. I have created this following script:

  • this works: s3_client = session.client('s3', region_name='ca-central-1', endpoint_url='https://s3.ca-central-1.amazonaws.com', config=boto3.session.Config(signature_version='s3v4'))
  • this raises the same error as above: s3_client = session.client('s3', region_name='ca-central-1', config=boto3.session.Config(signature_version='s3v4')), the error does disappear after seeming a day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

3 participants