在我的Cassandra配置中,我启用了用户身份验证,并通过ssl与cqlsh连接。
我在用gocql实现相同功能时遇到问题,以下是我的代码:
cluster := gocql.NewCluster("127.0.0.1")
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: "myuser",
Password: "mypassword",
}
cluster.SslOpts = &gocql.SslOptions {
CertPath: "/path/to/cert.pem",
}
当我尝试连接时,出现以下错误:
gocql: unable to create session: connectionpool: unable to load X509 key pair: open : no such file or directory
在python中,我可以使用类似的方法做到这一点:
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
USER = 'username'
PASS = 'password'
ssl_opts = {'ca_certs': '/path/to/cert.pem',
'ssl_version': PROTOCOL_TLSv1
}
credentials = PlainTextAuthProvider(username = USER, password = PASS)
# define host, port, cqlsh protocaol version
cluster = Cluster(contact_points= HOST, protocol_version= CQLSH_PROTOCOL_VERSION, auth_provider = credentials, port = CASSANDRA_PORT)
我检查了gocql和TLS文档here和here,但不确定如何设置ssl选项。
最佳答案
您要添加不带私钥的证书,这是“无此文件或目录”错误的出处。
您的python代码正在添加CA;您应该对Go代码执行相同的操作:
gocql.SslOptions {
CaPath: "/path/to/cert.pem",
}