fix(boto3): Fix botocore SigV4 failures caused by post-sign trace propagation - #7050
fix(boto3): Fix botocore SigV4 failures caused by post-sign trace propagation#7050pabloDeputter wants to merge 27 commits into
Conversation
- merge Sentry baggage with existing vendor (e.g. Datadog) baggage in botocore's`before-sign` hook; avoiding post-sign header tampering that invalidates the SigV4 signature. - Skip propagation for presigned requests Fixes: #7031 & PY-2667
Codecov Results 📊✅ 111606 passed | ⏭️ 6764 skipped | Total: 118370 | Pass Rate: 94.29% | Execution Time: 412m 40s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 97.14%. Project has 2483 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 90.17% 90.23% +0.06%
==========================================
Files 193 193 —
Lines 25317 25413 +96
Branches 9280 9322 +42
==========================================
+ Hits 22827 22930 +103
- Misses 2490 2483 -7
- Partials 1427 1429 +2Generated by Codecov Action |
| return rv | ||
|
|
||
| def endheaders(self: "HTTPConnection", *args: "Any", **kwargs: "Any") -> "Any": | ||
| trace_headers = getattr(self, "_sentrysdk_trace_headers", ()) |
There was a problem hiding this comment.
Does calling sentry_sdk.get_current_scope().iter_trace_propagation_headers() here instead of in putrequest() work?
It would be best to avoid stashing stuff on the HTTPConnection instance if we can help it.
There was a problem hiding this comment.
Good suggestion :) header generation is moved into endheaders() instead of being stored on the connection.
… SigV4 headers Refs: #7031 & PY-2667
|
I haven't forgot about this, it's just complex so I'll likely only re-review fully at the start of next week. |
…` + support for SigV4 query/presigned authentication Refs: #7031 & PY-2667
…ssues Refs: #7031 & PY-2667
…` since it's not used anymore
…ion` string instead of all headers
- Record existing and signed headers in `putheader()` so trace propagation can avoid reparsing `_buffer` on every request. Refs: #7031 & PY-2667
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 484a941. Configure here.

Description
Summary of issue
baggagewas not included inSignedHeaders. Any later modifications to the value did not invalidate the request.before-signevent. It addsbaggage, ... andx-datadog-*before signing. Any later modifications to the value DO invalidate the request, thus later HTTP-client injection is suppressed to avoid duplicate headers.before-signhandler writes the baggage to the AWS requestbaggagein the SigV4 signaturebaggagevalue403 ForbiddenorSignatureDoesNotMatch.Changes
before-signhandler, so finalbaggageandsentry-tracevalues are created before SigV4 signing.http.clientpropagation is delayed untilendheaders(), when the complete request headers and SigV4SignedHeadersare available. Existingbaggageheader is never mutated after it already was signed.Issues
Resolves: #7031 & PY-2667
Related issues in dd-trace-py: #19477 & #19358
Reminders
uv run ruff.feat:,fix:,ref:,meta:)