2

I have an issue with permissions in Mongodb

> use test
switched to db test
> db.createUser(
...   {
...     user: "tester",
...     pwd: "123456",
...     roles: [ { role: "readWrite", db: "test" },
...              { role: "read", db: "TestHPO" } ]
...   }
... );
Successfully added user: {
        "user" : "tester",
        "roles" : [
                {
                        "role" : "readWrite",
                        "db" : "test"
                },
                {
                        "role" : "read",
                        "db" : "TestHPO"
                }
        ]
}
> db.auth("tester", "123456" )
1
> use TestHPO
switched to db TestHPO
> db.createCollection("mycollection");
{ "ok" : 1 }

The test user has only read permission on TestHPO databases but can create and drop the collection in the above example.

This should be read-only which means just find, where is the issue with my code?

1

3 Answers 3

1

You are not using access control.

From https://docs.mongodb.com/manual/tutorial/enable-authentication/#re-start-the-mongodb-instance-with-access-control:

Re-start the mongod instance with the --auth command line option or, if using a configuration file, the security.authorization setting.

Sign up to request clarification or add additional context in comments.

Comments

0

Following Add Users - tutorial

Or

Another way.You should switch to database TestHPO and createUser again.

Comments

0

Update/create config file for mongo db with below auth properties: security: authorization: enabled setParameter: authenticationMechanisms: MONGODB-CR

Restart the mongodb with --auth & --config: mongod --auth --config C:\data\conf\mongod.conf

If the username or password contains a colon (:) or an at-sign (@) then it must be urlencoded otherwise throws exception.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.