节点间(或节点到节点)加密使用 TLS 保护集群中节点之间传输的数据。本页面介绍了如何在 Edge for Private Cloud 上使用 TLS 启用 Cassandra 节点间加密。如需执行这些步骤,您必须熟悉 Cassandra 环的详细信息。
启用 Cassandra 节点间加密
如需启用 Cassandra 节点间加密,请在集群中的所有节点上执行以下过程。您需要将每个节点的公共证书分发到所有节点。完成此操作后,每个节点的 truststore 中都将包含证书 node0.cer、node1.cer 等。每个节点在其密钥库中仅包含自己的私钥。例如,node0 的密钥库中将仅包含 node0.pem。您需要逐个在每个节点上启用加密。
请按照以下步骤启用 Cassandra 节点间加密:
按照附录中的步骤生成服务器证书,以创建自签名密钥和证书。
以下步骤假定您已创建
keystore.node0和truststore.node0,以及密钥库和 truststore 密码,如附录中所述。在继续执行后续步骤之前,应在每个节点上创建密钥库和 truststore 作为初步步骤。- 将以下属性添加到
/opt/apigee/customer/application/cassandra.properties文件中。如果该文件不存在,请创建它。conf_cassandra_internode_encryption=all conf_cassandra_keystore=/opt/apigee/data/apigee-cassandra/keystore.node0 conf_cassandra_keystore_password=keypass conf_cassandra_truststore=/opt/apigee/data/apigee-cassandra/truststore.node0 conf_cassandra_truststore_password=trustpass # Optionally set the following to enable 2-way TLS or mutual TLS # conf_cassandra_require_client_auth=true
- 确保文件
cassandra.properties归 apigee 用户所有:chown apigee:apigee \ /opt/apigee/customer/application/cassandra.properties
在每个 Cassandra 节点上逐一执行以下步骤,以便在不导致用户停机的情况下使更改生效:
- 停止 Cassandra 服务:
/opt/apigee/apigee-service/bin/apigee-service \ apigee-cassandra stop
- 重启 Cassandra 服务:
/opt/apigee/apigee-service/bin/apigee-service \ apigee-cassandra start
- 如需确定 TLS 加密服务是否已启动,请在系统日志中查看以下消息:
Starting Encrypted Messaging Service on TLS port
执行证书轮替
如需轮替证书,请按以下步骤操作:
- 将每个唯一生成的密钥对(请参阅附录)的证书添加到现有 Cassandra 节点的 truststore 中,以便旧证书和新证书都存在于同一 truststore 中:
keytool -import -v -trustcacerts -alias NEW_ALIAS \ -file CERT -keystore EXISTING_TRUSTSTORE
其中,
NEW_ALIAS是用于标识条目的唯一字符串,CERT是要添加的证书文件的名称,EXISTING_TRUSTSTORE是 Cassandra 节点上现有 truststore 的名称。 - 使用复制实用程序(例如 scp)将 truststore 分发到集群中的所有 Cassandra 节点,以替换每个节点正在使用的现有 truststore。
- 对集群执行滚动重启,以加载新的 truststore,并在新密钥就位之前为其建立信任:
/opt/apigee/apigee-service/bin/apigee-service \ apigee-cassandra restart
- 在集群中的每个 Cassandra 节点上,将 cassandra.properties 文件中显示的以下属性更新为新的密钥库值:
conf_cassandra_keystore=NEW_KEYSTORE_PATH conf_cassandra_keystore_password=NEW_KEYSTORE_PASSOWRD
where
NEW_KEYSTORE_PATHis the path to the directory where the keystore file is located andNEW_KEYSTORE_PASSWORDis the keystore password set when the certificates were created, as explained in the Appendix. - Stop the Cassandra service:
/opt/apigee/apigee-service/bin/apigee-service \ apigee-cassandra stop
- 重启 Cassandra 服务:
/opt/apigee/apigee-service/bin/apigee-service \ apigee-cassandra start
- 当所有节点之间成功建立通信后,继续执行下一个 Cassandra 节点。注意:只有在所有节点之间成功建立通信后,才能继续执行下一个节点。
附录
以下示例介绍了如何准备执行节点间加密步骤所需的服务器证书。示例中显示的命令使用以下参数:
| 参数 | 说明 |
|---|---|
node0 |
用于标识节点的任何唯一字符串。 |
keystore.node0 |
密钥库名称。这些命令假定此文件位于当前目录中。 |
keypass |
密钥库和密钥的 keypass 必须相同。 |
dname |
将 node0 的 IP 地址标识为 10.128.0.39。 |
-validity |
此标志上设置的值会使生成的密钥对在 10 年内有效。 |
- 进入以下目录:
cd /opt/apigee/data/apigee-cassandra
- 运行以下命令,在当前目录中生成一个名为
keystore.node0的文件:keytool -genkey -keyalg RSA -alias node0 -validity 3650 \ -keystore keystore.node0 -storepass keypass \ -keypass keypass -dname "CN=10.128.0.39, OU=None, \ O=None, L=None, C=None"
重要提示:请确保密钥密码与密钥库密码相同。
- 将证书导出到单独的文件:
keytool -export -alias node0 -file node0.cer \ -keystore keystore.node0
- 确保该文件只能由 apigee 用户读取,而不能由其他任何人读取:
$ chown apigee:apigee \ /opt/apigee/data/apigee-cassandra/keystore.node0 $ chmod 400 /opt/apigee/data/apigee-cassandra/keystore.node0
- 将生成的证书
node0.cer导入节点的 truststore:keytool -import -v -trustcacerts -alias node0 \ -file node0.cer -keystore truststore.node0
上述命令会要求您设置密码。这是 truststore 密码,可以与您之前设置的密钥库密码不同。如果系统提示您信任相应证书,请输入
yes。 - 使用 openssl 生成不含密钥的证书 PEM 文件。请注意,
cqlsh不适用于所生成格式的证书。$ keytool -importkeystore -srckeystore keystore.node0 \ -destkeystore node0.p12 -deststoretype PKCS12 -srcstorepass \ keypass -deststorepass keypass $ openssl pkcs12 -in node0.p12 -nokeys -out node0.cer.pem \ -passin pass:keypass $ openssl pkcs12 -in node0.p12 -nodes -nocerts -out node0.key.pem -passin pass:keypass
- 对于节点到节点加密,请将
node0.cer文件复制到每个节点,并将其导入每个节点的 truststore。keytool -import -v -trustcacerts -alias node0 \ -file node0.cer -keystore truststore.node1
- 使用
keytool -list检查密钥库和信任库文件中的证书:$ keytool -list -keystore keystore.node0 $ keytool -list -keystore truststore.node0