mongodb – 无法为创建为“userAdminAnyDatabase”角色的用户访问其他dbs

在mongo 2.4.x中,它支持create user in admin database的新方法,
我以为用userAdminAnyDatabase角色创建的用户应该能够访问所有其他数据库吗?

db.addUser({user:"u", pwd:"p", roles:["userAdminAnyDatabase"]})

但是,它不能按照文档这样做.

当我创建2.2.x样式的用户时,它的工作原理.

db.addUser("u","p")

我的问题是我错误的操作?如果我想创建一个可以使用2.4.x语法访问所有dbs的用户,那么正确的方法是什么?还需要其他选择吗?

谢谢.

这是详细的shell代码:

➜  mgo ✗ mongo
MongoDB shell version: 2.4.5
connecting to: test
> use admin
switched to db admin
> db.addUser({user: "u", pwd: "p", roles:["userAdminAnyDatabase"]})
{
    "user" : "u",
    "pwd" : "d4198ee555320fa5c048da6d6da440d8",
    "roles" : [
        "userAdminAnyDatabase"
    ],
    "_id" : ObjectId("51dc20f0282f72950455b62e")
}
> db.auth(
Display all 170 possibilities? (y or n)
> db.auth("u","p")
1
> ^C
bye
➜  mgo ✗ mongo admin -u u -p p
MongoDB shell version: 2.4.5
connecting to: admin
> show dbs
Tue Jul  9 22:44:47.959 JavaScript execution failed: listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" } at src/mongo/shell/mongo.js:L46
> use admin
switched to db admin
> db.addUser("uncle", "peter")
{
    "user" : "uncle",
    "readOnly" : false,
    "pwd" : "e42842e07c4fc324e9724d6aa41f6411",
    "_id" : ObjectId("51dc22456642fa58413adffc")
}
> db.auth("uncle", "peter")
1
> ^C
bye
➜  mgo ✗ mongo admin -u uncle -p peter
MongoDB shell version: 2.4.5
connecting to: admin
> show dbs
admi    (empty)
admin   0.203125GB
local   0.078125GB
qortex_global   0.203125GB
qortexprod  0.203125GB
test    (empty)
>
userAdminAnyDatabase上的文档说(http://docs.mongodb.org/manual/reference/user-privileges/#userAdminAnyDatabase):

However, userAdminAnyDatabase and userAdmin do not explicitly
authorize a user for any privileges beyond user administration.

您还必须为list databases命令添加“clusterAdmin”角色:http://docs.mongodb.org/manual/reference/user-privileges/#clusterAdmin

如果您希望用户从数据库和集合中读/写,则需要添加另一个角色,即“readWrite”角色:http://docs.mongodb.org/manual/reference/user-privileges/#readWrite

翻译自:https://stackoverflow.com/questions/17551734/can-not-access-other-dbs-for-user-who-created-as-useradminanydatabase-role

转载注明原文:mongodb – 无法为创建为“userAdminAnyDatabase”角色的用户访问其他dbs