-
Notifications
You must be signed in to change notification settings - Fork 564
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
otelaws: Add finalize middleware after instead of before #5975
Open
jacksehr
wants to merge
12
commits into
open-telemetry:main
Choose a base branch
from
jacksehr:no-inject-presigned-urls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pellared
changed the title
awsotel: add finalize middleware after instead of before
otelaws: Add finalize middleware after instead of before
Aug 7, 2024
@akats7 PTAL as a code owner. |
Hey @jacksehr, will take a look at this later today, thanks |
Hey @jacksehr, can you please resolve the issues in the unit tests to use your updated method, also would you be able to add/update a test case to reflect this change. |
Hey @jacksehr, any update on this? |
…lemetry-go-contrib into no-inject-presigned-urls
Please add a changelog entry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR addresses #3368.
Summary
In any presigned URL flow, the AWS SDK skips all
Finalize
middlewares after the PresignHTTPMiddleware. So, if we move context propagation after thePresignHTTPMiddleware
, we will not include context propagation headers in presigned URL requests, which should prevent the reported issue with signatures.Context
The existing middleware in this package adds propagation headers (e.g.
traceparent
) to outgoing AWS requests, presumably to be used in things like AWS X-Ray. However, when making requests for presigned URLs, the AWS SDK adds a bunch of middleware of its own to requests. The most important of these is the PresignHTTPMiddleware. This does a lot of things, but for the purposes of this PR/issue, there are two particularly relevant things it does:Incorporating request headers into the presigned URL signature
When it is built, the middleware receives a presigner. Then, when it is actually run, it receives a
*smithyHTTP.Request
, and it's entirely up to the presigner if the headers on the*smithyHTTP.Request
are incorporated in the calculation of the presigned URL's signature. If we look in the internals of the default v4 signer, it appears to just incorporate all existing headers and use them to sign the URL. This leads to the problem described in the above issue:As observed by the comments in that issue, disabling the context propagation solves this issue, which makes sense as that removes the
traceparent
header from the signature calculation.This leads us to the second relevant behaviour of the
PresignHTTPMiddleware
.Short circuiting remaining middleware
From the comments of the
PresignHTTPMiddleware
:In addition to this, the Deserialize middlewares get cleared, as seen here.
So, in the presigned URL flow, the last middleware that will get called will be the
PresignHTTPRequestMiddleware
. This is actually useful for us now, as if we just ensure our context propagation middleware comes last in theFinalize
step, then we can be sure it will never run in the presign flow. Simply shifting frommiddleware.Before
tomiddleware.After
does just that.I've also renamed the function and moved it so that its order reflects the order of middleware execution (i.e. finalize before deserialize)