草庐IT

MongoDB 提供了一个基本的身份验证系统。它在 2.2.3 版本中有变化吗?

coder 2023-11-06 原文

场景: Installed MongoDB 2.2.3在机器上(Windows 64 位)

按照所有步骤在 MongoDB 服务器上强制执行身份验证。

  1. 将用户添加到管理数据库

    use admin
    db.addUser('me_admin', '12345');
    db.auth('me_admin','12345');
    
  2. 使用 --auth 选项运行数据库服务器(mongod.exe 进程)以启用 身份验证

关注了类似问题的所有答案: How to secure MongoDB with username and password

问题:对于新版本 2.2.3,我无法设置身份验证。在执行相同的步骤后,我能够为 version 2.0.8 设置身份验证在同一台机器上。但它在 MongoDB 文档的某处提到 "Authentication on Localhost 在 2.2 版之前和之后略有不同"

问题有什么变化以及如何在新版本(即 2.2 及更高版本)中强制执行身份验证。任何人都可以提供一些想法或解决方案来对新的 MongoDB 2.2.3 进行同样的处理吗? ?


更新: 当我从命令提示符使用 --auth 参数启动 mongod.exe 进程时,我已经检查过身份验证在 2.2.3 上是否相同。

我在配置文件中使用了 auth=true 参数,如 docs 中所述, 但这没有用。

完成的研究:

  1. mongod.cfg文件包含如下配置时

    logpath=c:\mongodb\log\mongo.log, auth=true, profile=2

    log.txt 文件包含以下日志

    Mon Mar 11 15:06:35 Trying to start Windows service 'MongoDB'
    Mon Mar 11 15:06:35 Service running
    Mon Mar 11 15:06:35 [initandlisten] MongoDB starting : pid=7152 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI
    Mon Mar 11 15:06:35 [initandlisten] db version v2.2.3, pdfile version 4.5
    Mon Mar 11 15:06:35 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
    Mon Mar 11 15:06:35 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
    Mon Mar 11 15:06:35 [initandlisten] options: { config: "C:\mongodb\mongod.cfg", logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true }
    Mon Mar 11 15:06:35 [initandlisten] journal dir=/data/db/journal
    Mon Mar 11 15:06:35 [initandlisten] recover : no journal files present, no recovery needed
    Mon Mar 11 15:06:35 [initandlisten] waiting for connections on port 27017
    Mon Mar 11 15:06:35 [websvr] admin web console waiting for connections on port 28017
    
  2. 当我从命令提示符 mongod --auth 运行时,将显示以下日志:

        Mon Mar 11 15:09:40 [initandlisten] MongoDB starting : pid=6536 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI
        Mon Mar 11 15:09:40 [initandlisten] db version v2.2.3, pdfile version 4.5
        Mon Mar 11 15:09:40 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
        Mon Mar 11 15:09:40 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
        Mon Mar 11 15:09:40 [initandlisten] options: { auth: true }
        Mon Mar 11 15:09:40 [initandlisten] journal dir=/data/db/journal
        Mon Mar 11 15:09:40 [initandlisten] recover : no journal files present, no recovery needed
        Mon Mar 11 15:09:40 [initandlisten] waiting for connections on port 27017
        Mon Mar 11 15:09:40 [websvr] admin web console waiting for connections on port 28017
    

注意:选项的变化:

  1. 选项:{ 配置:“C:\mongodb\mongod.cfg”,日志路径: "c:\mongodb\log\mongo.log auth=true profile=2", service: true //不起作用

  2. options: { auth: true }//有效

有趣观察到的是,

当它从配置文件运行时。

logpath=c:\mongodb\log\mongo.log, auth=true, profile=2

它变成了:

logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true

我知道这是问题。它应该是这样的:

日志路径:"c:\mongodb\log\mongo.log", auth=true, profile="2", service: true

所以,问题是如何从配置文件传递 auth=true 参数并在 Windows7 上将 mongod.exe 进程作为服务运行

最佳答案

如您引用的部分所述,变化很小:

In general if there are no users for the admin database, you may connect via the localhost interface. For sharded clusters running version 2.2, if mongod is running with auth then all users connecting over the localhost interface must authenticate, even if there aren’t any users in the admin database.

基本上在 2.2 之前,如果你在分片集群中,你可以连接到本地主机,如果在管理数据库中找不到用户,则不会强制进行身份验证。这意味着如果您设置一个分片集群,那么设置一个默认用户可能是明智的,您已经这样做了。

Can anybody give some idea or solution to proceed the same with new MongoDB 2.2.3?

新的授权系统就在那里,你不需要做任何事情;就是这样。

关于MongoDB 提供了一个基本的身份验证系统。它在 2.2.3 版本中有变化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15333871/

有关MongoDB 提供了一个基本的身份验证系统。它在 2.2.3 版本中有变化吗?的更多相关文章

  1. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  2. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  3. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  4. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  5. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  6. ruby-on-rails - 如果为空或不验证数值,则使属性默认为 0 - 2

    我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val

  7. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  8. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  9. ruby - 为什么 SecureRandom.uuid 创建一个唯一的字符串? - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?

  10. ruby-on-rails - 如何将验证与模型分开 - 2

    我有一些非常大的模型,我必须将它们迁移到最新版本的Rails。这些模型有相当多的验证(User有大约50个验证)。是否可以将所有这些验证移动到另一个文件中?说app/models/validations/user_validations.rb。如果可以,有人可以提供示例吗? 最佳答案 您可以为此使用关注点:#app/models/validations/user_validations.rbrequire'active_support/concern'moduleUserValidationsextendActiveSupport:

随机推荐