Scenario: Installed MongoDB 2.2.3 on the machine (Windows 64-bit)
Followed all the steps to enforce authentication on MongoDB server.
Added User to admin database
use admin db.addUser('me_admin', '12345'); db.auth('me_admin','12345');
Ran database server (mongod.exe process) with the
--auth
option to enable authentication
Followed all answers for similar question: How to secure MongoDB with username and password
Issue: With new version 2.2.3 I am not able set up authentication. After following the same steps I was able to set up the authentication for the version 2.0.8 on the same machine. But its mentioned somewhere in MongoDB docs that "Authentication on Localhost varies slightly between before and after version 2.2"
Question: What is the change and how can enforce the authentication in new versions i.e. 2.2 onwards. Can anybody give some idea or solution to proceed the same with new MongoDB 2.2.3?
Update: I had checked that authentication works same on 2.2.3 when I start
mongod.exe
process with --auth
parameter from command prompt.
I was using auth=true
parameter in config file as mentioned in docs, but this did not work.
Research done:
When
mongod.cfg
file contains following configurationslogpath=c:\mongodb\log\mongo.log, auth=true, profile=2
The
log.txt
file contains following logsMon Mar 11 15:06:35 Trying to start Windows service 'MongoDB' Mon Mar 11 15:06:35 Service running Mon Mar 11 15:06:35 [initandlisten] MongoDB starting : pid=7152 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI Mon Mar 11 15:06:35 [initandlisten] db version v2.2.3, pdfile version 4.5 Mon Mar 11 15:06:35 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08 Mon Mar 11 15:06:35 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49 Mon Mar 11 15:06:35 [initandlisten] options: { config: "C:\mongodb\mongod.cfg", logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true } Mon Mar 11 15:06:35 [initandlisten] journal dir=/data/db/journal Mon Mar 11 15:06:35 [initandlisten] recover : no journal files present, no recovery needed Mon Mar 11 15:06:35 [initandlisten] waiting for connections on port 27017 Mon Mar 11 15:06:35 [websvr] admin web console waiting for connections on port 28017
When I run from command prompt
mongod --auth
, following log will be displayed:Mon Mar 11 15:09:40 [initandlisten] MongoDB starting : pid=6536 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI Mon Mar 11 15:09:40 [initandlisten] db version v2.2.3, pdfile version 4.5 Mon Mar 11 15:09:40 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08 Mon Mar 11 15:09:40 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49 Mon Mar 11 15:09:40 [initandlisten] options: { auth: true } Mon Mar 11 15:09:40 [initandlisten] journal dir=/data/db/journal Mon Mar 11 15:09:40 [initandlisten] recover : no journal files present, no recovery needed Mon Mar 11 15:09:40 [initandlisten] waiting for connections on port 27017 Mon Mar 11 15:09:40 [websvr] admin web console waiting for connections on port 28017
Note: The change in the options:
options:{ config: "C:\mongodb\mongod.cfg", logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true }
//Does not workoptions: { auth: true }
//Works
Interesting to observe is that,
When its ran from config file.
logpath=c:\mongodb\log\mongo.log, auth=true, profile=2
It got changed to:
logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true
I know here is the issue. It should be like:
logpath: "c:\mongodb\log\mongo.log", auth=true, profile="2", service: true
So, the question is how to pass auth=true
parameter from config file and run mongod.exe
process as service on Windows7