无法使用cqlsh连接到aws密钥空间

s3fp2yjn  于 2021-06-09  发布在  Cassandra
关注(0)|答案(1)|浏览(417)

我在连接到aws密钥空间时遇到了问题,包括我的应用程序代码和 cqlsh :

cqlsh cassandra.eu-west-2.amazonaws.com 9142 -u "xxxxxxxxxxxxxxx" -p "xxxxxxxxxxxxxxxxxxxxxx" --ssl

Connection error: ('Unable to connect to any servers', {'3.10.201.209': error(1, u"Tried connecting to [('3.10.201.209', 9142)]. Last error: [SSL] internal error (_ssl.c:727)")})

特别令人困惑的是,我的设置在过去是有效的。
我的 cqlshrc :

[connection]
port = 9142
factory = cqlshlib.ssl.ssl_transport_factory

[ssl]
validate = true
certfile = /home/abc/.cassandra/AmazonRootCA1.pem

我拿到证书时是这样的:

wget -c https://www.amazontrust.com/repository/AmazonRootCA1.pem

dns似乎很好:

nslookup cassandra.eu-west-2.amazonaws.com
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   cassandra.eu-west-2.amazonaws.com
Address: 3.10.201.209

我最近从18.04升级到了ubuntu20.04,这可能会引起一些问题。
更新:是的,它可能改变了默认的ssl协议

zujrkrfu

zujrkrfu1#

我为你想出来的 cqlsh ; 您需要设置ssl版本:

[connection]
port = 9142
factory = cqlshlib.ssl.ssl_transport_factory

[cql]
version = 3.4.4

[ssl]
validate = true
certfile = /home/abc/.cassandra/AmazonRootCA1.pem
version = TLSv1_2

对于.net解决方案的修复是类似的;你必须设置 SslProtocols 正确地。
下面是一个有效的f脚本:


# load "../.paket/load/netcoreapp3.1/CassandraCSharpDriver.fsx"

open System
open System.Net.Security
open System.Security
open System.Security.Authentication
open System.Security.Cryptography
open System.Security.Cryptography.X509Certificates
open Cassandra

let private getEnvVar (name : string) =
  let x = Environment.GetEnvironmentVariable name
  if String.IsNullOrWhiteSpace x
  then
    failwithf "The environment variable %s must be set" name
  else
    x

let region = getEnvVar "AWS_REGION"

let keyspace = getEnvVar "AWS_KEYSPACES_KEYSPACE"
let keyspacesUsername = getEnvVar "AWS_KEYSPACES_USERNAME"
let keyspacesPassword = getEnvVar "AWS_KEYSPACES_PASSWORD"

async {
  let certCollection = X509Certificate2Collection ()
  use cert = new X509Certificate2 (@"./AmazonRootCA1.pem", "amazon")

  certCollection.Add (cert) |> ignore

  let sslOptions =
    SSLOptions
      (
        SslProtocols.Tls12,
        true,
        (fun sender certificate chain sslPolicyErrors ->
          if sslPolicyErrors = SslPolicyErrors.None
          then
            true
          else
            printfn "Cassandra node SSL certificate validation error(s): {%A}" sslPolicyErrors
            false)
      )
    |> (fun x -> x.SetCertificateCollection(certCollection))

  let contactPoints = [| sprintf "cassandra.%s.amazonaws.com" region |]

  let cluster =
    Cluster.Builder()
      .AddContactPoints(contactPoints)
      .WithPort(9142)
      .WithAuthProvider(PlainTextAuthProvider (keyspacesUsername, keyspacesPassword))
      .WithSSL(sslOptions)
      .Build()

  use! cassandra =
    cluster.ConnectAsync keyspace
    |> Async.AwaitTask

  printfn "Connected. "
}
|> Async.RunSynchronously

应该很容易翻译成c#:)

相关问题