Fix: Authorization Policy does applies SAS token twice on retry requests #1331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
I encountered a bug where
put_block
operations would sporadically fail with http status code403 - Forbidden
when authenticating using a SAS token.Detailed of the error were:
"AuthenticationFailed"
"Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature."
<AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
Upon investigating I narrowed it down to the Authorization Policy applying SAS token params multiple times for retry requests.
Simple way to diagnose this issues when using
reqwest
as the url library is to run Env Logger filter with"azure_core::http_client::reqwest=debug"
which will causereqwest
to print the full URL for all requests.Details
I used the same approach as the Access Key policy already uses and simply check the presence of
sig
param in the path. This doesn't feel like a very foolproof solution but it fixes the issue for now.It seems that the python SDK suffered from a similar issues and they chose the same approach for resolving it Azure/azure-storage-python#304
The tests I added feel a little awkward because I had to mock the policy setup. If there is an already existing mock that would allow me to test this easily I am happy to update the PR!
I don't believe this should be an issue for header based authentication since
insert_header
would override an existing header if it was present