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

A connection to ES on cloud with param fix. #62

Merged
merged 3 commits into from
May 8, 2023

Conversation

mashhurs
Copy link
Collaborator

@mashhurs mashhurs commented May 1, 2023

Description

A connection to ES on cloud with cloud_auth option is raising an exception of [HTTP/1.1 401 Unauthorized]. This change properly sets the username and password in the credentials and establishes successful connection to ES on cloud.

@mashhurs mashhurs requested a review from yaauie May 2, 2023 15:22
@mashhurs mashhurs added the bug Something isn't working label May 4, 2023
@mashhurs mashhurs self-assigned this May 4, 2023
@@ -1,5 +1,6 @@
## 0.0.2 (UNRELEASED)
- Presents helpful guidance when run on an unsupported version of Java [#43](https://github.com/elastic/logstash-filter-elastic_integration/pull/43)
- Fix: now plugin is able to establish a connection to Elasticsearch on Elastic cloud with `cloud_id` and `cloud_auth` authentication pair [#62](https://github.com/elastic/logstash-filter-elastic_integration/pull/62)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will be moved to 0.0.3 once we release after #51 merge.

@@ -21,13 +21,12 @@
import org.apache.http.ssl.SSLContextBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.common.Strings;
Copy link
Member

Choose a reason for hiding this comment

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

I am hesitant to pull unrelated extra bits from Elasticsearch in because although they are likely-stable, they are internal implementation details of Elasticsearch.

Comment on lines 350 to 358
final int colonIndex = cloudAuth.getPassword().indexOf(":");
if (colonIndex <= 0) {
throw new IllegalArgumentException("Invalid cloudAuth.");
}
String username = cloudAuth.getPassword().substring(0, colonIndex);
String password = cloudAuth.getPassword().substring(colonIndex + 1);

Strings.requireNonEmpty(username, "cloudAuth username");
Strings.requireNonEmpty(password, "cloudAuth password");
Copy link
Member

Choose a reason for hiding this comment

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

An alternative that doesn't rely on Elasticsearch internals, using com.google.common.base.Strings#isNullOrEmpty(String) from the guava we already explicitly depend on:

Suggested change
final int colonIndex = cloudAuth.getPassword().indexOf(":");
if (colonIndex <= 0) {
throw new IllegalArgumentException("Invalid cloudAuth.");
}
String username = cloudAuth.getPassword().substring(0, colonIndex);
String password = cloudAuth.getPassword().substring(colonIndex + 1);
Strings.requireNonEmpty(username, "cloudAuth username");
Strings.requireNonEmpty(password, "cloudAuth password");
final String cloudAuthValue = cloudAuth.getValue();
final int colonIndex = cloudAuthValue.indexOf(":");
final String username;
final String password;
if ((colonIndex <= 0)
|| isNullOrEmpty(username = cloudAuthValue.substring(0, colonIndex))
|| isNullOrEmpty(password = cloudAuthValue.substring(colonIndex + 1))) {
throw new IllegalArgumentException("Invalid cloudAuth.");
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ES Strings is in common (kind of util) which would less likely change (and have IngestDocument, etc dependencies) but as we have a guava for these kinds of operations, updated it with recent commit.

Copy link
Member

Choose a reason for hiding this comment

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

ES Strings is in common (kind of util) which would less likely change (and have IngestDocument, etc dependencies) but as we have a guava for these kinds of operations

Yes; it is on our class-path as a transitive dependency of one or more Elasticsearch bits that we directly depend on, and is likely-stable, but we don't need to increase our cross-ties.

@mashhurs mashhurs force-pushed the connection-with-cloud-auth-fix branch from 5756475 to 4e1c18d Compare May 6, 2023 15:21
@mashhurs mashhurs requested a review from yaauie May 6, 2023 15:27
@yaauie yaauie merged commit 55a0356 into elastic:main May 8, 2023
@yaauie yaauie deleted the connection-with-cloud-auth-fix branch May 8, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cloud_auth unable to authenticate
2 participants