mongo-express: Persistent "Authentication Failed"

Hello my dear friends.

I’ve been trying to setup a docker container with MongoExpress + MongoDB all week long. I really tried fixing it using all information available on google, but I believe it exausted the possibilities of something obvious I’m missing. Here’s my docker-compose (I’m omitting whatever is not related to mongodb and mdb express):

mongo:
    image: mongo
    container_name: mongodb
    restart: unless-stopped
    env_file: .env
    environment:
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
      - MONGO_INITDB_DATABASE=auth
    networks:
      - education-network
    volumes:
      - ./strapidb:/data/db
    ports:
      - "27017:27017"

  mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    env_file: .env
    environment:
      - ME_CONFIG_MONGODB_ENABLE_ADMIN=true
      - ME_CONFIG_MONGODB_ADMINUSERNAME=${ME_CONFIG_MONGODB_ADMINUSERNAME}
      - ME_CONFIG_MONGODB_ADMINPASSWORD=${ME_CONFIG_MONGODB_ADMINPASSWORD}
      - ME_CONFIG_MONGODB_SERVER=${ME_CONFIG_MONGODB_SERVER}
      - ME_CONFIG_BASICAUTH_USERNAME=${ME_CONFIG_BASICAUTH_USERNAME}
      - ME_CONFIG_BASICAUTH_PASSWORD=${ME_CONFIG_BASICAUTH_PASSWORD}
      - ME_CONFIG_MONGODB_PORT=${ME_CONFIG_MONGODB_PORT}
    depends_on:
      - mongo
    links:
      - mongo
  networks:
      - education-network

networks:
  education-network:
    driver: bridge

Here’s my .env file (it’s ok about passwords, I’ll change them later, just for the sake of debugging this issue):

DATABASE_CLIENT=mongo
DATABASE_NAME=strapi
DATABASE_HOST=mongodb
DATABASE_PORT=27017
DATABASE_USERNAME=strapi
DATABASE_PASSWORD=password
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=pass
ME_CONFIG_MONGODB_ADMINUSERNAME=admin
ME_CONFIG_MONGODB_ADMINPASSWORD=pass
ME_CONFIG_MONGODB_SERVER=mongodb
ME_CONFIG_BASICAUTH_USERNAME=admin
ME_CONFIG_BASICAUTH_PASSWORD=pass
ME_CONFIG_MONGODB_PORT=27017

It runs just fine:

root@educationexperience:~/services/strapi# docker-compose up -d
Creating network "strapi_education-network" with driver "bridge"
Creating strapi                 ... done
Creating mongodb ... done
Creating strapi_mongo-express_1 ... done

It is hosted at https://mdb.projetoalex.cc. It’s aparrently ok but no database is possible to create or edit, listing…

Here is the docker logs output:


mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  | 
mongo-express_1  | 
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongodb          | 2020-06-25T14:18:14.930+0000 I  NETWORK  [listener] connection accepted from 172.30.0.4:39680 #2 (1 connection now open)
mongodb          | 2020-06-25T14:18:14.941+0000 I  NETWORK  [conn2] received client metadata from 172.30.0.4:39680 conn2: { driver: { name: "nodejs", version: "2.2.24" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "4.15.0-101-generic" }, platform: "Node.js v12.18.1, LE, mongodb-core: 2.1.8" }
mongo-express_1  | Database connected
mongodb          | 2020-06-25T14:18:14.951+0000 I  SHARDING [conn2] Marking collection admin.system.users as collection version: <unsharded>
mongodb          | 2020-06-25T14:18:14.952+0000 I  ACCESS   [conn2] SASL SCRAM-SHA-1 authentication failed for admin on admin from client 172.30.0.4:39680 ; UserNotFound: Could not find user "admin" for db "admin"
mongo-express_1  | Error [MongoError]: Authentication failed.
mongo-express_1  |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1  |     at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1  |     at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1  |     at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1  |     at Socket.emit (events.js:315:20)
mongo-express_1  |     at addChunk (_stream_readable.js:295:12)
mongo-express_1  |     at readableAddChunk (_stream_readable.js:271:9)
mongo-express_1  |     at Socket.Readable.push (_stream_readable.js:212:10)
mongo-express_1  |     at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
mongo-express_1  |   ok: 0,
mongo-express_1  |   errmsg: 'Authentication failed.',
mongo-express_1  |   code: 18,
mongo-express_1  |   codeName: 'AuthenticationFailed'
mongo-express_1  | }
mongo-express_1  | Admin Database connected
mongo-express_1  | unable to list databases
mongo-express_1  | Error [MongoError]: command listDatabases requires authentication
mongo-express_1  |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1  |     at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1  |     at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1  |     at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1  |     at Socket.emit (events.js:315:20)
mongo-express_1  |     at addChunk (_stream_readable.js:295:12)
mongo-express_1  |     at readableAddChunk (_stream_readable.js:271:9)
mongo-express_1  |     at Socket.Readable.push (_stream_readable.js:212:10)
mongo-express_1  |     at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
mongo-express_1  |   ok: 0,
mongo-express_1  |   errmsg: 'command listDatabases requires authentication',
mongo-express_1  |   code: 13,
mongo-express_1  |   codeName: 'Unauthorized'
mongo-express_1  | }

Sorry for this long post. But I really tried all options and I’m stuck with this issue. Hoping you guys can help me debug and solve it.

Thanks in advance.

  • Breno

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 7
  • Comments: 16 (2 by maintainers)

Most upvoted comments

Any luck with this one? I’m experiencing similar issue when running inside Kubernetes.

@StMarian I had to add support for SCRAM-SHA-1 in MongoDB Community Kubernetes Operator. By default there is a support only for the new one: SCRAM-SHA-256.

...
spec:
  security:
    authentication:
      modes: ["SCRAM", "SCRAM-SHA-1"]
...

After that, mongo-express (0.54.0) connected to my mongo (4.2).

https://www.mongodb.com/docs/manual/core/security-scram/

Maybe, mongo-express uses old library where only SCRAM-SHA-1 mechanism is supported?

I saw some bumps of packages in 1.0.0, so maybe that’s why it works on this tag.

Me too!

@fpause, did you find a solution? I am also having the same issue with MongoDB Community Kubernetes Operator

Hey, I know why…you need to do this: instead of echo password | base64, do echo -n password | base64 and of course same for username.

Just try!

On Thu, Dec 31, 2020, 12:17 AM Braedencraig notifications@github.com wrote:

Also having this issue! My credentials are correct!! What the HECK!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mongo-express/mongo-express/issues/579#issuecomment-752677753, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEHZNZ7WBPJ6W333RYBMOCDSXNHCRANCNFSM4OINNLAQ .

Looks like it got fixed in v1.0.0-alpha.1

I’m facing the same issue (using MongoDB Community Kubernetes Operator)

@deba10106 Where do you have to use the base64 encoding (when setting the password with MongoDB or just as a value for ME_CONFIG_MONGODB_ADMINPASSWORD)?