-
Notifications
You must be signed in to change notification settings - Fork 190
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
AwsSdk2Transport throw exception when using ApacheHttpClient to make an unsupported DELETE/GET request with a body #1256
AwsSdk2Transport throw exception when using ApacheHttpClient to make an unsupported DELETE/GET request with a body #1256
Conversation
java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java
Outdated
Show resolved
Hide resolved
8e1d91a
to
d837e5c
Compare
e75c9ec
to
a8a42f8
Compare
214545a
to
febd596
Compare
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.
Looks good. A lot going on that's somewhat unrelated to the signing fix, you might want to extract it first, but up to you.
...lient/src/test/java/org/opensearch/client/transport/util/GeneratedCertificateSSLContext.java
Outdated
Show resolved
Hide resolved
febd596
to
3e8c288
Compare
java-client/src/test/java/org/opensearch/client/transport/aws/AwsSdk2TransportTests.java
Outdated
Show resolved
Hide resolved
...lient/src/test/java/org/opensearch/client/transport/util/SelfSignedCertificateAuthority.java
Show resolved
Hide resolved
3e8c288
to
031f30b
Compare
…an unsupported DELETE/GET request with a body The AWS SDK's ApacheHttpClient implementation does not send the request body on DELETE or GET requests, https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java#L118-L137. Additionally moves to the supported `AwsV4HttpSigner` as `Aws4Signer` is now deprecated: https://github.com/aws/aws-sdk-java-v2/blob/88abec27e7d5d35b21545c7e05875a7cc3d0f46e/core/auth/src/main/java/software/amazon/awssdk/auth/signer/Aws4Signer.java Signed-off-by: Thomas Farr <tsfarr@amazon.com>
031f30b
to
92d1480
Compare
Unfortunately on further digging and expanding the tests a bit, AWS SDK's ApacheHttpClient does not send the request body at all for DELETE or GET requests, https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java#L118-L137 So this doesn't actually fix anything, as such I've pivoted to pre-emptively throwing an exception as the request would fail signature validation anyway and gives a clear reasoning. |
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
@Xtansia Probably worth opening an issue in that SDK, AFAIK nothing says |
@dblock indeed the spec [1] is not strict on that but the general recommendation (like [2]) is that GET should not have a body, DELETE may though (but shouldn't) [3]. Fe, https://www.rfc-editor.org/rfc/rfc9110.html#name-get says (similar for DELETE):
[1] https://www.rfc-editor.org/rfc/rfc9110.html#name-changes-from-rfc-7231 |
java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java
Outdated
Show resolved
Hide resolved
@@ -118,6 +122,10 @@ public AwsSdk2Transport( | |||
* @param options Options that apply to all requests. Can be null. Create with | |||
* {@link AwsSdk2TransportOptions#builder()} and use these to specify non-default credentials, | |||
* compression options, etc. | |||
* | |||
* @implNote Using {@code software.amazon.awssdk.http.apache.ApacheHttpClient} is discouraged as it does not support request bodies on GET or DELETE requests. |
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.
👍
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
I might just try PR'ing a fix into aws-sdk seeing as it's relatively simple change, and hopefully mean more likely to actually get fixed. |
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Created aws/aws-sdk-java-v2#5704 |
Good work 👏 |
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/opensearch-java/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/opensearch-java/backport-2.x
# Create a new branch
git switch --create backport/backport-1256-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e8e3a9942c1d2e006ea82ce8f4395fc94a4dd53b
# Push it to GitHub
git push --set-upstream origin backport/backport-1256-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/opensearch-java/backport-2.x Then, create a pull request where the |
…an unsupported DELETE/GET request with a body (opensearch-project#1256) * AwsSdk2Transport throw exception when using ApacheHttpClient to make an unsupported DELETE/GET request with a body The AWS SDK's ApacheHttpClient implementation does not send the request body on DELETE or GET requests, https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java#L118-L137. Additionally moves to the supported `AwsV4HttpSigner` as `Aws4Signer` is now deprecated: https://github.com/aws/aws-sdk-java-v2/blob/88abec27e7d5d35b21545c7e05875a7cc3d0f46e/core/auth/src/main/java/software/amazon/awssdk/auth/signer/Aws4Signer.java Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add guide note Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix javadoc Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-use ContentStreamProvider Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Also validate URLConnection client Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotless Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Test HEAD and OPTIONS Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit e8e3a99)
…an unsupported DELETE/GET request with a body (#1256) (#1288) * AwsSdk2Transport throw exception when using ApacheHttpClient to make an unsupported DELETE/GET request with a body The AWS SDK's ApacheHttpClient implementation does not send the request body on DELETE or GET requests, https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java#L118-L137. Additionally moves to the supported `AwsV4HttpSigner` as `Aws4Signer` is now deprecated: https://github.com/aws/aws-sdk-java-v2/blob/88abec27e7d5d35b21545c7e05875a7cc3d0f46e/core/auth/src/main/java/software/amazon/awssdk/auth/signer/Aws4Signer.java Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add guide note Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix javadoc Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-use ContentStreamProvider Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Also validate URLConnection client Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotless Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Test HEAD and OPTIONS Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit e8e3a99)
Hello @Xtansia , |
@houssain-barouni Yes, I have created #1333 |
Description
The AWS SDK's ApacheHttpClient implementation does not send the request body on DELETE or GET requests, https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java#L118-L137.
Additionally moves to the supported
AwsV4HttpSigner
asAws4Signer
is now deprecated: https://github.com/aws/aws-sdk-java-v2/blob/88abec27e7d5d35b21545c7e05875a7cc3d0f46e/core/auth/src/main/java/software/amazon/awssdk/auth/signer/Aws4Signer.javaIssues Resolved
Relates to #712
Relates to #521
Fixes #503
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.