SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Docker: Define auth on mongodb #267

Closed iwoork closed 6 years ago

iwoork commented 6 years ago

Might have missed this somewhere but I can't seem to find a way to implement authentication on the mongodb instance. This makes the database accessible to the outside world.

How to implement a username and password on mongodb and also make sure that restheart uses the same configuration?

I tried adding:

  environment:
      # provide your credentials here
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=rootPassXXX

but doesn't seem to work

mkjsix commented 6 years ago

@iwoork the 2 environment variables initialize mongodb, but then you need to provide those also to RESTHeart. At the moment however there isn't an automatic mechanism for reading environment variables, what we usually do is to define a custom restheart configuration file and create our own docker image with that

in your custom restheart.yml edit the mongouri with the same credentials:

mongo-uri: mongodb://<username>:<password>@<host>:<port>/<database>

This way restheart container will connect to the external database. Then you have to build your own Docker image, maybe starting from the official Dockerfile.

iwoork commented 6 years ago

Thanks for the response. I managed to make it work by manually logging into the mongo console and setting an admin user and use that credentials on the mongo-uri as stated above.