Authorization with Tailscale VPN

I have always used my self hosted MongoDB instance serving on localhost. I have now added a tailscale VPN interface as 100.x.y.z and restarted the DB.

MongoDB Compass now connects with a connection string in which localhost has been changed to tailscale IP address.

The SAME connection string used in pymongo does connect but the search fails with the following error:

pymongo.errors.OperationFailure: not authorized on your_database_name to execute command { find: "people", filter: { form: { $regex: "Poggiolini", $options: "i" } }, lsid: { id: UUID("84fd5fd2-e592-403f-b9bd-381cf7fa7e46") }, $db: "your_database_name" }, full error: {'ok': 0.0, 'errmsg': 'not authorized on your_database_name to execute command { find: "people", filter: { form: { $regex: "Poggiolini", $options: "i" } }, lsid: { id: UUID("84fd5fd2-e592-403f-b9bd-381cf7fa7e46") }, $db: "your_database_name" }', 'code': 13, 'codeName': 'Unauthorized'}
I am confused. Help please.

Sounds like you are accidentally or unintentionally relying on the “localhost exception” https://www.mongodb.com/docs/manual/core/localhost-exception/

To resolve, connect via localhost, create your first user using the docs above, and then connect via the IP with the newly created user’s credentials.

3 Likes