2

I am deploying mongodb to Kubernetes with following values:

mongodb:
  persistence:
    enabled: true
    existingClaim: mongodb-pvc
  volumePermissions:
    enabled: true
  mongodbRootPassword: hello
  mongodbUsername: db_user
  mongodbPassword: alongpassword
  mongodbDatabase: db_read
  replicaCount: 1
  usePassword: true

The chart gets deployed without any problem. But problem arises when connecting from rails app deployed in same cluster I set ENV like

- name: MONGO_DB_URI
  value: {{ template "core.mongodb.uri" . }}

and have this in template

{{- define "core.mongodb.uri" -}}
{{- printf "mongodb://%s:%s@%s-%s:27017" .Values.mongodb.user .Values.mongodb.password .Release.Name "mongodb.default.svc.cluster.local" -}}
{{- end -}}

The values are supplied correctly But when rails tries to connect the following error is thrown

Mongo::Auth::Unauthorized (User db_user (mechanism: scram) is not authorized to access admin (auth source: admin, used mechanism: SCRAM-SHA-1, used server: relese-name-mongodb.default.svc.cluster.local:27017 (STANDALONE)): Authentication failed. (on crelese-name-mongodb.default.svc.cluster.local:27017))

and get following in mongo log

2020-02-25T18:36:33.722+0000 I ACCESS   [conn2050] Supported SASL mechanisms requested for unknown user 'db_user@admin'
2020-02-25T18:36:33.733+0000 I ACCESS   [conn2050] SASL SCRAM-SHA-1 authentication failed for db_user on admin from client 10.244.0.227:34092 ; UserNotFound: Could not find user db_user@admin
Tek Nath Acharya
  • 1,676
  • 2
  • 20
  • 35
  • 1
    do you have a user defined in the admin database called `db_user`? – barrypicker Feb 25 '20 at 22:26
  • It might be helpful to see the config file associated with the mongod as well. Seems you have some form of authorization enabled. – barrypicker Feb 25 '20 at 22:26
  • @barrypicker That was the problem, solved after creating `bd_user` in `admin` database. But think it is not a good fix. – Tek Nath Acharya Feb 26 '20 at 04:57
  • If you can provide the configuration files I could provide guidance on authorization choices. BTW - given you specified a database user and password in the Chart but the user does not exist, what is your desired (or expected) outcome? – barrypicker Feb 26 '20 at 16:14

0 Answers0