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

Bug v6.0.0: extra_headers included into signature causing InvalidSignatureException #1241

Closed
Roytangrb opened this issue May 22, 2024 · 0 comments · Fixed by #1242
Closed

Comments

@Roytangrb
Copy link

Issue:

pynamodb.exceptions.GetError: Failed to get item: An error occurred (InvalidSignatureException) on request (<...>) on table (...) when calling the GetItem operation: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

when extra_headers configured to have headers used and striped by a proxy

Potential cause

Per documentation https://pynamodb.readthedocs.io/en/stable/settings.html#extra-headers

A dictionary of headers that should be added to every request. This is only useful when interfacing with DynamoDB through a proxy, where headers are stripped by the proxy before forwarding along. Failure to strip these headers before sending to AWS will result in an InvalidSignatureException due to request signing.

def _before_sign(self, request, **_) -> None:
if self._extra_headers is not None:
for k, v in self._extra_headers.items():
request.headers.add_header(k, v)

@raulmyocu found that request is signed after extra_headers are added in v6.0.0, in older version (v5.5.1 where error is not observed), requests are signed before extra_headers being added.

self._sign_request(request)
prepared_request = self.client._endpoint.prepare_request(request)
if self._extra_headers is not None:
prepared_request.headers.update(self._extra_headers)
if settings.extra_headers is not None:
prepared_request.headers.update(settings.extra_headers)

Related: #1079

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 a pull request may close this issue.

1 participant