electerious / Ackee

Self-hosted, Node.js based analytics tool for those who care about privacy.
https://ackee.electerious.com
MIT License
4.2k stars 351 forks source link

MongoDB Auth doesn't work #301

Closed Minecodes closed 2 years ago

Minecodes commented 2 years ago

My server said "Bad auth" on MongoDB, but my password was right and everything other too.

[Ackee] › ✖  fatal     MongoServerError: bad auth : Authentication failed.
    at MessageStream.messageHandler (/var/www/analytics/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:467:30)
    at MessageStream.emit (node:events:390:28)
    at processIncomingData (/var/www/analytics/node_modules/mongoose/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
    at MessageStream._write (/var/www/analytics/node_modules/mongoose/node_modules/mongodb/lib/cmap/message_stream.js:28:9)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at MessageStream.Writable.write (node:internal/streams/writable:334:10)
    at TLSSocket.ondata (node:internal/streams/readable:754:22)
    at TLSSocket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
electerious commented 2 years ago

Maybe there's no way to connect to the MongoDB in the container/environment Ackee is running. There shouldn't be any trouble connecting otherwise.

electerious commented 2 years ago

I'm closing this issue, because I'm not able to reproduce it. Let me know if there's something I can help with.

ndaidong commented 2 years ago

@Minecodes is your MongoDB running within another docker container? I got the same issue. After tested with some users with write permission on ackee database, I even tried with mongo root account, but it could not authenticate as expected.

ndaidong commented 2 years ago

@Minecodes I've fixed my issue. Here is short note, may be useful for you or someone who is facing this problem.

In mongodb you can do it as below:

# connect to mongodb cli with admin account, e.g, admin 
mongo -u ADMIN_USER

# with docker
docker exec -it CONTAINER mongo -u ADMIN_USER

# switch to ackee db
use ackeedb

# create user
db.createUser({
  user: 'USERNAME',
  pwd: 'PASSWORD',
  roles:[
    {
      role: 'readWrite',
      db: 'ackeedb'
    }
  ]
})
Minecodes commented 2 years ago

No, it's on MongoDB Atlas @ndaidong

carvalholeo commented 2 years ago

@Minecodes please, verify if your user does have permission to read/write any database at Security tab on MongoDB Atlas. I had the same issue when I started to use Ackee and it was solved changing this configuration,

Minecodes commented 2 years ago

@carvalholeo it was the right user, because I used it in my MongoDB CLI.