Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1528

Work around localhost exception issues in addUser helpers

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.13.0, 3.0.0
    • Affects Version/s: None
    • Component/s: Authentication
    • Labels:
      None

      With MongoDB 2.6 the usersInfo command is used to determine if the addUser helper should call createUser or updateUser when passed a given username. Starting with MongoDB 2.7.0 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. Any driver that calls usersInfo in its addUser helper can no longer be used to add the first admin user while 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.

      https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            barrie Barrie Segal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: