Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to authenticate with remote MongoDB server #52

Closed
aaronfay opened this issue Sep 14, 2012 · 9 comments
Closed

Support to authenticate with remote MongoDB server #52

aaronfay opened this issue Sep 14, 2012 · 9 comments

Comments

@aaronfay
Copy link
Contributor

Currently the deployd setup is dependent on running a mongodb instance locally, but for some systems (like http://koding.com) the mongo server is remote. Please add support to optionally connect to a remote mongo server with authentication.

@dallonf
Copy link
Member

dallonf commented Sep 17, 2012

Only the dpd command line tool is dependent on creating a local mongodb instance. You can configure it to run with a different server in a custom script:

var deployd = require('deployd');
var server = deployd({ db: {  port: 27017, host: '127.0.0.1', name: 'deployd' } }); //still a local instance, just an example
server.listen();

Does this answer your question? I'm not sure if your concern is relating to a development environment or deployment.

@aaronfay
Copy link
Contributor Author

Thanks for that.

Specifically related to koding.com, the remote connection requires authentication, for which changes needed to be made in db.js in Db.prototype.open. It's one thing to connect to a remote server, but the current implementation of that method doesn't make any allowance for username and password against the db.authenticate method.

I've updated the issue title to correctly reflect the issue.

@jeffbcross
Copy link
Member

@aaronfay out of curiosity, is there a hosted service you use, or do you self-host MongoDB instances? Or does koding.com provide database services?

Managing remote deployments of application & db are a big focus for us right now, so this is a helpful use case to be aware of.

@aaronfay
Copy link
Contributor Author

Hi @jeffbcross, my case was against koding.com specifically, they offer "one-click" MongoDB setup where they expose the remote host/port and credentials to connect to the db.

The db.js could be wired to check for username property in the options in order to trigger authentication:

// lib/db.js ~ line 111

function getConnection(db, fn) {
  if(db.connected) {
    fn(null, db._mdb);
  } else if(db.connecting) {
    db.once('connection attempted', function (err) {
      fn(err, db._mdb)
    });
  } else {
    db.connecting = true;
    db._mdb.open(function (err) {
      console.log(db)
      db.connecting = false;
      db.emit('connection attempted', err);
      if(err) {
        db.connected = false;
        throw err;
      } else {
        db.connected = true;
        // check for credentials
        if (db.options.username && db.options.password) {
          db._mdb.authenticate(db.options.username, db.options.password, function (err) {
            if (err) {
              db.connected = false;
              throw err;
            }
            fn(null, db._mdb);
          });
        } else {
          fn(null, db._mdb);
        }
      }
    });
  }
}

Please note this code is untested, I just upgraded deployd on koding.com to the git/master instead of the version on npm as I noticed they are not in sync. Koding.com is now complaining about a dependency in the doh module, it appears I need to be running node v0.8+. I apologize for the lack of pull request, I don't have the means to test the above code this very instant, I hope the snipped above will help in that direction.

Also, I have some invites to Koding.com if you're interested.

Regards,
Aaron

@aaronfay
Copy link
Contributor Author

Hello,

I've submitted a pull request on #54 for your review that fixes this issue.

Thanks,
Aaron

@jeffbcross
Copy link
Member

I'd love to try out koding.com. Could you send an invite to hello@deployd.com?

@aaronfay
Copy link
Contributor Author

You should have the invite now :)

@jeffbcross
Copy link
Member

Awesome, I'm in, thanks.

ritch added a commit that referenced this issue Sep 21, 2012
Fixes #52 - authenticate with remote mongo server
@Orrico
Copy link

Orrico commented Mar 8, 2013

I'd like a invite to koding.com too... please? jonasorrico@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants