dokku / dokku-mongo

a mongo plugin for dokku
MIT License
177 stars 32 forks source link

Connecting to mongo from outside dokku #39

Closed nickboucart closed 8 years ago

nickboucart commented 9 years ago

Hi,

I'm trying to connect to a mongo service from outside of dokku (e.g. my development macbook). I understand that I need to issue dokku mongo:expose but I can't seem to connect...

I use robomongo to connect, I have setup ssh tunnel to the machine dokku is running on, but I can't access the database. I use localhost as my host, one of the ports I received from mongo:expose as port, and I'm authenticating with the "admin" database with and as credentials. Robomongo says it can connect but cannot authenticate...

Any suggestions?

Thanks! Nick.

josegonzalez commented 9 years ago

Where did you get the credentials? The admin user has a root password we don't expose publicly, so you might just be using the service's password.

nickboucart commented 9 years ago

I was using the service username and password. I took those from the result of dokku mongo:info.

josegonzalez commented 9 years ago

Right, I think you need the admin credentials instead, there is a ROOTPASSWORD file for each service, might want to try those?

nickboucart commented 9 years ago

I will try it out later today... I did find some things about robomongo not being able to connect to mongo 3.x, so it might be an issue there.

Thanks for your fast response! Nick

silverbux commented 9 years ago

hi guys, i was having same issue... im just wondering where can i get the ROOTPASSWORD ? or are you referring to the actual "ROOTPASS" of the server?

josegonzalez commented 9 years ago

It's in something like /var/lib/dokku/services/mongo/SERVICE/ROOTPASSWORD.

Flink commented 9 years ago

For services using a root password, we could display it when using the info command

silverbux commented 9 years ago

still no luck, im on digitalocean server connecting via robomongo, already tried the following:

1.) connect with username root / ROOTPASSWORD 2.) connect with username admin / ROOTPASSWORD 3.) the credentials given from dokku mongo:info dbname 4.) connect using ssh tunnel

i managed to connect with the server with ssh tunnel but always end up having "authorization failed"

Flink commented 9 years ago

@silverbux That’s strange, you should be able to connect to mongo. Does the mongo:connect command work? I know I had issues with errbit and mongo 3.x but that’s because of the mongoid driver (IIRC) not handling correctly auth with mongo 3.x. Using mongo 2.6.x works without any problem. Could you try maybe with a 2.6.x version of mongo?

silverbux commented 8 years ago

@Flink your correct the problem was the version 3.x, i switched to version 2.6.11 and it works. Thanks! ^^

josegonzalez commented 8 years ago

Closing as this is a client issue, not one with our plugin.

malixsys commented 8 years ago

@silverbux what where you settings finally in Robomongo?

silverbux commented 8 years ago

@malixsys with SSH tunnel, dont forget to use the port that dokku exposed.

malixsys commented 8 years ago

@silverbux so you mongo:expose, take the 1st port , connect with robomongo to localhost:port with ssh through root@YOUR_DROPLET_IP with auth admin:ROOTPASSWORD@admin? Cause I get unauthorized...

silverbux commented 8 years ago

for some reason the "localhost" doesnt work for me too, i used public ip instead. regarding your ssh tunnel settings, just use your regular ssh settings. this might help.

http://codehyper.com/installing-mongodb-to-dokku-and-fixing-remote-access-issue/

malixsys commented 8 years ago

Oh! OK! Would you mind telling me what you have in each tab of your robomongo? You can of course paraphrase any sensitive info like MY_DROPLET_IP

silverbux commented 8 years ago

yep sure thing, here you go

Connection tab
    name: dokkuserver
    address: <MY_DROPLET_IP>
    port: 12571

Authentication tab
    database: <DATABASE_NAME>
    username: <DATABASE_USERNAME>
    pass: <DATABASE_PASSWORD>

SSH tab
    [x] Use SSH tunnel ( checked )
    SSH address: <MY_DROPLET_IP>
    port: 22
    username: <SSH_USERNAME>
    ssh auth method: password
    password: <SSH_PASSWORD>
malixsys commented 8 years ago

Super! And the Auth tab info comes from mongo:info right?

On Jan 20, 2016, 02:23 -0500, Alex Quiambaonotifications@github.com, wrote:

yep sure thing, here you go

Connection tab name: dokkuserver address:port: 12571 Authentication tab database:username:pass:SSH tab [x] Use SSH tunnel ( checked ) SSH address:port: 22 username:ssh auth method: password password:

— Reply to this email directly orview it on GitHub(https://github.com/dokku/dokku-mongo/issues/39#issuecomment-173116938).

silverbux commented 8 years ago

@malixsys yep correct

malixsys commented 8 years ago

It doesn't work for me because of this: http://stackoverflow.com/a/31476552/856468

@josegonzalez can we have a setting when using mongo:create to do a db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 }) ?

malixsys commented 8 years ago

@silverbux @josegonzalez I added a PR but until then:

cat /var/lib/dokku/services/mongo/YOUR_SERVICE/ROOTPASSWORD
dokku mongo:connect YOUR_SERVICE
use admin
db.auth('admin', ROOTPASSWORD)
db.runCommand({ grantRolesToUser: "admin", roles: [ "__system", "root", "userAdminAnyDatabase",
                                                                     "dbAdminAnyDatabase",
                                                                     "readWriteAnyDatabase"] })
schema.currentVersion = 3
var schema = db.system.version.findOne({"_id" : "authSchema"})
db.system.version.save(schema)
exit
dokku mongo:restart YOUR_SERVICE```
then reconnect and
```db.createUser( { user: "someUser", pwd: "some_secret_passw0rdz", roles: [ { role: "dbOwner", db: "YOUR_SERVICE" } ] });```