elm*_*lto 6 java ssl cassandra
我想设置自己的CA以与cassandra集群一起使用,这样我每次添加新节点时都不必复制所有证书.我已经阅读了一些Cassandra和SSL的教程,但它们都可以复制证书.我在CA流程中有点迷失
这是我认为我需要做的
现在:
优点:不再在节点之间复制ssl证书.每个节点只需一个,然后就可以了.
编辑:
好的,我就这样做了.如果我犯了任何错误,请告诉我.我遗漏了像JCE文件和适当的cassandra.yaml配置之类的东西.这些需要出现在服务器上!
openssl genrsa -out clusterCA.key 2048
openssl req -x509 -new -key clusterCA.key -days <DAYS> -out clusterCA.pem
keytool -importcert -alias clusterCA -file clusterCA.pem -keystore clustertruststore -storepass <PASS>
#on each cassandra host for clients. for client replace nodename with clientname
keytool -genkeypair -alias <NODENAME> -keyalg RSA -keysize 2048 -dname "CN=<NODENAME>,OU=<UNITNAME>,O=<ORGANISATION>" -keypass <PASS> -keystore <NODENAME>.keystore -storepass <PASS> -validity <DAYS>
keytool -keystore <NODENAME>.keystore -alias <NODENAME> -certreq -file <NODENAME>.cert -storepass <PASS> -keypass <PASS>
# sign it with CA
openssl x509 -req -CA clusterCA.pem -CAkey clusterCa.key -in <NODENAME>.cert -out <NODENAME>.signed -days <DAYS> -CAcreateserial
# add rootCA to host
keytool -keystore <NODENAME>.keystore -storepass <PASS> -alias clusterCA -import -file clusterCA.pem -noprompt
keytool -keystore <NODENAME>.keystore -storepass <PASS> -alias <NODENAME> -import -file <NODENAME>.signed -keypass <PASS>
## use <NODENAME>.keystore as truststore and keystore for cassandra node / client trust/keystore
## No need to copy keystores around. You only need it on your host
## create CQLSH pem
keytool -importkeystore -srckeystore <NODENAME>.keystore -destkeystore <NODENAME>_user1.p12 -deststoretype PKCS12
openssl pkcs12 -in <NODENAME>_user1.p12 -out <NODENAME>_user1.pem -nodes
## use <NODENAME>_user1.pem as certfile for cqlsh
Run Code Online (Sandbox Code Playgroud)
你的策略非常合理,这就是我的方式.您希望拥有自己的证书颁发机构,然后为每个节点创建CSR.这比单独信任节点证书更容易管理.
区分节点间加密和客户端加密也很重要.Cassandra为每个设置有不同的设置(在上面的链接中记录).如果使用客户端到节点加密,您还需要拥有客户端证书的信任库.您可以使用相同的信任库,也可以向客户端颁发证书.
在客户端到节点端,这里是 java驱动程序测试如何使用密钥和信任库设置SSLContext 的示例:
/**
* @param keyStorePath Path to keystore, if absent is not used.
* @param trustStorePath Path to truststore, if absent is not used.
* @return {@link com.datastax.driver.core.SSLOptions} with the given keystore and truststore path's for
* server certificate validation and client certificate authentication.
*/
public SSLOptions getSSLOptions(Optional<String> keyStorePath, Optional<String> trustStorePath) throws Exception {
TrustManagerFactory tmf = null;
if(trustStorePath.isPresent()) {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(this.getClass().getResourceAsStream(trustStorePath.get()), DEFAULT_CLIENT_TRUSTSTORE_PASSWORD.toCharArray());
tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
}
KeyManagerFactory kmf = null;
if(keyStorePath.isPresent()) {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(this.getClass().getResourceAsStream(keyStorePath.get()), DEFAULT_CLIENT_KEYSTORE_PASSWORD.toCharArray());
kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, DEFAULT_CLIENT_KEYSTORE_PASSWORD.toCharArray());
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf != null ? kmf.getKeyManagers() : null, tmf != null ? tmf.getTrustManagers() : null, new SecureRandom());
return new SSLOptions(sslContext, SSLOptions.DEFAULT_SSL_CIPHER_SUITES);
}
Run Code Online (Sandbox Code Playgroud)
一旦成为SSLOptions对象,您就可以将其简单地传递到Cluster Builder中,即:
cluster = Cluster.builder()
.addContactPoint(host)
.withSSL(sslOptions))
.build();
Run Code Online (Sandbox Code Playgroud)
CQLSH通过cqlshrc文件支持SSL.您可以在此处找到如何设置的示例.