stimms
stimms

Reputation: 44046

Jump box to MongoDB Atlas with VPC Peering

I have a Mongodb Atlas database which is set up with VPC peering to a VPC in AWS. This works find and I'm able to access it from inside the VPC. I was, however, hoping to provide a jumpbox so that developers could use an SSH tunnel to connect to the Atlas database from their workstations outside of the VPC.

Developer workstation --> SSH Tunnel to box in VPC --> Atlas

I'm having trouble with that, however because I'm not sure what tunnel I need to set up. It looks to me like Mongo connects by looking up replica information in a DNS seed list (mongodb+srv://). So it isn't as simple as doing

ssh user@jumpbox -L 27017:env.somehost.mongodb.net:27017

Is there a way to enable direct connections on Atlas so that I can enable developers to access this database through an SSH tunnel?

Upvotes: 1

Views: 744

Answers (1)

D. SM
D. SM

Reputation: 14480

For a replica set connection this isn't going to work with just MongoDB and a driver, but you can try running a proxy like https://github.com/coinbase/mongobetween on the jumpbox.

For standalone deployments you can connect through tunnels since the driver uses the address you supply and that's the end of it. Use directConnection URI option to force a standalone connection to a node of any deployment. While this allows you to connect to any node, you have to connect to the right node for replica sets (you can't write to secondaries) so this approach has limited utility for replica set deployments.

For mongos deployments that are not on Atlas the standalone behavior applies. With Atlas there are SRV records published which the driver follows, therefore for the tunneling purposes an Atlas sharded cluster behaves like a replica set and you can't trivially proxy connections to it. mongobetween may also work in this case.

Upvotes: 1

Related Questions