1
votes

So we are having an interesting problem. We wanted to add authentication at the MongoDB Layer for more security. But we not getting a favorable outcome.

Pre-Setup

  1. Use mongo shell (against admin table) as root
  2. Switch to desired database (applicationdb)
  3. Execute db.createUser()
  4. Validate user was created successfully

    { "_id" : "applicationdb.appuser", "user" : "appuser", "db" : "applicationdb", "roles" : [ { "role" : "readWrite", "db" : "applicationdb" } ] }

Scenario 1:

  1. Change mongodb.conf, auth=true
  2. Restart the Mongod service
  3. Connect mongoose using:

    mongoose.connect('mongodb://appuser:[email protected]:27017/applicationdb');

  4. No errors received for connect, so try to perform a GET through Mongoose causes the operation to timeout without any error (at least that I could find)

Scenario 2:

  1. Change mongodb.conf, auth=false
  2. Restart the Mongod service
  3. Connect mongoose using:

    mongoose.connect('mongodb://xx.xxx.xxx.xxx:27017/applicationdb');

  4. No errors received for connect, so try to perform a GET through Mongoose and it returns documents successfully

Why do we get this timeout and never a completed request when using authentication in MongoDB?

Any help would be great, we're at a loss on this one!

1
Can you add the mongoose connect code, the options you have set.virattara
@virattara, the code used is directly under step 3 in each scenario.Kyle

1 Answers

1
votes

You need to restart the mongo service with the --auth option see here

If it doesn't works do this: Try setting server options in mongoose with keepAlive set. See here and here.