minikube-mongodb-demo icon indicating copy to clipboard operation
minikube-mongodb-demo copied to clipboard

Authentication failure

Open gkganesh126 opened this issue 6 years ago • 10 comments

After running generate.sh and when I try to run, db.getSiblingDB('admin').auth("main_admin", "abc123"); I get, "Error: Authentication failed." But the pod is in running state.

gkganesh126 avatar Apr 23 '18 13:04 gkganesh126

Any updates? I'm having the same problem!

iArtur avatar Jun 29 '18 20:06 iArtur

Have you ran ./configure_repset_auth.sh abc123(step 3 here)? The description just says you ran generate.sh?

jakereps avatar Jul 21 '18 01:07 jakereps

I get the same error: Error: Authentication failed.

I ran ./generate.sh and then ./configure_repset_auth.sh abc123 Generate ran fine and pods and service were generated. But configure_repset_auth had this following output:

Configuring the MongoDB Replica Set
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0
{
	"ok" : 0,
	"errmsg" : "No host described in new configuration 1 for replica set MainRepSet maps to this node",
	"code" : 93,
	"codeName" : "InvalidReplicaSetConfig"
}
Waiting for the Replica Set to initialise...
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0
{
	"ok" : 0,
	"errmsg" : "no replset config has been received",
	"code" : 94,
	"codeName" : "NotYetInitialized"
}
Creating user: 'main_admin'
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0
2018-07-29T23:37:05.131+0000 E QUERY    [js] Error: couldn't add user: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1491:15
@(shell eval):1:1
command terminated with exit code 252


ariel123 avatar Jul 29 '18 23:07 ariel123

I'm also facing this issue and maybe found a solution. https://stackoverflow.com/questions/41783700/when-creating-first-admin-user-on-mongdb-cluster-getting-error-couldnt-add-use/41789745

But how could this be applied to the config file?

Ninerian avatar Nov 13 '18 10:11 Ninerian

@ariel123 @Ninerian Did you found any solution?

laurogripa avatar Jan 14 '19 22:01 laurogripa

I have the same issue.

cgillions avatar May 10 '19 13:05 cgillions

I had the same problem as @ariel123 @Ninerian and think I worked through it. I ended up, via kubectl and minikube, opening bash on one of the mongodb pods

kubectl exec -it mongod-0 -c mongod-container bash

Once in there, per the stackoverflow link (https://stackoverflow.com/a/41789745/278763) I disabled authorization by editing the mongo.conf file (I think I had to copy the .orig file to just mongo.conf) and stopped/started the mongo service. I also had to apt-get install an editor - nothing seemed to be installed by default.

After that came back up I tried runinng the configure script again and it seemed to work. Somewhere in there I think I also ran just rs.initiate() by itself to try and init something and I think that did something, but then it let me run the whole configure repset script in general.

petertirrell avatar May 24 '19 14:05 petertirrell

This means the image used has to be updated. Or could we leverage ConfigMap?

fzhan avatar Jul 25 '19 04:07 fzhan

@laurogripa Maybe you created the cluster on a different namespace. I had this issue for ./configure_repset_auth.sh script, Just change default to your namespace. As Repset Members need your services. Change host to host: "mongod-1.mongodb-service.**mongodb**.svc.cluster.local:27017 where mongodb is your namespace

tawsif93 avatar Feb 11 '20 10:02 tawsif93

@laurogripa Maybe you created the cluster on a different namespace. I had this issue for ./configure_repset_auth.sh script, Just change default to your namespace. As Repset Members need your services. Change host to host: "mongod-1.mongodb-service.**mongodb**.svc.cluster.local:27017 where mongodb is your namespace

I was facing the same issue. I just changed the default namespace to mynamespace as follows: host : "mongod-0.mongodb-service.default.svc.cluster.local:27017" to host : "mongod-0.mongodb-service.mynamespace.svc.cluster.local:27017"

faaizshah avatar Jan 11 '22 15:01 faaizshah