Skip to content
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

Fix: encode body before signing to match manticore adapter encoding. #217

Merged
merged 1 commit into from
Aug 23, 2023

Conversation

dblock
Copy link
Member

@dblock dblock commented Aug 22, 2023

Description

Manticore adapter encodes the request body before sending in a different way than the ruby code before signing. In the case of a ISO-8859-1 string it may not match the body being signed, causing a 403.

With

puts "       encoding: #{minimum_encoding_for(params[:body])}"
puts "  ruby encoding: #{params[:body].encode(minimum_encoding_for(params[:body])).inspect}"
puts "apache encoding: #{EntityUtils.toString(StringEntity.new(params[:body], minimum_encoding_for(params[:body]))).inspect}"
       encoding: UTF-8
  ruby encoding: "{\"index\":{\"_id\":null,\"_index\":\"my-index\",\"routing\":null}}\n{\"message\":\"bo\xEEte de r\xE9ception\",\"@version\":\"1\",\"@timestamp\":\"2023-08-23T12:21:54.057Z\"}\n"
apache encoding: "{\"index\":{\"_id\":null,\"_index\":\"my-index\",\"routing\":null}}\n{\"message\":\"bo�te de r�ception\",\"@version\":\"1\",\"@timestamp\":\"2023-08-23T12:21:54.057Z\"}\n"

I attempted to match encoding in pure ruby, too, but couldn't find the magical combination. It would be nice if Manticore had a way to callback with the entity being sent to avoid encoding twice, too :(

Repro in #207 (comment).

Issues Resolved

Closes #207.

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has documentation added
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Thanks for finding the cause of this issue!

@oeyh oeyh merged commit ada13fa into opensearch-project:main Aug 23, 2023
22 checks passed
@dblock dblock deleted the fix-207 branch August 23, 2023 17:06
@kffallis
Copy link

appreciate the work on this team

@opensearch-trigger-bot
Copy link

The backport to 1.3 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.3 1.3
# Navigate to the new working tree
cd .worktrees/backport-1.3
# Create a new branch
git switch --create backport/backport-217-to-1.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 ada13fa1303a9868c12e7ef69298e3c72fff59d4
# Push it to GitHub
git push --set-upstream origin backport/backport-217-to-1.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.3

Then, create a pull request where the base branch is 1.3 and the compare/head branch is backport/backport-217-to-1.3.

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.

[BUG] Receiving signature mismatch issue with SigV4
4 participants