Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
MongoDB user authorization - how-to #1168
Configuring MONGO_* settings with user authorization should not raise an error if the database does not exist.
First step, configure mongodb
I set-up a recent mongodb instance locally and I create an administrator user:
I configure mongo in authorization mode and restart the server:
As of now, I always need to authenticate for any operation on the databases
Second step, configure my REST Eve backend:
My configuration file MONGO part
Note: it is a JSON file that is transformed to a python dict...
Tell us what happens instead.
MongoDB connection string: mongodb://alignak:alignak@localhost:27017/admin Traceback (most recent call last): File "/usr/local/bin/alignak-backend", line 9, in <module> load_entry_point('alignak-backend==1.4.11', 'console_scripts', 'alignak-backend')() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2569, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load return self.resolve() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2235, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/usr/local/lib/python2.7/dist-packages/alignak_backend/main.py", line 8, in <module> from alignak_backend.app import app, manifest File "/usr/local/lib/python2.7/dist-packages/alignak_backend/app.py", line 2158, in <module> static_folder=base_path File "/usr/local/lib/python2.7/dist-packages/eve/flaskapp.py", line 176, in __init__ self.register_resource(resource, settings) File "/usr/local/lib/python2.7/dist-packages/eve/flaskapp.py", line 922, in register_resource create_index(self, resource, name, list_of_keys, index_options) File "/usr/local/lib/python2.7/dist-packages/eve/io/mongo/mongo.py", line 969, in create_index db = app.data.pymongo(resource, px).db File "/usr/local/lib/python2.7/dist-packages/eve/io/mongo/mongo.py", line 893, in pymongo self.driver[px] = PyMongo(self.app, px) File "/usr/local/lib/python2.7/dist-packages/flask_pymongo/__init__.py", line 97, in __init__ self.init_app(app, config_prefix) File "/usr/local/lib/python2.7/dist-packages/flask_pymongo/__init__.py", line 283, in init_app mechanism=auth_mechanism) File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 1274, in authenticate connect=True) File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 614, in _cache_credentials sock_info.authenticate(credentials) File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 688, in authenticate auth.authenticate(credentials, self) File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 542, in authenticate auth_func(credentials, sock_info) File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 245, in _authenticate_scram res = sock_info.command(source, cmd) File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 579, in command unacknowledged=unacknowledged) File "/usr/local/lib/python2.7/dist-packages/pymongo/network.py", line 150, in command parse_write_concern_error=parse_write_concern_error) File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line 155, in _check_command_response raise OperationFailure(msg % errmsg, code, response) pymongo.errors.OperationFailure: Authentication failed.
It looks like Eve do not consider the authorization parameters I provided to create the database!
I tried almost every parameters combination, with or whitout
Perharps I did something not correctly ... but what I expect is that Eve manages the DB creation by itself
I'm experiencing the same issue. I have Eve connected to a mongodb replica set, and that was working up until I enabled auth. Now when I altered my URI to include username and password, I get that exact same error. I have tried the exact URI that I give to eve directly on Mongo and it works properly:
Just for kicks, I also tried creating a MongoClient object with the same URI, and it was able to succesfully connect to Mongo, so I think the problem is with eve.
After much struggle, and making use of several options not mentioned directly in the documents, I managed to get it to work, using the following options:
And making absolutely sure that
Part of the problem was that the application error was always the same "Authentication Failed", but when I would look at the response.json() from the request I had made, it would have a more informative failure message.
I am having the same issue. Trying to use the mongo_srv protocol with eve. I can manually connect to pymongo in my Eve app but I get the same "Authentication Failed' error.
Does that mean I can't currently use the mongo+srv protocol with Eve?
@nicolaiarocci Testet now,
I don't use the
I only read the Quickstart docs so it would be nice if it was reflected there since it has an example with