ptpb / pb

pb is a formerly-lightweight pastebin and url shortener
Other
549 stars 52 forks source link

not authorized on pb to execute command #131

Closed tristan-k closed 8 years ago

tristan-k commented 8 years ago

Running $ ./runonce.py admin mongodb://tristank_mongoadmin:XXXXXX@localhost:20705 gives me an error. Also see Issue https://github.com/ptpb/pb/issues/130

 Traceback (most recent call last):
   File "./runonce.py", line 56, in <module>
     main(**vars(ns))
   File "./runonce.py", line 42, in main
     func(db)
   File "./runonce.py", line 35, in _admin
     add_config_user(db)
   File "./runonce.py", line 26, in add_config_user
     db.client.admin.add_user(*auth, roles=[{'role': 'readWrite', 'db': config['MONGO_DATABASE']}])
   File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/database.py", line 854, in add_user
     "instance of %s" % (string_type.__name__,))
 TypeError: name must be an instance of str

So I tried to manually add the database with:

$ mongo admin --port 20705 -u tristank_mongoadmin -p
> use pb
> db.collection.createIndex({ digest: 1}, { unique: true });
> db.collection.createIndex({ date: 1});
> db.collection.createIndex({ label: 1}, { unique: true }, { sparse: true });
> db.collection.createIndex({ private: 1}, { sparse: true });
> exit

I then started pb with

$ ./run.py
 * Running on http://[::]:61111/ (Press CTRL+C to quit)
 * Running on http://[::]:61111/ (Press CTRL+C to quit)
::ffff:77.181.169.36 - - [05/Oct/2015 01:17:03] "GET /favicon.ico HTTP/1.1" 404 -
[2015-10-05 01:17:28,267] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/home/tristank/venv/pbenv/src/flask/flask/app.py", line 1957, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tristank/venv/pbenv/src/flask/flask/app.py", line 1610, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/tristank/venv/pbenv/src/flask/flask/app.py", line 1513, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tristank/venv/pbenv/src/flask/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/tristank/venv/pbenv/src/flask/flask/app.py", line 1608, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/tristank/venv/pbenv/src/flask/flask/app.py", line 1594, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/virtual/tristank/html/pb-mongodb/pb/paste/views.py", line 67, in post
    if not cur.count():
  File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/cursor.py", line 674, in count
    return self.__collection._count(cmd)
  File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/collection.py", line 987, in _count
    allowable_errors=["ns missing"])
  File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/collection.py", line 191, in _command
    allowable_errors)
  File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/pool.py", line 184, in command
    codec_options, check, allowable_errors)
  File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/network.py", line 54, in command
    helpers._check_command_response(response_doc, msg, allowable_errors)
  File "/home/tristank/venv/pbenv/lib/python3.4/site-packages/pymongo/helpers.py", line 188, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: command SON([('count', 'pastes'), ('query', {'digest': '7cc0b176cd96d745ff8c652bd263aa57f7b35d6a'})]) on namespace pb.$cmd failed: not authorized on pb to execute command { count: "pastes", query: { digest: "7cc0b176cd96d745ff8c652bd263aa57f7b35d6a" } }
::ffff:77.181.169.36 - - [05/Oct/2015 01:17:28] "POST / HTTP/1.1" 500 -

Which gives me another error after trying to a add paste with the html formular.

Have a look at http://paste.tristank.de/

buhman commented 8 years ago

So I tried to manually add the database with:

This only adds indexes; the user provided in your configuration (if any) clearly doesn't have access to the pb database.

TypeError: name must be an instance of str

Show me your config. Hint: the host: thing should look just like mongodb://tristank_mongoadmin:XXXXXX@localhost:20705 only with some arbitrary set of new credentials that you want to be created, like 'pbuser:foopassword`.