MongoDB 2.4 Replica with authorization

How to configure the correct authorization for mongodb 2.4.1. My setup doesn't seem to work. Replica Member Configuration:

dbpath = /vol/data/mongodb/ # logfile logpath = /var/log/mongodb/mongodb.log logappend = true # socket bind_ip = 0.0.0.0 port = 27018 # replication replSet = <%= hostname[14,4] %> # authentication keyFile = /etc/mongodb.pass # turn off legacy privilege mode setParameter = supportCompatibilityFormPrivilegeDocuments=false setParameter = textSearchEnabled=false # turn off authorization auth = true 

After adding user authorization:

 > use admin > db.addUser( { user: "admin", pwd: "xxx", roles: [ "userAdminAnyDatabase", "readWriteAnyDatabase", "dbAdminAnyDatabase" ] } ) 

I cannot access rs commands. *.

 > use admin > db.auth('admin','xxx') 1 > rs.status() { "ok" : 0, "errmsg" : "unauthorized" } 
+4
source share
2 answers

I think you need to use keyFile if you have a replicaset.

Taken from http://docs.mongodb.org/manual/tutorial/enable-authentication/ :

Enable authentication using auth or keyFile options. Use auth for standalone instances, and keyFile with replica sets and clustered clusters. keyFile implies auth and allows members of the MongoDB deployment to authenticate internally.

+1
source

I also had the same problem. I have a solution for this.

Disable auth

1.Create a root user

Root privilege yields readWrite access to database while userAdminAnyDatabase role doesn't.

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

Enable auth

2. Log in as root

 mongo -u root --authenticationDatabase admin -p 

Then you can execute your commands.

Hope this helps :)

0
source

All Articles