Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My read-only user is able to write

Tags:

mongodb

I'm using MongoDB 3.0.7. I have a database called bravegoat and a read-only user called bravegoat-r.

I connect via shell:

mongo localhost:27017/bravegoat -u bravegoat-r -p mypassword

I switch to my database:

use bravegoat;

And I run:

db.runCommand({connectionStatus : 1})

Which outputs:

{
        "authInfo" : {
                "authenticatedUsers" : [
                        {
                                "user" : "bravegoat-r",
                                "db" : "bravegoat"
                        }
                ],
                "authenticatedUserRoles" : [
                        {
                                "role" : "read",
                                "db" : "bravegoat"
                        }
                ]
        },
        "ok" : 1
}

Only read role, so it looks fine, but when I invoke .save(), my user can insert data. I've read few pages about creating read-only users and I'm not able to see my problem. I'm starting to think it might be a bug in my version.

like image 388
Oriol del Rio Avatar asked Nov 10 '22 00:11

Oriol del Rio


1 Answers

You have to enable client access control by doing the following:

  1. Edit the /etc/mongod.conf file
  2. Add the following lines

security: authorization: enabled

  1. Restart MongoDB:

sudo service mongodb restart

like image 161
Michaël Perrin Avatar answered Nov 15 '22 13:11

Michaël Perrin