Datastax Cassandra - 带 SSL 的 Cqlsh 不工作
Datastax Cassandra - Cqlsh with SSL not working
我在 Ubuntu 机器上安装了单节点 Datastax Cassandra v3.5 集群。我正在尝试使用命令行界面 cqlsh 使用 SSL 选项连接到节点但没有成功(来自同一台机器)。我遵循的步骤是:
- 按照本指南准备了 .keystore、.cer 证书和 .truststore http://docs.datastax.com/en/cassandra/2.0/cassandra/security/secureSSLCertificates_t.html
相应地修改了我的cassandra.yaml:
client_encryption_options:
enabled: true
optional: false
keystore: /************************/.keystore
keystore_password: ************************
require_client_auth: false
# Set trustore and truststore_password if require_client_auth is true
truststore: /************************/.truststore
truststore_password: ************************
创建了一个 cqlshrc conf 文件并按照本指南进行填充 https://docs.datastax.com/en/cassandra/2.1/cassandra/security/secureCqlshSSL_t.html :
[connection]
hostname = *****
port = 9042
factory = cqlshlib.ssl.ssl_transport_factory
[ssl]
certfile = /home/conf/mycert.cer
validate = true ## Optional, true by default
所以基本上我创建了一个私钥和 public 密钥,将 Cassandra 指向我的 .keystore 和 .truststore(尽管我认为这不是必需的,因为我没有强制执行客户端身份验证)和 cqlsh到 public 密钥(证书)。
每当我尝试启动 cqlsh --ssl
我总是得到相同的错误,而不是 Cassandra 中的单个调试消息。错误信息是:
Connection error: ('Unable to connect to any servers',
{'*.*****.******': error(0, "Tried connecting to
[('..*.***', 9042)]. Last error: _ssl.c:344:error:00000000:lib(0):func(0):reason(0)")})
请注意,如果我删除 SSL 身份验证,一切都会正常运行。
编辑
我已经按照@Adam Holmberg 的建议解决了最初的问题,但 SSL 连接仍然不成功。我检查了我是否安装了 JCE 库,并且我一直在尝试强制 cqslh 使用 SSLv23 或 TLSv1 建立与 Cassandra 服务器的连接,但我一直收到以下错误:
Connection error: ('Unable to connect to any servers', ... ... ...
Last error: _ssl.c:510: EOF occurred in violation of protocol")})
此外,我还添加了 JVM 选项 -Djavax.net.debug=all 无济于事,我没有看到任何关于 ssl 的额外日志。
假设“/home/conf/mycert.cer”是您在服务器配置期间创建的文件,这不是 Python (cqlsh) 的正确格式。您需要将其导出为 PEM 格式以用于 Python:
keytool -exportcert -alias <alias> -keypass <pass> -keystore <keystore> -storepass <pass> -rfc -file cassandra_cert.pem
如果您只是尝试使用 cqlsh 并且不关心真正的安全性,您也可以从 cqlshrc 中省略这些选项(验证、certfile)并在没有证书验证的情况下连接。
经过一些尝试和错误以及@Adam 和@Aaron 提供的一些有用提示(感谢您的帮助),我终于在 cqlsh 和我的 Cassandra 服务器实例之间建立了 SSL 连接。
在思考这个问题后,我得出的结论是客户端和服务器都存在某种额外的配置错误,为了帮助可能面临同样问题的其他人,我将在这里 post我的最终配置:
cqlshrc
[connection]
hostname = *****.*****.*****.*****.*****
port = 9042
[cql]
version = 3.4
[tracing]
max_trace_wait = 10.0
[ssl]
certfile = /****/****/****/****.cer.pem
validate = false ## Optional, true by default
#version = SSLv23
#factory = cqlshlib.ssl.ssl_transport_factory
cassandra.yaml(相关部分)
# enable or disable client/server encryption.
client_encryption_options:
enabled: true
# If enabled and optional is set to true encrypted and unencrypted connections are handled.
optional: false
keystore: /***/****/****/.keystore
keystore_password: *********
require_client_auth: false
# Set trustore and truststore_password if require_client_auth is true
truststore: /****/****/****/.truststore
truststore_password: ****
# More advanced defaults below:
# protocol: TLSv1
# algorithm: SunX509
# store_type: JKS
# cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
我遇到了错误:
上次错误:[SSL] 内部错误 (_ssl.c:727)
解决这个问题的方法是在 cqlshrc 文件中添加 SSL 版本行:
[connection]
(...)
version = SSLv23
我在 Ubuntu 机器上安装了单节点 Datastax Cassandra v3.5 集群。我正在尝试使用命令行界面 cqlsh 使用 SSL 选项连接到节点但没有成功(来自同一台机器)。我遵循的步骤是:
- 按照本指南准备了 .keystore、.cer 证书和 .truststore http://docs.datastax.com/en/cassandra/2.0/cassandra/security/secureSSLCertificates_t.html
相应地修改了我的cassandra.yaml:
client_encryption_options: enabled: true optional: false keystore: /************************/.keystore keystore_password: ************************ require_client_auth: false # Set trustore and truststore_password if require_client_auth is true truststore: /************************/.truststore truststore_password: ************************
创建了一个 cqlshrc conf 文件并按照本指南进行填充 https://docs.datastax.com/en/cassandra/2.1/cassandra/security/secureCqlshSSL_t.html :
[connection] hostname = ***** port = 9042 factory = cqlshlib.ssl.ssl_transport_factory [ssl] certfile = /home/conf/mycert.cer validate = true ## Optional, true by default
所以基本上我创建了一个私钥和 public 密钥,将 Cassandra 指向我的 .keystore 和 .truststore(尽管我认为这不是必需的,因为我没有强制执行客户端身份验证)和 cqlsh到 public 密钥(证书)。
每当我尝试启动 cqlsh --ssl
我总是得到相同的错误,而不是 Cassandra 中的单个调试消息。错误信息是:
Connection error: ('Unable to connect to any servers', {'*.*****.******': error(0, "Tried connecting to [('..*.***', 9042)]. Last error: _ssl.c:344:error:00000000:lib(0):func(0):reason(0)")})
请注意,如果我删除 SSL 身份验证,一切都会正常运行。
编辑
我已经按照@Adam Holmberg 的建议解决了最初的问题,但 SSL 连接仍然不成功。我检查了我是否安装了 JCE 库,并且我一直在尝试强制 cqslh 使用 SSLv23 或 TLSv1 建立与 Cassandra 服务器的连接,但我一直收到以下错误:
Connection error: ('Unable to connect to any servers', ... ... ... Last error: _ssl.c:510: EOF occurred in violation of protocol")})
此外,我还添加了 JVM 选项 -Djavax.net.debug=all 无济于事,我没有看到任何关于 ssl 的额外日志。
假设“/home/conf/mycert.cer”是您在服务器配置期间创建的文件,这不是 Python (cqlsh) 的正确格式。您需要将其导出为 PEM 格式以用于 Python:
keytool -exportcert -alias <alias> -keypass <pass> -keystore <keystore> -storepass <pass> -rfc -file cassandra_cert.pem
如果您只是尝试使用 cqlsh 并且不关心真正的安全性,您也可以从 cqlshrc 中省略这些选项(验证、certfile)并在没有证书验证的情况下连接。
经过一些尝试和错误以及@Adam 和@Aaron 提供的一些有用提示(感谢您的帮助),我终于在 cqlsh 和我的 Cassandra 服务器实例之间建立了 SSL 连接。
在思考这个问题后,我得出的结论是客户端和服务器都存在某种额外的配置错误,为了帮助可能面临同样问题的其他人,我将在这里 post我的最终配置:
cqlshrc
[connection]
hostname = *****.*****.*****.*****.*****
port = 9042
[cql]
version = 3.4
[tracing]
max_trace_wait = 10.0
[ssl]
certfile = /****/****/****/****.cer.pem
validate = false ## Optional, true by default
#version = SSLv23
#factory = cqlshlib.ssl.ssl_transport_factory
cassandra.yaml(相关部分)
# enable or disable client/server encryption.
client_encryption_options:
enabled: true
# If enabled and optional is set to true encrypted and unencrypted connections are handled.
optional: false
keystore: /***/****/****/.keystore
keystore_password: *********
require_client_auth: false
# Set trustore and truststore_password if require_client_auth is true
truststore: /****/****/****/.truststore
truststore_password: ****
# More advanced defaults below:
# protocol: TLSv1
# algorithm: SunX509
# store_type: JKS
# cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
我遇到了错误: 上次错误:[SSL] 内部错误 (_ssl.c:727)
解决这个问题的方法是在 cqlshrc 文件中添加 SSL 版本行:
[connection]
(...)
version = SSLv23