为什么我可以在不使用 pymongo 上的“rds-combined-ca-bundle.pem”的情况下连接 AWS-documentDB

问题描述

AWS 如下所述。

##To encrypt data in transit,download the public key for Amazon DocumentDB named rds-combined-ca-bundle.pem

import pymongo

##Create a MongoDB client,open a connection to Amazon DocumentDB as a replica set and specify the read preference as secondary preferred
client = pymongo.MongoClient('mongodb://<sample-user>:<password>@sample-cluster.node.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaset=rs0&readPreference=secondaryPreferred&retryWrites=false') 

但是我可以在不使用 pymongo 上的“rds-combined-ca-bundle.pem”的情况下连接 aws-documentdb。

import ssl
from pymongo import MongoClient

client = MongoClient(db_host,db_port,username=db_user,password=db_password,ssl=True,ssl_cert_reqs=ssl.CERT_NONE)

为什么不使用“rds-combined-ca-bundle.pem”就可以连接??

解决方法

如果您查看 Mongo 文档,当您指定 ssl_cert_reqs=ssl.CERT_NONE 时,您是在告诉 PyMongo 绕过证书验证并仍然允许连接到服务器。 https://api.mongodb.com/python/3.3.0/examples/tls.html

但是,当您指定证书时,它会使用提供的证书执行服务器验证,这是推荐的方法。

,

要获取最新的 .pem 文件,请使用此链接:

https://docs.aws.amazon.com/documentdb/latest/developerguide/ca_cert_rotation.html