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

ODBC SSL Compliance Fix #75

Merged
merged 10 commits into from
Jun 22, 2022

Conversation

forestmvey
Copy link

Description

Fixed ODBC Driver Issues:

  • Driver ignores the UseSSL flag
  • SQL plugin query fails if opensearch instance has SSL enabled, and host url doesn't use https:// prefix
  • UI allows for mismatch between UseSSL flag, and specified protocol in host url
  • Driver defaults to OpenDistro sql endpoint in event of error with SQL plugin query

Issues Resolved

Github: 280

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has user manual doc added
  • Commits are signed 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.

…oint bug when using SSL without protocol specified in url

Signed-off-by: forestmvey <forestv@bitquilltech.com>
…he url

Signed-off-by: forestmvey <forestv@bitquilltech.com>
…tribution node

Signed-off-by: forestmvey <forestv@bitquilltech.com>
… url and/or incompatible with server url

Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
@forestmvey forestmvey requested a review from a team June 17, 2022 21:38
@codecov
Copy link

codecov bot commented Jun 17, 2022

Codecov Report

Merging #75 (4d88664) into integ-odbc_ssl_compliance_fix (26058b8) will not change coverage.
The diff coverage is n/a.

@@                       Coverage Diff                        @@
##             integ-odbc_ssl_compliance_fix      opensearch-project/sql#75   +/-   ##
================================================================
  Coverage                            97.66%   97.66%           
  Complexity                            2743     2743           
================================================================
  Files                                  268      268           
  Lines                                 6772     6772           
  Branches                               435      435           
================================================================
  Hits                                  6614     6614           
  Misses                                 157      157           
  Partials                                 1        1           
Flag Coverage Δ
sql-engine 97.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26058b8...4d88664. Read the comment docs.

if(rt_opts.crypt.use_ssl) {
rt_opts.conn.server = std::string("https://") + std::string(self->connInfo.server);
} else {
rt_opts.conn.server = std::string("http://") + std::string(self->connInfo.server);

Choose a reason for hiding this comment

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

rt_opts.conn.server should follow the same assignment patter as other properties in this method -- rt_opts.conn.server.assign(...)

@@ -1005,7 +1009,9 @@ std::string OpenSearchCommunication::GetClusterName() {

void OpenSearchCommunication::SetSqlEndpoint() {
std::string distribution = GetServerDistribution();
if (distribution.compare("opensearch") == 0) {
if (distribution.empty()) {
sql_endpoint = "Error";

Choose a reason for hiding this comment

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

If this is an error state, is there a better way to propagate the error to the user?

Is it possible for distribution to be empty?

Copy link
Author

@forestmvey forestmvey Jun 17, 2022

Choose a reason for hiding this comment

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

Distribution is empty in the event of GetServerDistribution() having an exception caught. I figured having Error for the endpoint is better than the previous /_opendistro/_sql when unable to query sql plugin. I am open to something else.

Copy link

@MaxKsyunz MaxKsyunz Jun 17, 2022

Choose a reason for hiding this comment

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

I see.

So, with this change, if GetServerDistribution returns "", then SetSqlEndpoint sets sql_endpoint to "Error", then EstablishConnection proceeds to try to connect to host Error, probably fails and returns false?

If that's correct, then it's better if EstablishConnection returns false after SetSqlEndpoint.

…ut server url generation into own function. Minor logic revisions.

Signed-off-by: forestmvey <forestv@bitquilltech.com>
@forestmvey forestmvey force-pushed the odbc_ssl_compliance_fix branch from 630d961 to af7c34b Compare June 20, 2022 20:32
…ausing an unusable UI state for windows users.

Signed-off-by: forestmvey <forestv@bitquilltech.com>
…failure to establish connection with url

Signed-off-by: forestmvey <forestv@bitquilltech.com>
SetErrorDetails("Connection error", m_error_message,
ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
LogMsg(OPENSEARCH_ERROR, m_error_message.c_str());
m_error_message_to_user = m_error_message;
return "";

Choose a reason for hiding this comment

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

why are we returning "" in all cases? Does it make sense to reconsider the response type of this function? Change to return void, or change the returns so that they return actual content ....?

Choose a reason for hiding this comment

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

Note: this is the problem with not have a javadoc.
The API contract for this function isn't described, which means I have to read the code and look up all the usages of this function to understand WHAT string is expected from this function.
Please add a javadoc header comment to the function you know what the parameters/returns are supposed to be. Then determine if a string return type is appropriate.

@@ -73,6 +75,26 @@ char CC_connect(ConnectionClass *self) {
return 1;
}

std::string generateValidServerUrl(ConnectionClass *self) {
std::string valid_server_url = "";
if(!strlen(self->connInfo.server)) {
Copy link

@MaxKsyunz MaxKsyunz Jun 20, 2022

Choose a reason for hiding this comment

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

I think, you'll simplify this function if you wrap self->connInfo.server into a string_view.

return valid_server_url;
}

bool url_len_valid = (strlen(self->connInfo.server) > strlen(HTTPS_PREFIX));

Choose a reason for hiding this comment

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

Why is url_len_valid necessary?

Copy link
Author

Choose a reason for hiding this comment

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

std::string::find: "If s does not point to an array long enough, it causes undefined behavior".
https://cplusplus.com/reference/string/string/find/

…g valid server URL's with string_view usage.

Signed-off-by: forestmvey <forestv@bitquilltech.com>
@forestmvey forestmvey merged commit 61e9a7b into integ-odbc_ssl_compliance_fix Jun 22, 2022
@Yury-Fridlyand Yury-Fridlyand deleted the odbc_ssl_compliance_fix branch January 12, 2023 19:45
andy-k-improving pushed a commit that referenced this pull request Nov 16, 2024
1. Remove unnecessary throws exception.
2. Use java style array declaration.
3. Remove unused variables.
4. Replace lambda with method references
5. Replace statement with lambda
6. Use valid random string

Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants