我正在部署我的第一个小应用程序,使用 MongoDB
和 Mongoid
作为驱动程序。
在生产中使用 MongoDB 的正确安全方式是什么?
我的意思是在开发过程中我刚刚开始 mongod
仅此而已 - 不需要用户名或密码,而且看起来不安全。
Mongoid 也设置默认配置
production:
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
我应该如何在我的生产服务器上配置这个选项和整个 MongoDB?
最佳答案
创建需要使用用户名和密码进行连接的生产环境:
在 mongo 控制台中:
// Add an Admin User (to the admin db)
use admin
db.addUser("theadmin", "anadminpassword")
// Use your database
use supercool
// Add a user (to your database)
db.addUser("joe", "passwordForJoe")
// show all users:
db.system.users.find()
// add readonly user (kinda cool)
db.addUser("readonly", "passwordForJoe", true)
现在,所有与 mongodb 的连接都需要身份验证 -- http://www.mongodb.org/display/DOCS/Security+and+Authentication
另外:您可以考虑使用您的 linux 防火墙仅允许来自您的 Web 服务器的 27017。
关于ruby-on-rails - 生产中的 MongoDB 和 Mongoid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7300080/