The following users were generated using Robomongo 0.8.5 connected to MongoDB 3.0.7.
The problems:
- With users generated in Robomongo it is not possible to log in through CLI.
- With users generated in CLI it is not possible to log in through Robomongo (with
auth=true
) - Robomongo does not log in with
auth=true
at all
When starting Robomongo I didn't perform any authentication, which may have resulted in having created those tables in unauthenticated mode.
While other questions are related to various other programming languages and JSON scripts, this schema is created by Robomongo itself and therefore it should be valid.
How can this have problem to authenticate the user in 3 different cases?
admin
Users
table, which defines admin
:
{
"_id" : ObjectId("56616c9c273eba0cc996edc5"),
"user" : "admin",
"pwd" : "90f500568434c37b61c8c1ce05fdf3ae",
"roles" : [
"readWrite",
"dbAdmin"
]
}
test_db
Users
table with admin
referenced from admin
:
{
"_id" : ObjectId("56616cb1273eba0cc996edc7"),
"user" : "admin",
"userSource" : "admin",
"roles" : [
"readWrite",
"dbAdmin"
]
}
direct_db
Users
table, which defines user
:
{
"_id" : ObjectId("56616edd273eba0cc996edcc"),
"user" : "user",
"pwd" : "3bcfc22a1cd6be41bc7814c13d3ce94c",
"roles" : [
"readWrite",
"dbAdmin"
]
}
Command line output:
> 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
Interestingly this CLI command works with and without auth=true
. I managed to be able to log in with auth=ture
, but only with setting { role: "readWrite", db: "root" }
, this line is important:
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