opensearch-project / logstash-output-opensearch

A Logstash plugin that sends event data to a OpenSearch clusters and stores as an index.
https://opensearch.org/docs/latest/clients/logstash/index/
Apache License 2.0
106 stars 80 forks source link

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

Closed dblock closed 1 year ago

dblock commented 1 year ago

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 https://github.com/opensearch-project/logstash-output-opensearch/issues/207#issuecomment-1688616636.

Issues Resolved

Closes #207.

Check List

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.

kffallis commented 1 year ago

appreciate the work on this team

opensearch-trigger-bot[bot] commented 1 year ago

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.