I have done for setup a mongodb's replicaset on k8s with 4 members (1 primary, 1 secondary, 1 arbiter, 1 hidden for backup). All members have enable authentication by passing argument --auth.
I also create a cronjob which responsible for backup db to s3.
However, I got a problem when try to connect to backup pod from cronjob pod.
Here is the error stack:
connecting to: mongodb://mongodb-backup-0.mongodb-backup.default.svc.cluster.local:27017/?authSource=admin&gssapiServiceName=mongodb
2019-04-05T04:26:52.870+0000 E QUERY [js] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:343:13
@(connect):2:6
exception: connect failed
I enable to connect to mongo backup's instance from inside backup pod:
rs0:SECONDARY> db.auth("admin", "test")
1
I also try to connect the backup pod from the secondary pod. It report the same error. Here is my command:
mongo --authenticationDatabase admin --host mongodb-backup-0.mongodb-backup.default.svc.cluster.local --port 27017 -u "admin" -p "test"
However, If I connect to the backup pod without username and password, I enable to connect to the mongodb backup instance.
mongo --authenticationDatabase admin --host mongodb-backup-0.mongodb-backup.default.svc.cluster.local --port 27017
Anyone can give an advise?
I found the answer for this problem.
I start the mongod instance with --authenticationMechanism 'SCRAM-SHA-256'
parameter. So, The mongo shell require input the --authenticationMechanism
to enable to login.