Creating single user with readWrite permissions on multiple databases

207 views
Skip to first unread message

jpbla...@gmail.com

unread,
Dec 4, 2017, 6:20:45 PM12/4/17
to mongodb-user
I have an application that needs to be able to access multiple databases, with readWrite permissions.  In keeping with the principle of least access, it should not have further access beyond that.  It appears that this should be possible by adding roles like so, with one for each database, changing the value of the db field:

{
   
"role": "readWrite",
    "db": "some_db"
}

What I'm stuck on is where that user should get created.  It seems like it should be created in the admin database, and then when my app connects it uses authSource=admin.  But I want to be sure that creating the user in the admin database doesn't grant actual admin access, to the admin database or otherwise.  From what I can tell, creating a user "in" a database, like this...

use admin
db
.createUser({ user: "my_user", pwd: "my_pwd", roles: [{"role": "readWrite", "db": "my_db"}] });

...does not imply any permissions for the database where the user is created (in this case, admin), but I haven't seen anywhere in the documentation that says so explicitly and unambiguously.

jpbla...@gmail.com

unread,
Dec 12, 2017, 4:10:27 PM12/12/17
to mongodb-user
I spoke with a representative from Mongo and confirmed that my assumptions are correct.

Wan Bachtiar

unread,
Dec 15, 2017, 1:20:48 AM12/15/17
to mongodb-user

does not imply any permissions for the database where the user is created (in this case, admin)

Hi,

This is referred to as the authentication database, the user’s name and authentication database serve as a unique identifier for that user.

This is not to be confused with granting permissions to users. See also Authorisation / Role-Based Access Control

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages