khezen / docker-mongo

MongoDB Docker image embedding RocksDB storage engine
33 stars 14 forks source link

Setting Admin Password, Auth and DB Name isn't working #2

Closed dbclkclk closed 7 years ago

dbclkclk commented 7 years ago

Hi:

Awesome container however, I am having an issue. Whenever I set the

  environment:
       - DB_USER:root
       - DB_PWD:p@ssw0rd
       - DB_NAME:blah
       - AUTH:y

It doesn't create the DB nor does it set authentication to true. I am able to connect to the running monodb in my container using Compass without credentials; when I try with credentials, it says invalid user for root: p@ssw0rd. Kindly let me know what could be the issue.

This is my docker-compose.yml

 version: '2'
 services:
   api:
      image: node:slim
     command: chown -R `id -u` /data/d
     volumes:
        - /Users/deanclarke/docker/medullan/api:/usr/src/app
     command: tail -f /dev/null
     depends_on:
        - database
     ports:
        - "8080:8080"
  database:
     image: khezen/mongo:latest
     ports:
          - "27017:27017"
     environment:
       - DB_USER:root
       - DB_PWD:p@ssw0rd
       - DB_NAME:blah
       - AUTH:y
     restart: always

Thanks.

khezen commented 7 years ago

Hi, thank you for reporting this issue. I am working on it.

khezen commented 7 years ago

@dbclkclk

I updated the image on Dockerhub

docker-compose pull or docker pull khezen/mongo to download the new version

I am testing with the following compose:

version: '2'
services:
    database:
     build: ..
     ports:
          - "27017:27017"
     environment:
       DB_USER: root
       DB_PWD: p@ssw0rd
       DB_NAME: blah
       AUTH: y
     restart: always

db creation

Db 'blah' is not shown in the dbs list until the first document is inserted but the db is created:

use admin
switched to db admin
db.auth("admin", "changeme")
1
show dbs
admin  0.000GB
local  0.000GB

auth

if you connect to your mongod instance with the mongo shell you should see expected users by typing:

use admin
switched to db admin
db.auth("admin", "changeme")
1
db.system.users.find().pretty()
{
    "_id" : "admin.admin",
    "user" : "admin",
    "db" : "admin",
    "credentials" : {
        "SCRAM-SHA-1" : {
            "iterationCount" : 10000,
            "salt" : "hMgNs3M7s8Uy4u5/jxxYLw==",
            "storedKey" : "l5VrDRoNl8/WA7UyUScjck7YTcY=",
            "serverKey" : "WmjbpR+jZpQ89X/tt7QRigJzf58="
        }
    },
    "roles" : [
        {
            "role" : "root",
            "db" : "admin"
        }
    ]
}
{
    "_id" : "blah.root",
    "user" : "root",
    "db" : "blah",
    "credentials" : {
        "SCRAM-SHA-1" : {
            "iterationCount" : 10000,
            "salt" : "cvmsEiidBsNyd4JXnaev7Q==",
            "storedKey" : "LbFXQKoLh7VH8KUeazFC7xVPx48=",
            "serverKey" : "7kvhviPbSc1rHoksZlsh8i5rtuQ="
        }
    },
    "roles" : [
        {
            "role" : "dbOwner",
            "db" : "blah"
        }
    ]
}

I am not a compass user. As a shell user, I am able to connect to the mongod instance without any auth. However, I am not allowed to perform any operation on 'blah' until authentication is done:

use blah
switched to db blah
db.test.insert({"test": "I am authenticated"})
WriteResult({
    "writeError" : {
        "code" : 13,
        "errmsg" : "not authorized on blah to execute command { insert: \"test\", documents: [ { _id: ObjectId('58579f705727d13b2b66dfe2') } ], ordered: true }"
    }
})
db.test.find().pretty()
Error: error: {
    "ok" : 0,
    "errmsg" : "not authorized on blah to execute command { find: \"test\", filter: {} }",
    "code" : 13,
    "codeName" : "Unauthorized"
}
use blah
switched to db blah
db.auth("root", "p@ssw0rd")
1
db.test.insert({"test": "I am authenticated"})
WriteResult({ "nInserted" : 1 })
db.test.find().pretty()
{
    "_id" : ObjectId("5857a16585535764ba337c6c"),
    "test" : "I am authenticated"
}

feedback

Please tell me if you have any issue with this new version