Skip to content

Commit

Permalink
[#6740]: Update clients to support mTLS in YB clusters.
Browse files Browse the repository at this point in the history
Summary: Since the coreDB supports mutual TLS, we need to ensure all RPC clients allow for that mode of connection. This diff adds the required code for yb-client to ensure proper functioning with mTLS enabled universes.

Test Plan:
Tested by creating an rf-1 yugabyted cluster with mTLS enabled. Used yb-cli to test for the following cases:
1) yb-cli passes all the flags correctly:
```
yb> connect --masters 127.0.0.1:7100 --certFile
/Users/yugabyte/Desktop/yugabyte-2.5.1.0/certs/ca.crt --clientCertFile
/Users/yugabyte/Desktop/yugabyte-2.5.1.0/certs/node.127.0.0.1.crt --clientKey
/Users/yugabyte/Desktop/yugabyte-2.5.1.0/certs/node.127.0.0.1.key
Connected to database at 127.0.0.1:7100
yb> list masters
Got 1 masters [(index) HostName Port UUID IsLeader State]:
    (1) 127.0.0.1 7100 d1b54ed4e0cd4a6dbe4b7aa8b4ad7926 true ALIVE
    Time taken: 609 ms.
yb> list tablet-servers
Got 1 tablet servers [(index) HostName Port UUID]:
    (1) 127.0.0.1 9100 c675511bf3a54782bcc10981e1b5a6b4
    Time taken: 12 ms.
```
2) yb-cli doesn't pass the client cert and key.
```
yb> connect --masters 127.0.0.1:7100 --certFile
/Users/yugabyte/Desktop/yugabyte-2.5.1.0/certs/ca.crt
Connected to database at 127.0.0.1:7100
yb> list masters
Failed to fetch masters info for database at 127.0.0.1:7100, error:
org.yb.client.NonRecoverableException: Too many attempts: YRpc(method=ListMasters,
service=yb.master.MasterService, tablet=null, attempt=6, maxAttempts=100,
DeadlineTracker(timeout=10000, elapsed=8154), Deferred@1289590497(state=PENDING, result=null,
callback=(continuation of Deferred@1364209305 after retry RPC after error@1902091760) ->
(continuation of Deferred@1611313267 after retry RPC after error@683610023) -> (continuation of
Deferred@1524561648 after retry RPC after error@536367732) -> (continuation of Deferred@712153672
after retry RPC after error@23484913) -> (continuation of Deferred@1822428066 after retry RPC after
error@80644961), errback=(continuation of Deferred@1364209305 after retry RPC after
error@1902091760) -> (continuation of Deferred@1611313267 after retry RPC after error@683610023) ->
(continuation of Deferred@1524561648 after retry RPC after error@536367732) -> (continuation of
Deferred@712153672 after retry RPC after error@23484913) -> (continuation of Deferred@1822428066
after retry RPC after error@80644961)))
```
The following error was also observed on the master:
```
I1223 15:28:22.020306 237490176 secure_stream.cc:546] SECURE[S] kHandshake { local: 127.0.0.1:7100
remote: 127.0.0.1:56103 }: Handshake failed: Network error (yb/rpc/secure_stream.cc:674): Handshake
failed: peer did not return a certificate, address: 127.0.0.1, hostname:
```

Reviewers: bogdan, sergei, sanketh

Reviewed By: sanketh

Subscribers: jenkins-bot, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D10207
  • Loading branch information
Arnav15 committed Feb 16, 2021
1 parent 8ef3197 commit 1e5639c
Show file tree
Hide file tree
Showing 20 changed files with 405 additions and 52 deletions.
2 changes: 1 addition & 1 deletion java/interface-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</parent>

<artifactId>interface-annotations</artifactId>
Expand Down
14 changes: 10 additions & 4 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
<packaging>pom</packaging>

<name>YugaByte</name>
Expand Down Expand Up @@ -112,6 +112,8 @@

<postgresql.jdbc.driver.version>42.2.5</postgresql.jdbc.driver.version>

<bouncycastle.version>1.61</bouncycastle.version>

<!-- Test configuration -->
<testdata.dir>target/testdata</testdata.dir>
<testArgLine>-enableassertions -Xmx3000m
Expand All @@ -128,7 +130,6 @@
<module>yb-client</module>
<module>yb-cli</module>
<module>yb-cql</module>
<module>yb-cql-4x</module>
<module>yb-pgsql</module>
<module>yb-loadtester</module>
<module>yb-jedis-tests</module>
Expand Down Expand Up @@ -342,7 +343,7 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
Expand Down Expand Up @@ -474,6 +475,11 @@
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>

<!--
Dependencies typically used in tests.
Expand All @@ -494,7 +500,7 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions java/yb-cdc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</parent>
<groupId>org.yb</groupId>
<artifactId>yb-cdc</artifactId>
Expand Down Expand Up @@ -43,12 +43,12 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
11 changes: 8 additions & 3 deletions java/yb-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</parent>

<artifactId>yb-cli</artifactId>
Expand All @@ -40,12 +40,12 @@
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand All @@ -70,6 +70,11 @@
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.61</version>
</dependency>
</dependencies>

<build>
Expand Down
24 changes: 22 additions & 2 deletions java/yb-cli/src/main/java/org/yb/ybcli/commands/YBCliCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.yb.Common.HostPortPB;
import org.yb.Schema;
import org.yb.client.AsyncYBClient;
import org.yb.client.AsyncYBClient.AsyncYBClientBuilder;
import org.yb.client.ChangeConfigResponse;
import org.yb.client.GetLoadMovePercentResponse;
import org.yb.client.GetMasterClusterConfigResponse;
Expand Down Expand Up @@ -84,9 +85,28 @@ public String connect(
@CliOption(key = { "masters", "m" },
mandatory = true,
help = "Comma separated list of masters as '<host>:<port>'")
final String masterAddresses) {
final String masterAddresses,
@CliOption(key = { "certFile", "cert"},
help = "CA Certificate for SSL connections.")
final String certFile,
@CliOption(key = { "clientCertFile", "clientCert"},
help = "Client Certificate for mTLS connections.")
final String clientCertFile,
@CliOption(key = { "clientKeyFile", "clientKey"},
help = "Client Private Key for mTLS connections.")
final String clientKeyFile) {
try {
AsyncYBClient asyncClient = new AsyncYBClient.AsyncYBClientBuilder(masterAddresses).build();
AsyncYBClientBuilder builder = new AsyncYBClientBuilder(masterAddresses);
if (certFile != null) {
builder.sslCertFile(certFile);
}
if (clientCertFile != null) {
if (clientKeyFile == null) {
return "ClientKey cannot be null when ClientCert is provided.";
}
builder.sslClientCertFiles(clientCertFile, clientKeyFile);
}
AsyncYBClient asyncClient = builder.build();
ybClient = new YBClient(asyncClient);
this.masterAddresses = masterAddresses;
connectedToDatabase = true;
Expand Down
9 changes: 7 additions & 2 deletions java/yb-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
</parent>

<artifactId>yb-client</artifactId>
<name>YB Java Client</name>
<version>0.8.2-SNAPSHOT</version>
<version>0.8.3-SNAPSHOT</version>
<properties>
<yb.thirdparty.dir>${project.basedir}/../../thirdparty</yb.thirdparty.dir>
</properties>

<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.61</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Loading

0 comments on commit 1e5639c

Please sign in to comment.