以下用户是使用连接到MongoDB 3.0.7的Robomongo 0.8.5生成的。
问题:
- 在 Robomongo 中生成的用户无法通过 CLI 登录。
- 在 CLI 中生成的用户无法通过 Robomongo 登录(使用
auth=true
) - Robomongo 根本无法
auth=true
登录
启动 Robomongo 时,我没有执行任何身份验证,这可能导致在未经身份验证的模式下创建了这些表。
虽然其他问题与各种其他编程语言和 JSON 脚本有关,但此模式是由 Robomongo 本身创建的,因此它应该是有效的。
在 3 种不同情况下对用户进行身份验证会有问题吗?
admin
Users
表,它定义admin
:
{
"_id" : ObjectId("56616c9c273eba0cc996edc5"),
"user" : "admin",
"pwd" : "90f500568434c37b61c8c1ce05fdf3ae",
"roles" : [
"readWrite",
"dbAdmin"
]
}
test_db
Users
admin
引用自的表admin
:
{
"_id" : ObjectId("56616cb1273eba0cc996edc7"),
"user" : "admin",
"userSource" : "admin",
"roles" : [
"readWrite",
"dbAdmin"
]
}
direct_db
Users
表,它定义user
:
{
"_id" : ObjectId("56616edd273eba0cc996edcc"),
"user" : "user",
"pwd" : "3bcfc22a1cd6be41bc7814c13d3ce94c",
"roles" : [
"readWrite",
"dbAdmin"
]
}
命令行输出:
> use admin;
switched to db admin
> db.auth( "admin", "password" );
Error: 18 Authentication failed.
0
> use test_db;
switched to db test_db
> db.auth( "admin", "password" );
Error: 18 Authentication failed.
0
> use direct_db;
switched to db direct_db
> db.auth( "user", "password" );
Error: 18 Authentication failed.
0
mongo.log
:
2015-12-04T12:26:09.665+0100 I NETWORK [initandlisten] connection accepted from 127.0.0.1:5140 #272 (53 connections now open)
2015-12-04T12:26:09.685+0100 I ACCESS [conn272] authenticate db: admin { authenticate: 1, nonce: "xxx", user: "admin", key: "xxx" }
2015-12-04T12:26:09.685+0100 I ACCESS [conn272] Failed to authenticate admin@admin with mechanism MONGODB-CR: AuthenticationFailed UserNotFound Could not find user admin@admin
有趣的是,这个 CLI 命令可以使用和不使用auth=true
. 我设法能够使用 登录auth=ture
,但只能使用 setting { role: "readWrite", db: "root" }
,这一行很重要:
mongo --authenticationDatabase db_name -u username -p password
>>>Connected to Mongo CLI client...<<<
> db.createUser(
{
"user" : "admin",
"pwd": "password",
"roles" : [
{ role: "readWrite", db: "root" },
{ role: "readWrite", db: "admin" },
{ role: "dbAdmin", db: "admin" },
{ role: "readWrite", db: "test_db" },
{ role: "dbAdmin", db: "test_db" }
]
})
>>>Successfully added user...<<<
> db.auth("admin","password")
1