Skip to content

Commit

Permalink
[#8029][YW] Fix slow queries failing to fetch on client-to-node TLS e…
Browse files Browse the repository at this point in the history
…ncrypted universes

Summary:
This issue was observed on 2.7 branch and observed again on master branch with 2.7.0-b17
database version. When client-to-node TLS encryption is enabled on the universe, the fetching of
slow queries fails with 500 error. Upon further digging, the error is caused by pg_hba.conf not
allowing the YW ip address with SSL off. When just the "ssl" = true parameter is added, a different
error was thrown: `org.postgresql.util.PSQLException: SSL error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target`. As a result, the "sslmode" = "require" was added and found to work.

Test Plan:
Create universe with Client-To-Node encryption enabled. Go to the overview page and check
the network logs. The slow_queries API request should not throw an error.

Reviewers: arnav, spotachev, sanketh

Reviewed By: spotachev

Subscribers: jenkins-bot, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D11333
  • Loading branch information
Andrew Cai committed Jun 7, 2021
1 parent 0a5e1d5 commit 8875b62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ public JsonNode query(Universe universe, boolean fetchSlowQueries) {
Callable<JsonNode> callable;

if (fetchSlowQueries) {
callable = new SlowQueryExecutor(ip, node.ysqlServerRpcPort, SLOW_QUERY_STATS_SQL);
callable = new SlowQueryExecutor(
ip,
node.ysqlServerRpcPort,
universe,
SLOW_QUERY_STATS_SQL
);
Future<JsonNode> future = threadPool.submit(callable);
futures.add(future);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.yugabyte.yw.common.ApiHelper;
import com.yugabyte.yw.forms.RunQueryFormData;
import com.yugabyte.yw.forms.SlowQueriesParams;
import com.yugabyte.yw.forms.UniverseDefinitionTaskParams;
import com.yugabyte.yw.models.MetricConfig;
import com.yugabyte.yw.models.Universe;
import org.slf4j.Logger;
Expand Down Expand Up @@ -37,13 +38,15 @@ public class SlowQueryExecutor implements Callable<JsonNode> {
private String hostName;
private int port;
private String query;
private Universe universe;

private final String DEFAULT_DB_USER = "yugabyte";
private final String DEFAULT_DB_PASSWORD = "yugabyte";

public SlowQueryExecutor(String hostName, int port, String query) {
public SlowQueryExecutor(String hostName, int port, Universe universe, String query) {
this.hostName = hostName;
this.port = port;
this.universe = universe;
this.query = query;
this.apiHelper = Play.current().injector().instanceOf(ApiHelper.class);
}
Expand All @@ -70,9 +73,18 @@ private List<Map<String, Object>> resultSetToMap(ResultSet result) throws SQLExc
@Override
public JsonNode call() {
ObjectNode response = Json.newObject();
String connectString = String.format("jdbc:postgresql://%s:%d/%s", hostName, port, "postgres");
try (Connection conn =
DriverManager.getConnection(connectString, DEFAULT_DB_USER, DEFAULT_DB_PASSWORD)) {
String connectString = String.format("jdbc:postgresql://%s:%d/%s",
hostName, port, "postgres");
Properties connInfo = new Properties();
connInfo.put("user", DEFAULT_DB_USER);
connInfo.put("password", DEFAULT_DB_PASSWORD);
UniverseDefinitionTaskParams.Cluster primaryCluster =
universe.getUniverseDetails().getPrimaryCluster();
if (primaryCluster.userIntent.enableClientToNodeEncrypt) {
connInfo.put("ssl", "true");
connInfo.put("sslmode", "require");
}
try (Connection conn = DriverManager.getConnection(connectString, connInfo)) {
if (conn == null) {
response.put("error", "Unable to connect to DB");
} else {
Expand Down

0 comments on commit 8875b62

Please sign in to comment.