phico
phico

Reputation: 1403

Helm Kubernetes MongoDB authentification

How can we authenticate to a mongodb database created by helm stable/mongo chart (from another pod in the same cluster)?

I tried also to add ?authSource=admin&replicaSet=rs0 at the url but authentication still fails..

Upvotes: 1

Views: 1376

Answers (2)

Vittorio Palmisano
Vittorio Palmisano

Reputation: 605

Using the stable/mongodb chart and enabling the replicaSet option, you should connect to the service hostname <deployment fullname>-mongodb using the "root" user and mongodbRootPassword provided password using the --authenticationDatabase admin option (or setting authSource=admin in the connection URL). Example:

kubectl exec -it deployname-mongodb-primary-0 -- mongo dbname -u root -p rootpassword --authenticationDatabase admin

Intstead, if you set mongodbUsername, mongodbPassword and mongodbDatabase, you can connect as non-root user to the configured database; in this case, you should skip the --authenticationDatabase (or authSource=admin) option. Example:

kubectl exec -it deployname-mongodb-primary-0 -- mongo -u username -p userpassword

Upvotes: 0

phico
phico

Reputation: 1403

I managed to connect with the following url (only as root) : mongodb://root:<root_password>@mongodb.mongodb:27017/<db_name>?authSource=admin&replicaSet=rs0 with the --authenticationDatabase admin of the NOTES.txt converted to authSource=admin url parameter

Upvotes: 3

Related Questions