繁体   English   中英

Mongodb集群:可以查询普通集合,但不能查询system.users

[英]Mongodb cluster:can query on normal collections ,but not on system.users

我使用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")
}

真是奇怪!

在我更改根角色后

[  "clusterAdmin",  "userAdmin",  "readWriteAnyDatabase",  "dbAdmin",  "read" ]

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

,问题解决了!

看来问题出在角色类型“ userAdmin”。从mongodb doc ,针对db admin的user 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.

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM