-
Notifications
You must be signed in to change notification settings - Fork 455
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
[WIP] HTTP exporter support ssl credentials #938
Conversation
|
Codecov Report
@@ Coverage Diff @@
## main #938 +/- ##
==========================================
- Coverage 95.36% 95.30% -0.05%
==========================================
Files 160 160
Lines 6779 6786 +7
==========================================
+ Hits 6464 6467 +3
- Misses 315 319 +4
|
I have thought using civetweb to setup a temporary HTTP server for unit test. Because prometheus-cpp also depend it. We can also use it without import another library or binary. |
@owent - This looks good - production-ready embeddable web-server, but just wondering whether we really need this for unit tests. What advantage do you think we will get from this over our internal http server specifically for unit-tests? |
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.
I have thought using civetweb to setup a temporary HTTP server for unit test. Because prometheus-cpp also depend it. We can also use it without import another library or binary.
It maybe need more discussion about how to test HTTP requests. @maxgolov @lalitb@owent - This looks good - production-ready embeddable web-server, but just wondering whether we really need this for unit tests. What advantage do you think we will get from this over our internal http server specifically for unit-tests?
We need HTTPS here.If implementation SSL support for http server need a lot codes, maybe it's easier to use a third party library?
@@ -125,6 +125,8 @@ class Request | |||
|
|||
virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; | |||
|
|||
virtual void IncludePermissionsFilePath(std::string filepath) noexcept = 0; |
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.
Maybe we should use nosdt::string_view
instead of std::string here?
@@ -68,6 +68,9 @@ struct OtlpHttpExporterOptions | |||
|
|||
// TODO: Enable/disable to verify SSL certificate | |||
std::chrono::milliseconds timeout = std::chrono::milliseconds(30000); | |||
|
|||
// filepath of the sll certifcate, this is empty if there is none. | |||
std::string sslCertPath; |
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.
Should we use lower case to keep the same style as before?
// TODO: support ssl cert verification for https request | ||
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYPEER, 0); // 1L | ||
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYHOST, 0); // 2L | ||
if (ssl_cert_path.empty()){ |
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.
I think it's better to use a option use_ssl_credentials
to control whether to ignore SSL verification which just like in OtlpGrpcExporterOptions
.
And we should also privide options to set CURLOPT_SSLKEY
and CURLOPT_SSLCERT
.
@pavanshahm - Thanks for this PR. It would be good to have SSL certificate check integrated. A couple of comments here:
|
OK. I thought we don't really need to test the ssl-handshake as part of the unit test here, as it should work correctly with |
I don't think we need to test ssl-handshake either. But I think we should test whether the new options ( |
ok, I was thinking to avoid testing the HTTPS request path as part of the unit test if it needs us to build and link with a third-party library. On second thought - I had a quick look at |
@pavanshahm - just wondering if you have plans to continue on this PR? As this has been at WIP state for some time now. |
@pavanshahm - Checking one more time if you have plans to work on this PR. While it would be really good to get it merged, we also don't want to keep it stale for long. |
@@ -68,6 +68,9 @@ struct OtlpHttpExporterOptions | |||
|
|||
// TODO: Enable/disable to verify SSL certificate | |||
std::chrono::milliseconds timeout = std::chrono::milliseconds(30000); | |||
|
|||
// filepath of the sll certifcate, this is empty if there is none. | |||
std::string sslCertPath; |
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.
mTLS support (requested by someone else here in another issue) will require two more fields for paths to private and public key. To avoid confusion please rename this field to make it more clear that this is path to trusted root CA certificates, e.g. sslCaCertPath
.
In my issue I also asked about way to specify minimum TLS version (CURLOPT_SSLVERSION
) and allowed ciphers (CURLOPT_SSL_CIPHER_LIST
). Below I also mentioned another one to disable certificate validation. All of them would need corresponding fields here.
BTW, you also have typo in comment above - sll -> ssl
@@ -58,12 +58,20 @@ class Request : public http_client::Request | |||
timeout_ms_ = timeout_ms; | |||
} | |||
|
|||
void IncludePermissionsFilePath(std::string filepath) noexcept override |
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.
Other methods here uses nostd::string_view
for parameters instead of std::string
, please make it consistent.
// TODO: support ssl cert verification for https request | ||
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYPEER, 0); // 1L | ||
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYHOST, 0); // 2L | ||
if (ssl_cert_path.empty()){ |
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.
Empty CA cert path should mean that user wants to use default system path, not disable certificate validation. Ability to disable validation is another use case. Please add another option to disable certificate validation.
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYHOST, 0); // 2L | ||
} else { | ||
curl_easy_setopt(curl_, CURLOPT_CAPATH, ssl_cert_path.c_str()); | ||
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYPEER, 1); |
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.
This option is set by default to 1, so this line can be skipped.
Fixes # (issue)
Changes
We needed to include ssl credentials if we wanted to use the http exporter so we added an additional option in http_exporter_options in order to allow it.
We also needed to update the curl.BUILD files in order to build cURL with the https protocol supported. This was done with a lot of trial and error and copied from the tensorflow build file, so I'm not sure which options are actually necessary and which ones are not.
Unit Tests are pending, but let me know if this is the right approach before I write those tests.
CHANGELOG.md
updated for non-trivial changes