【发布时间】:2019-04-24 01:53:15
【问题描述】:
我在 Ubuntu 16.04.5 LTS 服务器上设置了一个具有 SSL 安全性的 mongoDB 数据库,并且我已经使用了几个月。为了在 mongo 上设置 SSL,我遵循了 Rajan Maharjan 在 medium.com (link) 上的教程。在一段时间未使用后返回我的服务器,我收到以下错误消息:
SSL peer certificate validation failed: certificate has expired
查看mongo日志,发现:
[PeriodicTaskRunner] Server certificate is now invalid. It expired on 2018-11-10T08:10:11.000Z
因此,我按照与第一次创建证书时相同的步骤,使用 rootCA.key 文件重新生成并重新签署了所有证书。我重新启动了 mongod:
service mongod restart
现在我有“自签名证书”错误:
MongoDB shell version v4.0.2
connecting to: mongodb://IP:port/
2018-11-21T13:11:10.584+0000 E NETWORK [js] SSL peer certificate
validation failed: self signed certificate
2018-11-21T13:11:10.584+0000 E QUERY [js] Error:
couldn't connect to server IP:port, connection attempt failed:
SSLHandshakeFailed: SSL peer certificate validation failed: self signed certificate :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
我的连接字符串如下:
mongo --ssl --sslCAFile /PATH/TO/rootCA.pem --sslPEMKeyFile /PATH/TO/mongodb.pem --host IP:port
我没有找到任何关于为 mongoDB 重新签名证书的资源。任何帮助将不胜感激。
编辑
/etc/mongod.conf:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: PORT
bindIp: IP
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/rootCA.pem
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
security:
authorization: "enabled"
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
【问题讨论】:
-
您是否使用了正确的 sslCAFile?不应该是
/PATH/TO/abc.crt吗? -
@AniketMaithani 根据您的建议,我尝试使用 .crt,我在日志中得到
Error: network error while attempting to run command 'isMaster' on host和SSL peer certificate validation failed: self signed certificate。我的问题中的连接字符串与我之前使用的相同并且它曾经工作过。 -
在 mongo 连接字符串中添加
--sslAllowInvalidCertificates选项会产生以下错误消息:日志中的[js] Error: network error while attempting to run command 'isMaster' on host和SSL peer certificate validation failed: self signed certificate。 -
嘿@Nicolas 你可以在这里发布你的 /etc/mongod.conf 文件吗?同时尝试使用以下内容:dpaste.de/U4Lm
-
嗨@AniketMaithani 我编辑了我的问题以添加 .conf 文件。我尝试了您的解决方案(并在 .conf 文件中注释掉了 rootCA.pem 行)但使用
mongod --sslMode requireSSL --sslPEMKeyFile /etc/ssl/mongodb.pem我得到exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating并且在重新启动服务时,在日志中出现以下错误WARNING: No SSL certificate validation can be performed since no CA file has been provided
标签: mongodb ssl openssl ubuntu-16.04