如何正确配置 MongoDB 以在 Ubuntu 上使用 Letsencrypt SSL

Pet*_*tah 8 ubuntu ssl tls mongodb ubuntu-14.04

如何正确配置 MongoDB 以在 Ubuntu 上使用 Letsencrypt SSL?

我使用 Letsencrypt 创建了一个 SSL 证书并通过以下方式将其组合:

cat /etc/letsencrypt/live/example.com/fullchain.pem /etc/letsencrypt/live/example.com/privkey.pem > /etc/ssl/mongo.pem
Run Code Online (Sandbox Code Playgroud)

并设置 mongo 配置,如:

net:
  port: 27017
  bindIp: 0.0.0.0
  ssl:
    mode: requireSSL
    PEMKeyFile: /etc/ssl/mongo.pem
Run Code Online (Sandbox Code Playgroud)

但是在尝试启动 Mongo 时出现此错误:

No SSL certificate validation can be performed since no CA file has been provided; please specify an sslCAFile parameter
Run Code Online (Sandbox Code Playgroud)

如何正确设置 CAFile?Ubuntu 通常不会在自己的文件中使用带有一堆不同根证书的“CA 路径”吗?我尝试使用 CURL CA 包,但这也不起作用。

我使用的是 Mongo v3.0.12 和 Ubuntu 14.04

Her*_*sen 9

您组合了错误的 pem 文件。您需要privkey.pemcert.pem.

cat /etc/letsencrypt/live/example.com/privkey.pem /etc/letsencrypt/live/example.com/cert.pem > /etc/ssl/mongo.pem
Run Code Online (Sandbox Code Playgroud)

对于 CAFile,您需要从https://www.identrust.com/certificates/trustid/root-download-x3.html下载 IdenTrust DST Root CA X3

sudo touch /etc/ssl/ca.crt
sudo chmod 777 /etc/ssl/ca.crt
Run Code Online (Sandbox Code Playgroud)

添加网站的证书,添加 -----BEGIN CERTIFICATE----- 和 -----END CERTIFICATE----- 行并确保以新行结尾保存文件:

sudo vi /etc/ssl/ca.crt
Run Code Online (Sandbox Code Playgroud)

然后使用以下命令将 crt 文件转换为 pem:

sudo touch /etc/ssl/ca.pem
sudo chmod 777 /etc/ssl/ca.pem
sudo openssl x509 -in /etc/ssl/ca.crt -out /etc/ssl/ca.pem -outform PEM
Run Code Online (Sandbox Code Playgroud)

并与chain.pemfrom Let's Encrypt 组合成单个文件ca.pem

sudo cat /etc/letsencrypt/live/example.com/chain.pem >> /etc/ssl/ca.pem
Run Code Online (Sandbox Code Playgroud)

要设置 CAFile,请遵循此 mongo 配置设置:

net:  
  port: 27017
  bindIp: 0.0.0.0
  ssl:  
    mode: requireSSL  
    PEMKeyFile: /etc/ssl/mongo.pem
    CAFile: /etc/ssl/ca.pem
Run Code Online (Sandbox Code Playgroud)

重启MongoDB:

sudo systemctl restart mongod
sudo systemctl status mongod
Run Code Online (Sandbox Code Playgroud)

不要忘记更新 Let's Encrypt 证书的那一刻,您还需要更新mongo.pemca.pem

  • 因为当时 let's encrypt 是相当新的技术,所以他们使用 Identrust 交叉签署他们的证书。您可以直接从 https://letsencrypt.org/certs/trustid-x3-root.pem.txt 下载它。现在让我们加密受到广泛信任 (2认同)

Ada*_*m C 3

您需要的 CA 文件可以从 Letsencrypt 获取,在此处查找中间证书之一:

https://letsencrypt.org/certificates/

然后,使用SSL CAFile选项指定该证书的路径。