Repository navigation
Apply disable-ssl-validation to the HTTP/2 client - #1462
ryanjbaxter merged 3 commits into
Conversation
spring.cloud.openfeign.httpclient.disable-ssl-validation was only applied to the Apache HttpClient 5 client. Http2ClientFeignConfiguration never read it, so with the JDK HTTP/2 client, calls to a server with an untrusted certificate still failed with an SSLHandshakeException. When the property is set, configure the HttpClient.Builder with an SSLContext whose trust manager accepts every certificate. It extends X509ExtendedTrustManager, so hostname verification is skipped as well, matching the Apache HttpClient 5 behavior. Fixes spring-cloudgh-1196 Signed-off-by: Rajesh Vasa <guptha.rh@gmail.com>
ryanjbaxter
left a comment
There was a problem hiding this comment.
We should also update the docs to state that the property effects the http2 client
| * manager, so this also skips hostname verification, like the Apache HttpClient 5 | ||
| * configuration does with its no-op hostname verifier. | ||
| */ | ||
| static class DisabledValidationTrustManager extends X509ExtendedTrustManager { |
There was a problem hiding this comment.
Can this class be shared with HttpClient5FeignConfiguration?
There was a problem hiding this comment.
Done in 100eee6: it's now a shared package-private DisabledValidationTrustManager class used by both configurations.
837740b to
8ccad9a
Compare
…cument HTTP/2 support Address review feedback on spring-cloudgh-1196: - Move DisabledValidationTrustManager to its own package-private class, shared by HttpClient5FeignConfiguration and Http2ClientFeignConfiguration. It extends X509ExtendedTrustManager, so the JDK HttpClient also skips hostname verification; Apache HttpClient 5 already skipped it with its no-op hostname verifier. - Log a warning when the HTTP/2 client is created with disable-ssl-validation=true. - Document that the property applies to the HTTP/2 client too, in the property description and the HTTP clients section. Signed-off-by: Rajesh Vasa <guptha.rh@gmail.com>
8ccad9a to
100eee6
Compare
|
Thanks @ryanjbaxter! Updated:
Should HC5 log the same warning? Happy to add it. |
ryanjbaxter
left a comment
There was a problem hiding this comment.
Yes a warning there also would be good
|
|
||
| |=== | ||
|
|
||
| `spring.cloud.openfeign.httpclient.disable-ssl-validation` applies to both Apache HttpClient 5 and the HTTP/2 (Java `HttpClient`) client. When it is `true`, server certificates and host names are not verified, and the HTTP/2 client logs a warning when it is created. Use it only for testing, never in production. |
There was a problem hiding this comment.
Actually to be consistent with what the docs state
You can further customise http clients by setting values in the
spring.cloud.openfeign.httpclient.xxxproperties. The ones prefixed just withhttpclientwill work for all the clients, the ones prefixed withhttpclient.hc5to Apache HttpClient 5, and the ones prefixed withhttpclient.http2to Http2Client. You can find a full list of properties you can customise in the appendix.
We http/2 should have its own property
Address review feedback on spring-cloudgh-1196: to follow the documented httpclient.hc5.* / httpclient.http2.* convention, the HTTP/2 client now uses spring.cloud.openfeign.httpclient.http2.disable-ssl-validation instead of the top-level property. The top-level httpclient.disable-ssl-validation again applies only to Apache HttpClient 5, so existing users who set it do not silently lose validation on the HTTP/2 client. Update the docs and configuration properties table, and add a test that the top-level property does not affect the HTTP/2 client. Signed-off-by: Rajesh Vasa <guptha.rh@gmail.com>
|
Thanks Ryan, that makes sense. I've moved it to its own property, |
|
Thanks for the review and merge, @ryanjbaxter! |
Fixes #1196
spring.cloud.openfeign.httpclient.disable-ssl-validationwas only applied to the Apache HttpClient 5 client, andHttp2ClientFeignConfigurationhad no way to disable SSL validation, so with the JDK HTTP/2 client, calls to a server with an untrusted certificate always failed with anSSLHandshakeException.Following the documented
httpclient.hc5.*/httpclient.http2.*convention, the HTTP/2 client now has its own property,spring.cloud.openfeign.httpclient.http2.disable-ssl-validation. When it istrue, theHttpClient.Builderis configured with anSSLContextwhose trust manager accepts every certificate. It extendsX509ExtendedTrustManager, so hostname verification is skipped as well, matching the Apache HttpClient 5 behavior. A warning is logged when the client is created with validation disabled.The top-level
httpclient.disable-ssl-validationstill applies only to Apache HttpClient 5, so existing users who set it do not silently lose validation on the HTTP/2 client. The trust manager is now a shared package-private class used by both configurations. The docs and the configuration properties table are updated.The issue also mentions the default client. That client is Feign's own
Client.Default, created outside the auto-configured clients, so I kept this PR focused on the HTTP/2 client. Happy to follow up on the default client if you'd like.Tests
FeignHttp2ClientDisableSslValidationTests: starts a local HTTPS server with a self-signed certificate issued for a different host name (a new test keystore,http2-self-signed.p12), and checks that the HTTP/2 client connects and logs a warning whenhttpclient.http2.disable-ssl-validation=true, still fails withSSLHandshakeExceptionby default, and is not affected by the top-levelhttpclient.disable-ssl-validationspring-cloud-openfeign-corebuild passes locally, including checkstyle