【问题标题】:Mongodb cluster:can query on normal collections ,but not on system.usersMongodb集群:可以查询普通集合,但不能查询system.users
【发布时间】:2014-02-09 05:14:53
【问题描述】:

我使用 keyFile 来验证我的 mongodb 集群系统。我已经拥有针对 admin db 的管理员角色:

所以,首先我使用身份验证登录:

mongo localhost:40000/admin -u root -p 123456
mongos> use admin
switched to db admin
mongos> db.system.users.find()
{ "_id" : ObjectId("52dcb305398751501c530378"), "user" : "root", "pwd" : "a02786431d8419bbebee7aa4dad6aee9", "roles" : [  "clusterAdmin",  "userAdmin",  "readWriteAnyDatabase",  "dbAdmin",  "read" ] }

我以这样的角色登录后,除了addUser操作之外,我可以在admin和任何其他普通数据库上做任何事情(包括查询、删除、修改等)!

例如,对于一个普通的数据库genbank,我尝试添加一个用户:

mongos> use genbank
switched to db genbank
mongos> db.addUser({user:"genbankReader",pwd:"123456",roles:["read"]})
{
        "user" : "genbankReader",
        "pwd" : "6f755264f6d28045198f6ae53523005e",
        "roles" : [
                "read"
        ],
        "_id" : ObjectId("52dcb8495ec4b673f09b66eb")
}
Mon Jan 20 13:46:49.007 couldn't add user: not authorized for insert on genbank.system.users at src/mongo/shell/db.js:128

但是对于数据库管理员,我可以根据需要执行 addUser():

mongos> use admin
switched to db admin
mongos> db.addUser({user:"adminReader",pwd:"123456",roles:["read"]})
{
        "user" : "adminReader",
        "pwd" : "60c67cf3181b8b8570583ddfb62dd32e",
        "roles" : [
                "read"
        ],
        "_id" : ObjectId("52dcb8b25ec4b673f09b66ec")
}

真的很奇怪!

【问题讨论】:

    标签: mongodb authentication admin roles


    【解决方案1】:

    在我从

    更改 root 角色之后
    [  "clusterAdmin",  "userAdmin",  "readWriteAnyDatabase",  "dbAdmin",  "read" ]
    

    [ "clusterAdmin", "userAdminAnyDatabase",  "dbAdminAnyDatabase", "readWriteAnyDatabase" ]
    

    ,问题解决了!

    似乎问题来自角色类型“userAdmin”。来自mongodb doc,针对db admin的用户管理员角色与userAdminAnyDatabase相同:

    Note The userAdmin role is a database-specific privilege, and only grants a user the ability to administer users on a single database. However, for the admin database, userAdmin **allows a user the ability to gain userAdminAnyDatabase**. Thus, for the admin database only, these roles are effectively the same.
    

    因此,针对数据库管理员的角色类型 userAdmin 并不能直接为我们提供管理其他 dbs 上的用户的能力,但该角色下的用户可以创建另一个角色“userAdminAnyDatabase”,并且只有在此角色下用户才能管理其他 db 的用户。

    【讨论】:

      猜你喜欢
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 2016-03-14
      • 2016-03-05
      • 2019-05-09
      • 2016-09-27
      • 2015-11-13
      相关资源
      最近更新 更多