Reputation: 1121
I have a mongodb sharded cluster, with mongos machines, mongo nodes in replicate sets and config servers. MongoDB version is 3.02
The guy that set this up left the company a while ago and now I cant do simple things like show dbs or show collections
I have OS root in all these Debian machines, so I want to know how to reset mongo's root password so I can admin the database.
The apps that access this db seem to be working fine, using a user that has low privileges. I know the password for this particular user.
This is a production setup, so I can't afford to keep it down for more than a few seconds, tops minutes.
Upvotes: 14
Views: 54364
Reputation: 6506
/etc/
folder using: sudo nano mongod.conf
# security:
# authorization: enabled
sudo service mongod stop
sudo service mongod start
db.createUser({ user:"admin", pwd:"password", roles:[{role:"root", db:"admin"}] });
systemctl --type=service --state=active
. If it has started, it will be in the list as mongod.service
./var/log/mongodb/mongodb.log
but this is less likely to be helpful in this situation.Upvotes: 2
Reputation: 191
It depends on the types of users. For example, if you are using SCRAM, the basic steps to reset password would be:
Upvotes: 14
Reputation: 4425
There are two options here
If you plan to upgrade to 3.4 this can be done without downtime:
--transitionToAuth
(This will allow both authenticated and non-authenticated traffic for some duration)If you need to do this with existing MongoDB without upgrade:
keyFile
optionsUpvotes: 2
Reputation: 7480
I think this may work:
https://dba.stackexchange.com/questions/62976/how-can-i-enter-mongo-as-a-superuser-or-reset-users
Upvotes: 8
Reputation: 1580
This may not be the perfect answer, because I cannot test it. The base problem is of course that, that you cannot put your system into maintenance mode, where you can change admin password... But there is config file parameter security.transitionToAuth what you can add with rolling matter to your config file(s).
A mongod or mongos running with security.transitionToAuth
does not enforce user access controls. Users may connect to your deployment without any access control checks and perform read, write, and administrative operations.
Upvotes: 1