shellhub-io / shellhub

:computer: Get seamless remote access to any Linux device. Centralized SSH for the edge and cloud computing
https://shellhub.io
Apache License 2.0
1.38k stars 137 forks source link

can't add-namespace with MongoDB 5.x+ #3038

Closed civilizeddev closed 1 year ago

civilizeddev commented 1 year ago

Description

I tried to self-hosted deploy ShellHub in a Kubernetes environment. I ended up using MongoDB version 6.x, and I'm not sure if it's because of that, but whenever I try to add a namespace through the API or CLI, it keeps failing with the 'namespace already exists' error.

One thing I noticed is that it succeeds before v0.10.4 and fails after v0.10.5. The change is due to this commit.

v0.10.4

https://github.com/shellhub-io/shellhub/blob/97fc663fbf28a399ac682480777e0566da12fe86/api/store/mongo/namespace_store.go#L166-L170

v0.10.5

https://github.com/shellhub-io/shellhub/blob/73dbd27ace84d8d6da8f17ef53c1761e924ed0d4/api/store/mongo/namespace_store.go#L168-L196

I suspect this might be a compatibility issue arising from the different version of MongoDB.

I'm using a Kubernetes environment, so I'm trying to install MongoDB using a helm chart. Unfortunately, the MongoDB 4.x version that you guys have set as default is too outdated and doesn't support the latest helm chart. I hope you can provide a compatibility patch so that even the latest version of MongoDB can be used without any issues.

https://github.com/shellhub-io/shellhub/blob/73dbd27ace84d8d6da8f17ef53c1761e924ed0d4/cli/service.go#L215-L218

Also, looking at the code, it doesn't print the actual error logs at all and always overwrites the err return value. This makes debugging difficult and causes confusion, so I hope this part can be improved as well.

What I tried

v0.12.4

# ok
./cli user create username password email@gmail.com

# fail (namespace already exists)
./cli namespace create namespace username 

# fail (namespace already exists)
./cli add-namespace namespace username

v0.10.4

This is my workaround for now.

# ok
./cli add-user username password email@gmail.com

# ok
./cli add-namespace namespace username

v0.10.5

# ok
./cli add-user username password email@gmail.com

# fail (namespace already exists)
./cli add-namespace namespace username

Environment

Related

Edition

Community

Version

v0.12.4

civilizeddev commented 1 year ago

MongoDB Transaction

Transaction numbers are only allowed on a replica set member or mongos.

It seems that this issue is not due to the MongoDB version but rather the mode in which MongoDB is run.

I discovered that in order to use Transactions, MongoDB needs to be run as a Replica Set or Sharded Cluster.

I think this problem arose because I was running MongoDB in Standalone Mode.

Reference