huggingface/Mongoku

Unable to add an auth enabled server

shreyasnagare opened this issue · 7 comments

When I start mongoku, I get the following output (error).

[Mongoku] Starting...
[localhost:27017] Connected to localhost:27017
[Mongoku] listening on port 3100
(node:7634) UnhandledPromiseRejectionWarning: MongoError: command listDatabases requires authentication
    at Connection.<anonymous> (/home/bd/node_modules/mongodb-core/lib/connection/pool.js:443:61)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at processMessage (/home/bd/node_modules/mongodb-core/lib/connection/connection.js:364:10)
    at Socket.<anonymous> (/home/bd/node_modules/mongodb-core/lib/connection/connection.js:533:15)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)hen I 
    at Socket.Readable.push (_stream_readable.js:208:10)
(node:7634) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7634) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

As mongoku doesn't have the auth details, I tried to add the server using the GUI. I noticed that the add server input field was not editable.

n1t0 commented

Hi @shreyasnagare, I just published a new version that should fix this problem. You can update with npm update -g mongoku

You may have to use an address of the form user:password@localhost:27017/admin if admin is the database used for authentication.

Let me know if it worked!

I added the /admin too but it doesn't seem to work. I also tried restarting mongoku after that but it did not work.

[Mongoku] Starting...
[127.0.0.1:27017] Connected to 127.0.0.1:27017
[localhost:27017] Connected to localhost:27017
{ MongoError: command listDatabases requires authentication
    at Connection.<anonymous> (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/pool.js:443:61)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at processMessage (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/connection.js:364:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/connection.js:533:15)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
  ok: 0,
  errmsg: 'command listDatabases requires authentication',
  code: 13,
  codeName: 'Unauthorized',
  name: 'MongoError',
  [Symbol(mongoErrorContextSymbol)]: {} }
[localhost:27017] Connected to localhost:27017
{ MongoError: not authorized on config to execute command { collStats: "system.sessions", lsid: { id: UUID("14ab5210-c8be-4718-9eac-e98c6ed86bad") }, $db: "config" }
    at Connection.<anonymous> (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/pool.js:443:61)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at processMessage (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/connection.js:364:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/connection.js:533:15)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
  ok: 0,
  errmsg: 'not authorized on config to execute command { collStats: "system.sessions", lsid: { id: UUID("14ab5210-c8be-4718-9eac-e98c6ed86bad") }, $db: "config" }',
  code: 13,
  codeName: 'Unauthorized',
  name: 'MongoError',
  [Symbol(mongoErrorContextSymbol)]: {} }
{ MongoError: not authorized on config to execute command { collStats: "system.sessions", lsid: { id: UUID("ce564454-10cc-496c-814e-31a6503fff30") }, $db: "config" }
    at Connection.<anonymous> (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/pool.js:443:61)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at processMessage (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/connection.js:364:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/mongoku/node_modules/mongodb-core/lib/connection/connection.js:533:15)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
  ok: 0,
  errmsg: 'not authorized on config to execute command { collStats: "system.sessions", lsid: { id: UUID("ce564454-10cc-496c-814e-31a6503fff30") }, $db: "config" }',
  code: 13,
  codeName: 'Unauthorized',
  name: 'MongoError',
  [Symbol(mongoErrorContextSymbol)]: {} }
[Mongoku] listening on port 3100
n1t0 commented

Did you first remove the old entry for localhost before adding the new one? Can you provide me with the information about the roles your user currently has on mongodb? I will need to investigate further.

Yes, I did remove the old entry before adding a new one. About the roles... I get [ ] when I do db.getRoles() or db.getUsers() (MongoDB shell) but this doesn't seem to be a problem for other apps. Is there a way to specify authentication source in mongoku?

This is how I connect to the DB via command line:

mongo admin -u MONGODB_USERNAME -p MONGODB_PWD

This is how I connect other apps to the same db:

mongoengine.connect(db = app.config['MONGODB_DATABASE'],
            host = app.config['MONGODB_HOST'],
            port = app.config['MONGODB_PORT'],
            username = app.config['MONGODB_USERNAME'],
            password = app.config['MONGODB_PWD'],
            authentication_source = 'admin')
n1t0 commented

In order to list users you have to actually be using the admin database in the shell, and also your user should probably have the relevant role for this. If you are on any other database, it just gives you an empty array.

On my side it seems to work even with readWrite permission on only one database, using the following address user:pwd@localhost:27017. It shows me only the database I have access to. So I guess you are maybe using an older version of MongoDB which does not let you list the databases if you don't have access to every of them on the server. Do you know the version number of your mongodb server?

Maybe you can try modifying the .mongoku.db file, located in your user's home directory and use an address like that: user:pwd@localhost:27017/database?authSource=admin (Mongoku won't let you enter this directly in the input). Then restart it.

If you still get the command listDatabases requires authentication error, I am afraid you won't be able to use Mongoku with your current permissions.

n1t0 commented

This should be fixed with the new release

It worked! Thanks.