NodeBB MongoError: Authentication failed in Docker


  • Hello,

    I'm trying move my current forum to a docker container, but I get this error when I start and then see nodebb's log:

        at readableAddChunk (internal/streams/readable.js:284:9)
    [cluster] Child Process (381) has exited (code: 0, signal: null)
    
    NodeBB v1.16.2 Copyright (C) 2013-2014 NodeBB Inc.
    This program comes with ABSOLUTELY NO WARRANTY.
    This is free software, and you are welcome to redistribute it under certain conditions.
    For the full license, please visit: http://www.gnu.org/copyleft/gpl.html
    
    Clustering enabled: Spinning up 1 process(es).
    
    2021-04-02T20:29:11.773Z [4567/466] - info: Initializing NodeBB v1.16.2 http://DOMAIN.COM/
    (node:466) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
    (Use `node --trace-warnings ...` to show where the warning was created)
    2021-04-02T20:29:29.820Z [4567/466] - error: MongoError: Authentication failed.
        at MessageStream.messageHandler (/home/nodebb/node_modules/mongodb/lib/cmap/connection.js:268:20)
        at MessageStream.emit (events.js:315:20)
        at processIncomingData (/home/nodebb/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
        at MessageStream._write (/home/nodebb/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
        at writeOrBuffer (internal/streams/writable.js:358:12)
    [cluster] Child Process (466) has exited (code: 0, signal: null)
        at MessageStream.Writable.write (internal/streams/writable.js:303:10)
        at Socket.ondata (internal/streams/readable.js:719:22)
        at Socket.emit (events.js:315:20)
        at addChunk (internal/streams/readable.js:309:12)
        at readableAddChunk (internal/streams/readable.js:284:9)
    

    I checked config.json file and the database connection info, they're correct in my opinion (I've copied them from my current NodeBB forum which is running on a standalone VPS):

    {
        "url": "http://DOMAIN.COM/",
        "secret": "e7cfe25e-6916-4831-8c6f-5856b122bfa2",
        "database": "mongo",
        "port": "4567",
        "mongo": {
            "host": "node_db",
            "port": "27017",
            "username": "USER",
            "password": "PASS",
            "database": "DB"
        }
    }
    

    My mongo container is another one, and these two container can ping each other with no problem (there's no networking issue between them), but I don't know why NodeBB shows it cannot authenticate.

    Also when I run ./nodebb setup, I get the below logs:

    2021-04-02T20:35:15.917Z [485] - info: NodeBB Setup Triggered via Command Line
    
    Welcome to NodeBB v1.16.2!
    
    This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.
    Press enter to accept the default setting (shown in brackets).
    2021-04-02T20:35:16.396Z [485] - info:
    Now configuring mongo database:
    (node:485) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
    (Use `node --trace-warnings ...` to show where the warning was created)
    2021-04-02T20:35:17.208Z [485] - warn: NodeBB Setup Aborted.
     MongoError: Authentication failed.
        at MessageStream.messageHandler (/home/nodebb/node_modules/mongodb/lib/cmap/connection.js:268:20)
        at MessageStream.emit (events.js:315:20)
        at processIncomingData (/home/nodebb/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
        at MessageStream._write (/home/nodebb/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
        at writeOrBuffer (internal/streams/writable.js:358:12)
        at MessageStream.Writable.write (internal/streams/writable.js:303:10)
        at Socket.ondata (internal/streams/readable.js:719:22)
        at Socket.emit (events.js:315:20)
        at addChunk (internal/streams/readable.js:309:12)
        at readableAddChunk (internal/streams/readable.js:284:9)
    

    I have also modified bindIp line and added nodebb's container name to allow connections, but I get this error.

    bindIp: 127.0.0.1,NAME
    

    telneting from NodeBB container to telnet mongo 27017 works fine and mongo "mongodb:[email protected]" in command line of nodebb container works fine too.

    I also logged into MongoDB's shell with the exact username and password and that was right.

    It's I think clear that it cannot authenticate, but I do not know why and what's my issue that I did not notice.

    Could you please help me?

  • Community Rep

    @inna Seems you've fairly covered the bases. That you can both connect and auth via cli is instructive. Points to maybe something nodebb config side?

    For e.g., I am unclear on this stanza:

    @inna said in NodeBB MongoError: Authentication failed in Docker:

    "mongo": {
    "host": "node_db",
    "port": "27017",
    "username": "USER",
    "password": "PASS",
    "database": "DB"
    }

    Emphasis added.

    @inna said in NodeBB MongoError: Authentication failed in Docker:

    My mongo container is another one, and these two container can ping each other with no problem (there's no networking issue between them), but I don't know why NodeBB shows it cannot authenticate.

    So... what is the actual value for the mongodb container? Maybe try something more explicit? Like the mongodb node's IP address?

    "host": "10.0.0.5",
    

    Otherwise... I don't do Docker so whatever goes on in those black boxes is a mystery to me....


  • @gotwf thanks for the reply, let me explain some of them:

    "host": "node_db",
    

    The name node_db is the name that I specified for database container, and the name node_site is I chose for NodeBB container (nodebb_site has files).

    I tried both container's name and IP address of the container, but it seems there's another issue.

    As IPs of docker containers may change if I restart the server (172.17.0.0/16), it's better to use container's name.

    I also have changed bindIp option to bindIp: 127.0.0.1,172.24.0.4 and then try again but no luck. Also tried with bindIp: 0.0.0.0 but still no luck.

    I grepped localhost in /home/nodebb/node_modules/mongodb/lib/cmap/connection.js and changed it to node_db, but still no luck.

    I'm confused although connection is fine, where this authentication failed goes from and why.

    I commented the lines related to security and authorization in mongod.conf, but no luck.

  • Global Moderator Plugin & Theme Dev

    https://github.com/NodeBB/NodeBB/blob/c02310b80f3138bc0eef1962721cc9c116abbac0/.github/workflows/test.yaml#L71

    We use the mongo docker image in our CI tests through GitHub actions. Not sure how helpful this is for you.

Suggested Topics

| |