azukaar / Cosmos-Server

☁️ The Most Secure and Easy Selfhosted Home Server. Take control of your data and privacy without sacrificing security and stability (Authentication, anti-DDOS, anti-bot)
https://cosmos-cloud.io
Other
3.1k stars 112 forks source link

[BUG]: MongoDB authentication source not working #111

Closed SSTentacleSS closed 10 months ago

SSTentacleSS commented 10 months ago

What happened?

When I tried to create a separate user on the cosmos database to differentiate access - cosmos did not process the mongo uri correctly, it seemed to not like the mongo://.../cosmos part

What should have happened?

Cosmos must log in to the cosmos database

How to reproduce the bug?

Execute using mongo shell

use("cosmos")

db.createUser({
  user: "cosmos",
  pwd: "test",
  roles: ["dbOwner"]
})

And then set connection string to mongodb://cosmos:test@address:27017/cosmos with replacing address to your docker container name/mongo address

Relevant log output

[ERROR] Database Connect : connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (InvalidNamespace) Invalid database name: 'cosmos/'

Possible solution

Perhaps it’s worth changing db.go and replacing string concatenation with an object-based option for changing parameters?

Maybe it's worth doing something like

...
opts := options.Client().ApplyURI(GetBaseMainConfig().MongoDB).SetRetryWrites(true).SetWriteConcern("majority")
client, err = mongo.Connect(context.TODO(), opts)
...

SetWriteConcern SetRetryWrites

System details

SSTentacleSS commented 10 months ago

Thanks for your quick response!

azukaar commented 10 months ago

Thanks for your quick response!

Meant to give you a better response than that ahah thanks for the well written ticket the change will be tested and introduced in 0.12 (prob next end of week) thanks again

azukaar commented 10 months ago

fixed in 0.12