Skip to content

src/rgw: amend the s3 error code when x_amz_content_sha256 is error - #55230

Closed
climb-mountain123 wants to merge 1 commit into
ceph:mainfrom
climb-mountain123:s3_error_code
Closed

climb-mountain123 wants to merge 1 commit into
ceph:mainfrom
climb-mountain123:s3_error_code

Conversation

@climb-mountain123

Copy link
Copy Markdown

Validate the x_amz_content_sha256 request header. When the length of the header string is not 64 characters and contains characters other than 0-9 and a-f, return InvalidArgument.

Fixes: https://tracker.ceph.com/issues/64084

Signed-off-by: daijufang [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

Validate the x_amz_content_sha256 request header. When the length of the header string is not 64 characters and contains characters other than 0-9 and a-f, return InvalidArgument.

Fixes: https://tracker.ceph.com/issues/64084

Signed-off-by: daijufang <[email protected]>
@climb-mountain123
climb-mountain123 requested a review from a team as a code owner January 18, 2024 09:51
@github-actions github-actions Bot added the rgw label Jan 18, 2024
Comment thread src/rgw/rgw_auth_s3.cc
Comment on lines +541 to +545
std::string x_amz_content_sha256 = std::string(info.env->get("HTTP_X_AMZ_CONTENT_SHA256", ""));
std::regex hexRegex("^[0-9a-fA-F]+$");
if (x_amz_content_sha256.length() != 64 || !std::regex_match(x_amz_content_sha256, hexRegex)) {
ldpp_dout(dpp, 10) << "error x-amz-content-sha256 = " << x_amz_content_sha256 << dendl;
return -EINVAL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to support the validation of the x-amz-content-sha256 request header in the bool AWSv4ComplSingle::complete() function in the rgw_auth_s3.cc file. The validation of the header and the signature is done separately. However, why is it possible to create a bucket successfully even when x-amz-content-sha256 is incorrect?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the CreateBucket request body is empty, we use a null completer instead of AWSv4ComplSingle. see is_v4_payload_empty() in:

ceph/src/rgw/rgw_rest_s3.cc

Lines 5820 to 5827 in d7e2a32

if (is_v4_payload_unsigned(exp_payload_hash) || is_v4_payload_empty(s) || is_non_s3_op) {
return {
access_key_id,
client_signature,
session_token,
std::move(string_to_sign),
sig_factory,
null_completer_factory

if the request body isn't empty (for example, from s3cmd mb s3://testbucket --bucket-location=foo which sends a CreateBucketConfiguration xml document), i do see AWSv4ComplSingle being created and later checked in do_aws4_auth_completion:

CONTENT_LENGTH=102
...
req 9584837891480720678 0.000000000s delaying v4 auth
...
req 9584837891480720678 0.001000034s s3:create_bucket NOTICE: call to do_aws4_auth_completion
req 9584837891480720678 0.001000034s s3:create_bucket v4 auth ok -- do_aws4_auth_completion
req 9584837891480720678 0.001000034s s3:create_bucket create bucket input data=<CreateBucketConfiguration><LocationConstraint>foo</LocationConstraint></CreateBucketConfiguration>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since is_v4_payload_empty() is the only case we're missing, i pushed a draft commit to #55250 that adds it right before that null-completer part. how does that look?

cc @mattbenjamin who's working on other completer changes in #54856

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it is also a good idea.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@cbodley

cbodley commented Feb 16, 2024

Copy link
Copy Markdown
Contributor

this merged with #55250. thanks for the help @climb-mountain123!

@cbodley cbodley closed this Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants