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

[BUG] Failing to connect to an OpenSearch cluster with a bad username/password gives unhelpful error #494

Closed
chenqi0805 opened this issue May 22, 2023 · 3 comments · Fixed by #495
Labels
bug Something isn't working

Comments

@chenqi0805
Copy link
Contributor

chenqi0805 commented May 22, 2023

What is the bug?

Failing to connect to an OpenSearch cluster with a bad username/password gives unhelpful error:

Exception in thread "main" jakarta.json.stream.JsonParsingException: Jackson exception: Unrecognized token 'Unauthorized': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (ByteArrayInputStream); line: 1, column: 13]
	at org.opensearch.client.json.jackson.JacksonJsonpParser.convertException(JacksonJsonpParser.java:97)
	at org.opensearch.client.json.jackson.JacksonJsonpParser.fetchNextToken(JacksonJsonpParser.java:104)
	at org.opensearch.client.json.jackson.JacksonJsonpParser.next(JacksonJsonpParser.java:131)
	at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:82)
	at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:92)
	at org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:56)
	at org.opensearch.client.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:271)
	at org.opensearch.client.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:143)
	at org.opensearch.client.opensearch.cluster.OpenSearchClusterClient.getSettings(OpenSearchClusterClient.java:282)
	at org.opensearch.dataprepper.plugins.sink.opensearch.index.AbstractIndexManager.checkISMEnabled(AbstractIndexManager.java:187)
	at org.opensearch.dataprepper.plugins.sink.opensearch.index.AbstractIndexManager.checkAndCreateIndexTemplate(AbstractIndexManager.java:208)
	at org.opensearch.dataprepper.plugins.sink.opensearch.index.AbstractIndexManager.setupIndex(AbstractIndexManager.java:203)
	at org.opensearch.dataprepper.plugins.sink.opensearch.OpenSearchSink.doInitializeInternal(OpenSearchSink.java:174)
	at org.opensearch.dataprepper.plugins.sink.opensearch.OpenSearchSink.doInitialize(OpenSearchSink.java:139)
	at org.opensearch.dataprepper.model.sink.AbstractSink.initialize(AbstractSink.java:39)
	at org.opensearch.dataprepper.pipeline.Pipeline.isReady(Pipeline.java:194)
	at org.opensearch.dataprepper.DataPrepper.execute(DataPrepper.java:93)
	at org.opensearch.dataprepper.DataPrepperExecute.main(DataPrepperExecute.java:42)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Unauthorized': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (ByteArrayInputStream); line: 1, column: 13]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:759)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3693)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2781)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:907)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:793)
	at org.opensearch.client.json.jackson.JacksonJsonpParser.fetchNextToken(JacksonJsonpParser.java:102)
	... 16 more

How can one reproduce the bug?

use opensearch-java client with wrong username or password configured to call any API against a opensearch engine

What is the expected behavior?

A clear error message indicating wrong username or password

What is your host/environment?

macOS.

Do you have any screenshots?

Screenshot 2023-05-22 at 1 28 29 PM

Do you have any additional context?

The bug seems to be at parsing with both RestClientTransport and AwsSdk2Transport

@chenqi0805 chenqi0805 added bug Something isn't working untriaged labels May 22, 2023
@wbeckler
Copy link

This is another great catch. Thank you for reporting this! If you're up for it, feel free to submit a PR.

@chenqi0805
Copy link
Contributor Author

@wbeckler This one seems not so straightforward to fix as the low level response entity is just a string value of Unauthorized which is not valid json. We probably need to modify that message to be more clear. Do you have suggestions where it can be modified?

@wbeckler
Copy link

@chenqi0805 The fix you submitted for this error parsing issue is an improvement. Thank you for these bar-raising issues and PRs. To answer your question above, for issues around the response from the OpenSearch server, one option is to open an issue in the core repo, https://github.com/opensearch-project/OpenSearch/issues

@reta reta closed this as completed in #495 May 30, 2023
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 a pull request may close this issue.

2 participants