MongoDB Atlas - Ruby connection not working inside Kubernetes

8/14/2019

I have a Ruby script that connects to MongoDB Atlas for getting some data. It does work perfectly if I:

  1. Run the script locally
  2. Run the script locally with docker
  3. Run the script in a separated AWS EC2 Instance
  4. Run the script in docker inside a seperated AWS EC2 instance
  5. Run the script inside local cluster with minikube.

However it doesn't work inside kubernetes, I am using EKS.

I have tried all items listed before and make sure the user exists on MongoDB Atlas.

This is pretty much the output that I receive:

User moon (mechanism: scram) is not authorized to access test (used mechanism: SCRAM-SHA-1) (Mongo::Auth::Unauthorized)

I'd appreciate any input.

-- xorb
aws-eks
eks
kubernetes
mongodb
ruby

2 Answers

8/16/2019

What i have found:

It looks like users permissions miss configuration:

As per documentation: Create a MongoDB User for Your Cluster.

You must create a MongoDB user to access your deployment. For security purposes, Atlas requires clients to authenticate as MongoDB users to access clusters.

MongoDB users are separate from Atlas users:

MongoDB users can access databases hosted in Atlas. Atlas users can log into Atlas but do not have access to MongoDB databases.

Hope this help.

-- Hanx
Source: StackOverflow

10/28/2019

Solved by adding &authSource=admin to the connection string.

-- xorb
Source: StackOverflow