Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-714

Work around localhost exception issues in add_user when connected to MongoDB >= 2.7.1

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 2.7.2, 3.0
    • None
    • None

    Description

      Starting with MongoDB 2.7.1 the scope of the localhost exception for authentication was dramatically narrowed. It is no longer possible to call the userInfo command unauthenticated, even when the localhost exception is in effect.

      >>> c = pymongo.MongoClient()
      >>> try:
      ...     c.admin.add_user('admin', 'pass', roles=['root'])
      ... except Exception as exc:
      ...     print exc.details
      ... 
      {u'code': 13, u'ok': 0.0, u'errmsg': u'not authorized on admin to execute command { usersInfo: "admin" }'}
      >>> 
      >>> c.admin.command('createUser', 'admin', pwd='pass', roles=['root'])
      {u'ok': 1.0}
      >>> c.admin.authenticate('admin', 'pass')
      True
      >>> c.server_info()['version']
      u'2.7.2'

      A workaround for this issue is to catch the exception and call createUser if the error code is 13 (Unauthorized). Any exception from the createUser call should propagate to the user application.

      Attachments

        Issue Links

          Activity

            People

              luke.lovett Luke Lovett
              bernie@mongodb.com Bernie Hackett
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: