Skip to content

Commit f3b848a

Browse files
committed
Different handling for security specific errors in the CLI. Fix for #33230 (#33255)
1 parent e5eddc2 commit f3b848a

File tree

2 files changed

+14
-0
lines changed
  • docs/reference/sql/endpoints
  • x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli

2 files changed

+14
-0
lines changed

docs/reference/sql/endpoints/cli.asciidoc

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ the first parameter:
2222
$ ./bin/elasticsearch-sql-cli https://some.server:9200
2323
--------------------------------------------------
2424

25+
If security is enabled on your cluster, you can pass the username
26+
and password in the form `username:password@host_name:port`
27+
to the SQL CLI:
28+
29+
[source,bash]
30+
--------------------------------------------------
31+
$ ./bin/elasticsearch-sql-cli https://sql_user:[email protected]:9200
32+
--------------------------------------------------
33+
2534
Once the CLI is running you can use any <<sql-spec,query>> that
2635
Elasticsearch supports:
2736

x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/Cli.java

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.jline.terminal.TerminalBuilder;
2828
import java.io.IOException;
2929
import java.net.ConnectException;
30+
import java.sql.SQLInvalidAuthorizationSpecException;
3031
import java.util.Arrays;
3132
import java.util.List;
3233
import java.util.logging.LogManager;
@@ -139,6 +140,10 @@ private void checkConnection(CliSession cliSession, CliTerminal cliTerminal, Con
139140
// Most likely Elasticsearch is not running
140141
throw new UserException(ExitCodes.IO_ERROR,
141142
"Cannot connect to the server " + con.connectionString() + " - " + ex.getCause().getMessage());
143+
} else if (ex.getCause() != null && ex.getCause() instanceof SQLInvalidAuthorizationSpecException) {
144+
throw new UserException(ExitCodes.NOPERM,
145+
"Cannot establish a secure connection to the server " +
146+
con.connectionString() + " - " + ex.getCause().getMessage());
142147
} else {
143148
// Most likely we connected to something other than Elasticsearch
144149
throw new UserException(ExitCodes.DATA_ERROR,

0 commit comments

Comments
 (0)