Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, May 4, 2016

MongoDB - admin user not authorized

MongoDB - admin user not authorized


I am trying to add authorization to my MongoDB.
I am doing all this on Linux with MongoDB 2.6.1.
My mongod.conf file is in the old compatibility format
(this is how it came with the installation).

1) I created admin user as described here in (3)

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

2) I then edited mongod.conf by uncommenting this line

auth = true

3) Finally I rebooted the mongod service and I tried to login with:

/usr/bin/mongo localhost:27017/admin -u sa -p pwd

4) I can connect but it says this upon connect.

MongoDB shell version: 2.6.1  connecting to: localhost:27017/admin  Welcome to the MongoDB shell!  The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)  Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }  

5) Now it seems this sa user I created has no permissions at all.

root@test02:~# mc  MongoDB shell version: 2.6.1  connecting to: localhost:27017/admin  Welcome to the MongoDB shell!  The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)  Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }  [admin] 2014-05-29 17:57:03.011 >>> use admin  switched to db admin  [admin] 2014-05-29 17:57:07.889 >>> show collections  2014-05-29T17:57:10.377-0400 error: {          "$err" : "not authorized for query on admin.system.namespaces",          "code" : 13  } at src/mongo/shell/query.js:131  [admin] 2014-05-29 17:57:10.378 >>> use test  switched to db test  [test] 2014-05-29 17:57:13.466 >>> show collections  2014-05-29T17:57:15.930-0400 error: {          "$err" : "not authorized for query on test.system.namespaces",          "code" : 13  } at src/mongo/shell/query.js:131  [test] 2014-05-29 17:57:15.931 >>>  

What is the problem? I repeated this whole procedure 3 times and
I think I did it all as specified in the MongoDB docs. But it doesn't work.
I was expecting this sa user to be authorized to do anything so that
he can then create other users and give them more specific permissions.

Answer by John Petrone for MongoDB - admin user not authorized


It's a bit confusing - I believe you will need to grant yourself readWrite to query a database. A user with dbadmin or useradmin can admin the database (including granting yourself additional rights) but cannot perform queries or write data.

so grant yourself readWrite and you should be fine -

http://docs.mongodb.org/manual/reference/built-in-roles/#readWrite

Answer by s-hunter for MongoDB - admin user not authorized


I was also scratching my head around the same issue, and everything worked after I set the role to be root when adding the first admin user.

use admin  db.createUser(    {      user: "admin",      pwd: "password",      roles: [ { role: "root", db: "admin" } ]    }  );  exit;   

For a complete authentication setting reference, see the steps I've compiled after hours of research over the internet.

Answer by ibirite for MongoDB - admin user not authorized


I had a similar problem here on a Windows environment: I have installed Bitnami DreamFactory and it also installs another MongoDb that is started on system boot. I was running my MongoDbService (that was started without any error) but I noticed after losing a lot of time that I was in fact connecting on Bitnami's MongoDb Service. Please, take a look if there is not another instance of mongoDB running on your server.

Good Luck!

Answer by Buminda for MongoDB - admin user not authorized


This may be because you havent set noAuth=true in mongodb.conf

# Turn on/off security.  Off is currently the default  noauth = true  #auth = true  

After setting this restart the service using

service mongod restart

Answer by Bart C for MongoDB - admin user not authorized


Perhaps a quick example of how to change a current user will be helpful to somebody. This is what I was actually looking for.

Following advice of @JohnPetrone I added readWrite role to my admin user with grantRolesToUser

> use admin  > db.grantRolesToUser("admin",["readWrite"])  > show collections  system.users  system.version  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.