elastic / connectors

Source code for all Elastic connectors, developed by the Search team at Elastic, and home of our Python connector development framework
https://www.elastic.co/guide/en/enterprise-search/master/index.html
Other
73 stars 126 forks source link

Mongodb requires admin db permission #1922

Closed lio-p closed 9 months ago

lio-p commented 10 months ago

Bug Description

The documentation says The user must have access to the configured database and collection. You may want to create a dedicated, read-only user for each connector.

However, using an user with read only access to a user database, the connector sync fails with the following error: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}

To Reproduce

Steps to reproduce the behavior:

  1. In MongoDB, create a user with read only permission on an user database.
  "users": [
    {
      "_id": "test.suppliersReadOnly",
      "userId": {
        "$binary": {
          "base64": "+TvKq76mRGivDG0qkguvCw==",
          "subType": "04"
        }
      },
      "user": "suppliersReadOnly",
      "db": "test",
      "roles": [
        {
          "role": "read",
          "db": "retail"
        }
      ],
      "mechanisms": [
        "SCRAM-SHA-1",
        "SCRAM-SHA-256"
      ]
    }
  ],
  "ok": 1
}

Use this user with the MongoDB connector.

Expected behavior

The sync should be successful. Or at least, we shouldn't have to provide an user with root permission on admin db.

artem-shelkovnikov commented 10 months ago

I feel like the easiest fix here is not to fail validation, but instead just debug that "hey we can't validate anything" if we don't have the permission.

Warn is gonna be too noisy IMO, so debug is the way to go

vidok commented 9 months ago

This is interesting. I created a couple of read-only users for Cresty in Atlas and all of them worked as expected. Did you see this error while using a local MongoDB instance?

artem-shelkovnikov commented 9 months ago

I had same with read-only users in https://mongodb.com. The behaviour above I reproduced with our functional test container, so I assume this problem happens only with on-prem (maybe some managed services can do it too)