Repository navigation
feat(auth): add SigV4 and SigV4a request signing - #8820
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8820 +/- ##
===========================================
+ Coverage 97.17% 97.20% +0.02%
===========================================
Files 323 327 +4
Lines 16629 16759 +130
Branches 1510 1523 +13
===========================================
+ Hits 16160 16290 +130
Misses 328 328
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This file contains hidden or 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
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.



Issue number:
closes #8817
Summary
Changes
SigV4 request signing in the Auth utility, following the design Powertools for TypeScript shipped in its
signerpackage (RFC aws-powertools/powertools-lambda-typescript#4972). This is the oldest open feature request we had, #2493 from 2023, and it builds on what @stephenbawks did in #2435: botocore does the signing, we do the ergonomics.SigV4Signer(service, region=None, credentials=None, session=None). Region and credentials come from the Lambda environment by default, no provider chain on the cold start path;session=opts into botocore's chain,credentials=takes explicit ones.sign(method, url, headers=None, body=None)returns aSignedRequestwithmethod,url,headersandbody. No network call.requests_auth()andhttpx_auth()returnauth=objects for those clients, duck-typed, neither library is imported.service="s3"switches to botocore'sS3SigV4Auth, so object keys with spaces or+sign correctly andx-amz-content-sha256is added.requestsencoding a space as+gets a 403 from the service; I hit exactly that against a real Function URL during review, see below.SigV4aSigner(service, region_set="*")for multi-region signatures, through botocore's CRT signers.awscrtis not in the Lambda runtime, so it ships as theauth-sigv4aextra and the class raisesSignerConfigErrorwith the install hint when it is missing.SignerConfigError(anAuthError, reasonsigner_misconfigured) at construction for a missing region, missing credentials, empty service or missingawscrt. Messages never carry credential material.pyjwtnorcryptography.auth-sigv4aextra.User experience
Verification
tests/functional/auth: 520 passed. Signatures are checked against botocore's ownSigV4Auth/S3SigV4Authoutput on a frozen clock, plus repeated query keys,+/&/unicode/blank values, str/bytes/empty bodies, explicit and session credentials, region precedence,requestsandhttpxend to end with a mock transport, streaming bodies rejected, lazy imports in a clean interpreter.test_with_signer_required_packages(botocore only): 14 passed. noxtest_with_sigv4a_required_packages: 17 passed, SigV4a producesAWS4-ECDSA-P256-SHA256with theX-Amz-Region-Setheader.AWS_IAMauth and an S3 object with keyreports/2026 11/summary+v2.csv. Unsigned: 403. Signed throughrequests,httpxandsign()+urllib3: 200, including repeated query keys, spaces,&,+, unicode and blank values. Wrongservice: 403. S3 object fetched withservice="s3": 200 and the right content; unsigned 403. Resources deleted afterwards.ruff,mypy,xenonclean. Written with an AI assistant; I ran everything above myself.Follow-up once merged: close #2493 and #2713 pointing here.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.