-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
only add the content-sha256 header when it's already exists for CrtSigV4QueryAuth and CrtSigV4AsymQueryAuth #3243
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ def add_auth(self, request): | |
else: | ||
explicit_payload = UNSIGNED_PAYLOAD | ||
|
||
if self._should_add_content_sha256_header(explicit_payload): | ||
if self._should_add_content_sha256_header(existing_sha256, explicit_payload): | ||
body_header = ( | ||
awscrt.auth.AwsSignedBodyHeaderType.X_AMZ_CONTENT_SHA_256 | ||
) | ||
|
@@ -169,7 +169,7 @@ def _should_sha256_sign_payload(self, request): | |
# bit of metadata through the request context. | ||
return request.context.get('payload_signing_enabled', True) | ||
|
||
def _should_add_content_sha256_header(self, explicit_payload): | ||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# only add X-Amz-Content-SHA256 header if payload is explicitly set | ||
return explicit_payload is not None | ||
|
||
|
@@ -278,7 +278,7 @@ def add_auth(self, request): | |
else: | ||
explicit_payload = UNSIGNED_PAYLOAD | ||
|
||
if self._should_add_content_sha256_header(explicit_payload): | ||
if self._should_add_content_sha256_header(existing_sha256, explicit_payload): | ||
body_header = ( | ||
awscrt.auth.AwsSignedBodyHeaderType.X_AMZ_CONTENT_SHA_256 | ||
) | ||
|
@@ -371,7 +371,7 @@ def _should_sha256_sign_payload(self, request): | |
# bit of metadata through the request context. | ||
return request.context.get('payload_signing_enabled', True) | ||
|
||
def _should_add_content_sha256_header(self, explicit_payload): | ||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# only add X-Amz-Content-SHA256 header if payload is explicitly set | ||
return explicit_payload is not None | ||
|
||
|
@@ -421,7 +421,7 @@ def _should_sha256_sign_payload(self, request): | |
# checks. | ||
return super()._should_sha256_sign_payload(request) | ||
|
||
def _should_add_content_sha256_header(self, explicit_payload): | ||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# Always add X-Amz-Content-SHA256 header | ||
return True | ||
|
||
|
@@ -494,6 +494,10 @@ def _apply_signing_changes(self, aws_request, signed_crt_request): | |
# fragment - 4 | ||
aws_request.url = urlunsplit((p[0], p[1], p[2], signed_query, p[4])) | ||
|
||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# only add X-Amz-Content-SHA256 header if header already set to UNSIGNED_PAYLOAD | ||
return existing_sha256 == UNSIGNED_PAYLOAD | ||
Comment on lines
+498
to
+499
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we only adding this if it's unsigned? What if we have an actual payload we're signing for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a temporary workaround we want to add for vpc-lattice and not want to introduce the change for others (Even though that it might be more reasonable to add the header to sign for other service as well, and it will match the behavior for the botocore signer). And they only supports UNSIGNED-PAYLOAD We decided to have an other workaround as the short term patch within CRT now. awslabs/aws-c-auth#249 We will have further discussion about what's the proper way to handle their use case in the near future, and it should be across SDKs not only for CRT. So, no need for this PR now. |
||
|
||
|
||
class CrtS3SigV4AsymQueryAuth(CrtSigV4AsymQueryAuth): | ||
"""S3 SigV4A auth using query parameters. | ||
|
@@ -512,7 +516,7 @@ def _should_sha256_sign_payload(self, request): | |
# payload. Instead, you use a constant string "UNSIGNED-PAYLOAD". | ||
return False | ||
|
||
def _should_add_content_sha256_header(self, explicit_payload): | ||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# Never add X-Amz-Content-SHA256 header | ||
return False | ||
|
||
|
@@ -591,6 +595,10 @@ def _apply_signing_changes(self, aws_request, signed_crt_request): | |
# fragment - 4 | ||
aws_request.url = urlunsplit((p[0], p[1], p[2], signed_query, p[4])) | ||
|
||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# only add X-Amz-Content-SHA256 header if header already set to UNSIGNED_PAYLOAD | ||
return existing_sha256 == UNSIGNED_PAYLOAD | ||
|
||
|
||
class CrtS3SigV4QueryAuth(CrtSigV4QueryAuth): | ||
"""S3 SigV4 auth using query parameters. | ||
|
@@ -611,7 +619,7 @@ def _should_sha256_sign_payload(self, request): | |
# payload. Instead, you use a constant string "UNSIGNED-PAYLOAD". | ||
return False | ||
|
||
def _should_add_content_sha256_header(self, explicit_payload): | ||
def _should_add_content_sha256_header(self, existing_sha256, explicit_payload): | ||
# Never add X-Amz-Content-SHA256 header | ||
return False | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always add new positional arguments at the end of the function signature. I would also recommend making this an optional parameter that defaults to
None
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we also missed an update somewhere? I think this will be resolved if you follow the advice above, but we should figure out where we're missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw the error, but I don't understand why... Looks like we are not declaring
_should_add_content_sha256_header
anywhere else, and I updated the param for_should_add_content_sha256_header
inCrtSigV4QueryAuth
. Interesting.