为什么 mongodb 拒绝 ssl 连接?

Why mongodb refuses ssl connections?

我是 运行 一个位于防火墙后面的虚拟服务器上的 mongodb 3.2 实例(不允许我配置)。如果在 /etc/mongod.conf

中关闭 ssl,Mongo 可以从任何地方访问(和连接)(bind_ip:0.0.0.0)

此外,我生成了一个 CA、一个 server.pem 和一个 client.pem(通过 mongo-shell 连接)。这些证书工作正常,因为我可以从机器连接到 mongod mongod is 运行 on:

$ mongo --host localhost --ssl --sslPEMKeyFile client.pem --sslCAFile ca.crt

但是:当我尝试从另一台具有相同证书的机器连接时,它无法连接:

$ mongo --host mongo1.mydomain.net --ssl --sslPEMKeyFile client.pem --sslCAFile ca.crt

MongoDB shell version: 3.2.9
connecting to: <ip>:27017/test
2016-08-22T22:29:17.632+0200 W NETWORK  [thread1] Failed to connect to <ip>:27017 after 5000 milliseconds, giving up.
2016-08-22T22:29:17.633+0200 E QUERY    [thread1] Error: couldn't connect to server <ip>:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:231:14
@(connect):1:6

这很奇怪,因为 /var/log/mongodb/mongd.log 说 mongod 正在端口 27017 上列出用于 ssl 连接(netstat 表示相同):

2016-08-22T21:09:10.182+0200 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2016-08-22T21:09:10.182+0200 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-08-22T21:09:10.183+0200 I NETWORK  [initandlisten] waiting for connections on port 27017 ssl

日志文件中没有列出其他机器的 ssl 连接尝试,这更奇怪。

所以我问了tcpdump:

23:10:32.984067 IP (tos 0x0, ttl 51, id 64132, offset 0, flags [DF], proto TCP (6), length 60)
    <other_machine>.39644 > 172.12.51.23.27017: Flags [S], cksum 0xd3d0 (correct), seq 1809185188, win 29200, options [mss 1420,sackOK,TS val 7275296 ecr 0,nop,wscale 7], length 0
23:10:32.984112 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    172.12.51.23.27017 > <other_machine>.39644: Flags [S.], cksum 0x9506 (incorrect -> 0x14cf), seq 2653469724, ack 1809185189, win 28960, options [mss 1460,sackOK,TS val 93151206 ecr 7275296,nop,wscale 7], length 0
23:10:33.041545 IP (tos 0x0, ttl 51, id 64133, offset 0, flags [DF], proto TCP (6), length 52)
    <other_machine>.39644 > 172.12.51.23.27017: Flags [.], cksum 0xb3c5 (correct), seq 1, ack 1, win 229, options [nop,nop,TS val 7275313 ecr 93151206], length 0
23:10:33.047713 IP (tos 0x0, ttl 63, id 49309, offset 0, flags [none], proto TCP (6), length 40)
    <other_machine>.39644 > 172.12.51.23.27017: Flags [R.], cksum 0x55ec (correct), seq 1, ack 1, win 229, length 0

mongo 服务器的第一个回复总是有一个无效的校验和。但我真的不知道这是否重要。其实我不知道如何解决这个问题,我只是希望任何人都可以帮助我提示。

干杯, 动态

证书中的主机名可能与 mongo 命令中使用的主机名不同。尝试在 mongo 命令末尾添加 --sslAllowInvalidHostnames 参数。

mongo --host mongo1.mydomain.net --ssl --sslPEMKeyFile client.pem --sslCAFile ca.crt --sslAllowInvalidHostnames

请参阅 mongodb 连接选项 https://docs.mongodb.com/manual/reference/program/mongotop/#cmdoption--sslAllowInvalidHostnames

谢谢穆罕默德!

这也是我的第一个想法。但在与系统管理员交谈后发现,他们安装了一个应用程序防火墙,它将端口 27017 上的 SSL 请求分类为属于 mongodb 服务器的 not。防火墙预期端口 27017 上的未加密流量。

一旦他们重新配置了防火墙,一切都会按预期运行。

再见, 动态