2012-11-16 19:49:28 +00:00
|
|
|
-module(replication_ssl).
|
2012-12-14 15:50:49 +00:00
|
|
|
-behavior(riak_test).
|
|
|
|
-export([confirm/0]).
|
2012-11-16 19:49:28 +00:00
|
|
|
-compile(export_all).
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
|
|
|
confirm() ->
|
2014-01-08 17:07:32 +00:00
|
|
|
%% test requires allow_mult=false
|
2014-01-19 18:00:21 +00:00
|
|
|
rt:set_conf(all, [{"buckets.default.allow_mult", "false"}]),
|
2014-01-08 17:07:32 +00:00
|
|
|
|
2013-04-26 15:02:23 +00:00
|
|
|
NumNodes = rt_config:get(num_nodes, 6),
|
|
|
|
ClusterASize = rt_config:get(cluster_a_size, 3),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
2014-05-09 18:46:52 +00:00
|
|
|
CertDir = rt_config:get(rt_scratch_dir) ++ "/certs",
|
|
|
|
|
|
|
|
%% make a bunch of crypto keys
|
|
|
|
make_certs:rootCA(CertDir, "rootCA"),
|
|
|
|
make_certs:intermediateCA(CertDir, "intCA", "rootCA"),
|
|
|
|
make_certs:endusers(CertDir, "rootCA", ["site3.basho.com", "site4.basho.com"]),
|
|
|
|
make_certs:endusers(CertDir, "intCA", ["site1.basho.com", "site2.basho.com"]),
|
|
|
|
|
2013-01-22 18:49:22 +00:00
|
|
|
lager:info("Deploy ~p nodes", [NumNodes]),
|
2012-11-16 19:49:28 +00:00
|
|
|
BaseConf = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
2013-06-03 17:36:50 +00:00
|
|
|
{ssl_enabled, false},
|
2012-11-16 19:49:28 +00:00
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled}
|
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
2013-04-26 15:02:23 +00:00
|
|
|
PrivDir = rt:priv_dir(),
|
2013-02-20 03:50:12 +00:00
|
|
|
|
|
|
|
lager:info("priv dir: ~p -> ~p", [code:priv_dir(riak_test), PrivDir]),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
|
|
|
SSLConfig1 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
2014-05-09 18:46:52 +00:00
|
|
|
{certfile, filename:join([CertDir,
|
2014-06-12 18:38:58 +00:00
|
|
|
"site1.basho.com/cert.pem"])},
|
2014-05-09 18:46:52 +00:00
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site1.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
2014-06-12 18:38:58 +00:00
|
|
|
"site1.basho.com"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
|
|
|
SSLConfig2 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
2014-05-09 18:46:52 +00:00
|
|
|
{certfile, filename:join([CertDir,
|
|
|
|
"site2.basho.com/cert.pem"])},
|
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site2.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
2014-06-12 18:38:58 +00:00
|
|
|
"site2.basho.com"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
|
|
|
SSLConfig3 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
2014-05-09 18:46:52 +00:00
|
|
|
{certfile, filename:join([CertDir,
|
|
|
|
"site3.basho.com/cert.pem"])},
|
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site3.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
2014-06-12 18:38:58 +00:00
|
|
|
"site3.basho.com"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
|
|
|
%% same as above,with a depth of 0
|
|
|
|
SSLConfig3A = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
|
|
|
{ssl_depth, 0},
|
2014-05-09 18:46:52 +00:00
|
|
|
{certfile, filename:join([CertDir,
|
|
|
|
"site3.basho.com/cert.pem"])},
|
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site3.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
2014-06-12 18:38:58 +00:00
|
|
|
"site3.basho.com"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
|
|
|
SSLConfig4 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
|
|
|
{ssl_depth, 0},
|
2014-05-09 18:46:52 +00:00
|
|
|
{certfile, filename:join([CertDir,
|
|
|
|
"site4.basho.com/cert.pem"])},
|
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site4.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
2014-06-12 18:38:58 +00:00
|
|
|
"site4.basho.com"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
|
|
|
SSLConfig5 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
2014-07-15 17:45:46 +00:00
|
|
|
{ssl_depth, 1},
|
|
|
|
{peer_common_name_acl, ["*.basho.com"]},
|
|
|
|
{certfile, filename:join([CertDir,
|
|
|
|
"site1.basho.com/cert.pem"])},
|
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site1.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
|
|
|
"site1.basho.com/cacerts.pem"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
|
|
|
SSLConfig6 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
2014-07-15 17:45:46 +00:00
|
|
|
{ssl_depth, 1},
|
|
|
|
{peer_common_name_acl, ["site1.basho.com"]},
|
|
|
|
{certfile, filename:join([CertDir,
|
|
|
|
"site2.basho.com/cert.pem"])},
|
|
|
|
{keyfile, filename:join([CertDir,
|
|
|
|
"site2.basho.com/key.pem"])},
|
|
|
|
{cacertdir, filename:join([CertDir,
|
|
|
|
"site2.basho.com/cacerts.pem"])}
|
2012-11-16 19:49:28 +00:00
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
2012-12-04 05:13:21 +00:00
|
|
|
SSLConfig7 = [
|
|
|
|
{riak_repl,
|
|
|
|
[
|
|
|
|
{fullsync_on_connect, false},
|
|
|
|
{fullsync_interval, disabled},
|
|
|
|
{ssl_enabled, true},
|
|
|
|
{peer_common_name_acl, ["ca.cataclysm-software.net"]},
|
|
|
|
{certfile, filename:join([PrivDir,
|
|
|
|
"certs/cacert.org/ny-cert-old.pem"])},
|
|
|
|
{keyfile, filename:join([PrivDir,
|
|
|
|
"certs/cacert.org/ny-key.pem"])},
|
|
|
|
{cacertdir, filename:join([PrivDir,
|
|
|
|
"certs/cacert.org/ca"])}
|
|
|
|
]}
|
|
|
|
],
|
|
|
|
|
2014-07-15 17:45:46 +00:00
|
|
|
lager:info("===testing basic connectivity"),
|
2012-12-04 05:13:21 +00:00
|
|
|
|
2014-12-18 21:07:00 +00:00
|
|
|
[Node1, Node2] = rt:deploy_nodes(2, BaseConf, [riak_kv, riak_repl]),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
|
|
|
Listeners = replication:add_listeners([Node1]),
|
|
|
|
replication:verify_listeners(Listeners),
|
|
|
|
|
|
|
|
{Ip, Port, _} = hd(Listeners),
|
|
|
|
replication:add_site(Node2, {Ip, Port, "site1"}),
|
|
|
|
|
2014-07-14 18:37:32 +00:00
|
|
|
replication:wait_for_site_ips(Node2, "site1", Listeners),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
rt:log_to_nodes([Node1, Node2], "Basic connectivity test"),
|
2014-07-15 17:45:46 +00:00
|
|
|
?assertEqual(ok, replication:wait_until_connection(Node1)),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
lager:info("===testing you can't connect to a server with a cert with the same common name"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Testing identical cert is disallowed"),
|
2014-01-06 21:31:27 +00:00
|
|
|
?assertMatch({fail, _}, test_connection({Node1, merge_config(SSLConfig1, BaseConf)},
|
2012-11-16 19:49:28 +00:00
|
|
|
{Node2, merge_config(SSLConfig1, BaseConf)})),
|
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
lager:info("===testing you can't connect when peer doesn't support SSL"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Testing missing ssl on peer fails"),
|
2014-01-06 21:31:27 +00:00
|
|
|
?assertMatch({fail, _}, test_connection({Node1, merge_config(SSLConfig1, BaseConf)},
|
2013-06-03 17:36:50 +00:00
|
|
|
{Node2, BaseConf})),
|
|
|
|
|
|
|
|
lager:info("===testing you can't connect when local doesn't support SSL"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Testing missing ssl locally fails"),
|
2014-01-06 21:31:27 +00:00
|
|
|
?assertMatch({fail, _}, test_connection({Node1, BaseConf},
|
2013-06-03 17:36:50 +00:00
|
|
|
{Node2, merge_config(SSLConfig2, BaseConf)})),
|
|
|
|
|
|
|
|
lager:info("===testing simple SSL connectivity"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Basic SSL test"),
|
2012-11-16 19:49:28 +00:00
|
|
|
?assertEqual(ok, test_connection({Node1, merge_config(SSLConfig1, BaseConf)},
|
|
|
|
{Node2, merge_config(SSLConfig2, BaseConf)})),
|
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
lager:info("===testing SSL connectivity with an intermediate CA"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Intermediate CA test"),
|
2012-11-16 19:49:28 +00:00
|
|
|
?assertEqual(ok, test_connection({Node1, merge_config(SSLConfig1, BaseConf)},
|
|
|
|
{Node2, merge_config(SSLConfig3, BaseConf)})),
|
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
lager:info("===testing disallowing intermediate CAs works"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Disallowing intermediate CA test"),
|
2012-11-16 19:49:28 +00:00
|
|
|
?assertEqual(ok, test_connection({Node1, merge_config(SSLConfig3A, BaseConf)},
|
|
|
|
{Node2, merge_config(SSLConfig4, BaseConf)})),
|
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
lager:info("===testing disallowing intermediate CAs disallows connections"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "Disallowing intermediate CA test 2"),
|
2014-01-06 21:31:27 +00:00
|
|
|
?assertMatch({fail, _}, test_connection({Node1, merge_config(SSLConfig3A, BaseConf)},
|
2012-11-16 19:49:28 +00:00
|
|
|
{Node2, merge_config(SSLConfig1, BaseConf)})),
|
|
|
|
|
2014-07-15 17:45:46 +00:00
|
|
|
lager:info("===testing wildcard and strict ACLs"),
|
2013-06-03 17:36:50 +00:00
|
|
|
rt:log_to_nodes([Node1, Node2], "wildcard and strict ACL test"),
|
2012-11-16 19:49:28 +00:00
|
|
|
?assertEqual(ok, test_connection({Node1, merge_config(SSLConfig5, BaseConf)},
|
|
|
|
{Node2, merge_config(SSLConfig6, BaseConf)})),
|
|
|
|
|
2013-06-03 17:36:50 +00:00
|
|
|
lager:info("===testing expired certificates fail"),
|
|
|
|
rt:log_to_nodes([Node1, Node2], "expired certificates test"),
|
2014-01-06 21:31:27 +00:00
|
|
|
?assertMatch({fail, _}, test_connection({Node1, merge_config(SSLConfig5, BaseConf)},
|
2012-12-04 05:13:21 +00:00
|
|
|
{Node2, merge_config(SSLConfig7, BaseConf)})),
|
|
|
|
|
2012-11-16 19:49:28 +00:00
|
|
|
lager:info("Connectivity tests passed"),
|
|
|
|
|
|
|
|
lager:info("Re-deploying 6 nodes"),
|
|
|
|
|
2014-12-18 21:07:00 +00:00
|
|
|
Nodes = rt:deploy_nodes(6, BaseConf, [riak_kv, riak_repl]),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
|
|
|
[rt:wait_until_pingable(N) || N <- Nodes],
|
|
|
|
|
|
|
|
{ANodes, BNodes} = lists:split(ClusterASize, Nodes),
|
|
|
|
|
|
|
|
lager:info("Reconfiguring nodes with SSL options"),
|
|
|
|
[rt:update_app_config(N, merge_config(SSLConfig5, BaseConf)) || N <-
|
|
|
|
ANodes],
|
|
|
|
|
|
|
|
[rt:update_app_config(N, merge_config(SSLConfig6, BaseConf)) || N <-
|
|
|
|
BNodes],
|
|
|
|
|
|
|
|
[rt:wait_until_pingable(N) || N <- Nodes],
|
|
|
|
|
|
|
|
lager:info("Build cluster A"),
|
2013-01-30 19:15:41 +00:00
|
|
|
repl_util:make_cluster(ANodes),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
|
|
|
lager:info("Build cluster B"),
|
2013-01-30 19:15:41 +00:00
|
|
|
repl_util:make_cluster(BNodes),
|
2012-11-16 19:49:28 +00:00
|
|
|
|
|
|
|
replication:replication(ANodes, BNodes, false),
|
|
|
|
|
|
|
|
pass.
|
|
|
|
|
|
|
|
merge_config(Mixin, Base) ->
|
|
|
|
lists:ukeymerge(1, lists:keysort(1, Mixin), lists:keysort(1, Base)).
|
|
|
|
|
|
|
|
test_connection({Node1, Config1}, {Node2, Config2}) ->
|
|
|
|
rt:update_app_config(Node1, Config1),
|
|
|
|
rt:wait_until_pingable(Node1),
|
|
|
|
rt:update_app_config(Node2, Config2),
|
|
|
|
rt:wait_until_pingable(Node2),
|
2014-07-15 17:45:46 +00:00
|
|
|
rt:wait_for_service(Node1, [riak_kv, riak_repl]),
|
|
|
|
rt:wait_for_service(Node2, [riak_kv, riak_repl]),
|
2013-02-20 03:50:12 +00:00
|
|
|
replication:wait_until_connection(Node1).
|