forked from apache/kudu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java] fixed bug in the connection negotiation code
This patch fixes a typo in the connection negotiation code in the Java client. Prior to this fix, channel binding information was not verified during connection negotiation because the peer certificate was not set. In addition, I modified the error handing code in Negotiator.java to abort connection negotiation upon receiving SSLPeerUnverifiedException due to the absence of the channel binding information or the presence of the invalid one. I also added a test to verify that Kudu Java client doesn't connect to a Kudu server which doesn't provide valid channel binding information during the connection negotiation phase. Kudos to Andy Singer for pointing to the bug. Change-Id: I7bfd428128e224f03901a6cd7b33283495a28d54 Reviewed-on: http://gerrit.cloudera.org:8080/14713 Tested-by: Kudu Jenkins Reviewed-by: Adar Dembo <[email protected]> Reviewed-by: Todd Lipcon <[email protected]> (cherry picked from commit a0e8964) Reviewed-on: http://gerrit.cloudera.org:8080/14727 Reviewed-by: Alexey Serbin <[email protected]>
- Loading branch information
1 parent
34dfee4
commit 91d196f
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
|
||
import com.google.common.base.Stopwatch; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.ImmutableList; | ||
import com.stumbleupon.async.Deferred; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.After; | ||
|
@@ -61,8 +62,19 @@ public class TestSecurity { | |
private enum Option { | ||
LONG_LEADER_ELECTION, | ||
SHORT_TOKENS_AND_TICKETS, | ||
START_TSERVERS | ||
}; | ||
START_TSERVERS, | ||
} | ||
|
||
static private class KeyValueMessage { | ||
final String key; | ||
final String val; | ||
final String msg; | ||
KeyValueMessage(String k, String v, String m) { | ||
key = k; | ||
val = v; | ||
msg = m; | ||
} | ||
} | ||
|
||
private void startCluster(Set<Option> opts) throws IOException { | ||
MiniKuduClusterBuilder mcb = new MiniKuduClusterBuilder(); | ||
|
@@ -435,4 +447,46 @@ public void testExternallyProvidedSubjectRefreshedExternally() throws Exception | |
Assert.assertThat(cla.getAppendedText(), CoreMatchers.containsString( | ||
"Using caller-provided subject with Kerberos principal [email protected].")); | ||
} | ||
|
||
/** | ||
* Test that if a Kudu server (in this case master) doesn't provide valid | ||
* connection binding information, Java client fails to connect to the server. | ||
*/ | ||
@Test(timeout=60000) | ||
public void testNegotiationChannelBindings() throws Exception { | ||
startCluster(ImmutableSet.of(Option.START_TSERVERS)); | ||
// Test precondition: all is well with masters -- the client is able | ||
// to connect to the cluster and create a table. | ||
client.createTable("TestSecurity-channel-bindings-0", | ||
getBasicSchema(), getBasicCreateTableOptions()); | ||
|
||
List<KeyValueMessage> variants = ImmutableList.of( | ||
new KeyValueMessage("rpc_inject_invalid_channel_bindings_ratio", "1.0", | ||
"invalid channel bindings provided by remote peer"), | ||
new KeyValueMessage("rpc_send_channel_bindings", "false", | ||
"no channel bindings provided by remote peer")); | ||
|
||
// Make all masters sending invalid channel binding info during connection | ||
// negotiation. | ||
for (KeyValueMessage kvm : variants) { | ||
for (HostAndPort hp : miniCluster.getMasterServers()) { | ||
miniCluster.setMasterFlag(hp, kvm.key, kvm.val); | ||
} | ||
|
||
// Now, a client should not be able to connect to any master: negotiation | ||
// fails because client cannot authenticate the servers since it fails | ||
// to verify the connection binding. | ||
try { | ||
KuduClient c = new KuduClient.KuduClientBuilder( | ||
miniCluster.getMasterAddressesAsString()).build(); | ||
c.createTable("TestSecurity-channel-bindings-1", | ||
getBasicSchema(), getBasicCreateTableOptions()); | ||
Assert.fail("client should not be able to connect to any master"); | ||
} catch (NonRecoverableException e) { | ||
Assert.assertThat(e.getMessage(), CoreMatchers.containsString( | ||
"unable to verify identity of peer")); | ||
Assert.assertThat(e.getMessage(), CoreMatchers.containsString(kvm.msg)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters