-
Notifications
You must be signed in to change notification settings - Fork 653
Description
This issue (I would call it a bug but perhaps it is a feature request) is that users would like to a la docker-compose.yml and/or environment variables be able to set a database with a username and password they specify upon launch of the image.
Background:
This issue was filed #174 and closed because the behavior of a PR #145 was mentioned as the solution. What #145 actually does and what users expect are entirely different. What PR #145 does is set a user with elevated permissions (i.e. "root" user) that has superuser access to the entire MongoDB instance (as mentioned in #174 (comment). However what most users expect from these environment variables is that a database they specify is initialized with the username and password they have set. It is confusing that these environment variables (MONGO_INITDB_DATABASE, MONGO_INITDB_ROOT_PASSWORD and MONGO_INITDB_ROOT_USERNAME) pertain to only setting a user with the role root on the database admin and initializing an user specified database for .js and .sh scripts in /docker-entrypoint-initdb.d/ to be run against.
Proposal:
We should make the environment variables very explicitly named in what they do in addition to adding others for the behavior I think most users come to expect when reading the variable names. Since it is the case most users would like their instance initialized with a database of their specification we should add this feature to meet that expectation.
- We keep
MONGO_INITDB_ROOT_USERNAMEandMONGO_INITDB_ROOT_PASSWORD - We remove
MONGO_INITDB_DATABASEas it is misleading - We add
MONGO_INITDB_ROOT_DATABASEand allow it to override the hardcodedadmindatabase - We add
MONGO_USERDB_ADMIN_USERNAME,MONGO_USERDB_ADMIN_PASSWORD, andMONGO_USERDB_ADMIN_DATABASE - We update the documentation to state:
MONGO_INITDB_ROOT_USERNAME,MONGO_INITDB_ROOT_PASSWORD, andMONGO_INITDB_ROOT_DATABASEwill be used for therootrole to Mongo
MONGO_USERDB_ADMIN_USERNAME,MONGO_USERDB_ADMIN_PASSWORD, andMONGO_USERDB_ADMIN_DATABASEwill be used to initialize a user specified database- That all of the
.jsand.shscripts a user supplies in/docker-entrypoint-initdb.d/will be executed againstMONGO_USERDB_ADMIN_DATABASE
Reasons for change:
- The variables
MONGO_INITDB_ROOT_PASSWORDandMONGO_INITDB_ROOT_USERNAMEare only used for theadmindatabase - Currently all
MONGO_INITDB_DATABASEdoes is have operations used against it whenever a user has dropped in.jsor.shscripts into/docker-entrypoint-initdb.d/. This unclear unless you look atdocker-entrypoint.shin this repository and no where clearly stated in the documentation as such - The documentation is unclear and the only way to hack in a user initialized database with a username and password on image launch is to also create a script in
/docker-entrypoint-initdb.d/which then places burden on the user to maintain therootrole credentials in environment variables which live separately from a custom.jsor.shscript which they have to volume into the image
References:
- Issue: Initialize admin username/password and DB doesn't seems to be working ... #174
- PR: Add "docker-entrypoint-initdb.d" behavior which mimics PostgreSQL, including (optional) automated "root" user creation #145
Involved Persons:
@mmi-rperez
@tianon
@vutran1710
@yosifkit
@lonix1
@johnwyles