Skip to content

Commit 6f917ed

Browse files
zakum1regisb
authored andcommitted
feat: support for mongodb SSL+auth source/mech+replica set
This change builds upon a previously proposed PR: #437 There was another long conversation about this topic here: overhangio/tutor-forum#10 (comment) We could have supported the MongoDB auth/replica set/ssl parameters as part of the MongoDB host URI, but then this URI is not supported in the forum plugin, which uses an old version of the mongoid client. We were hoping that the client would have been upgraded by now, but it's not been upgraded for a long time. The changes introduced here are 100% backward-compatible. The forum plugin will have to be updated to take into account the new parameters.
1 parent 1310480 commit 6f917ed

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Feature] Add support for MongoDB SSL, authentication source, mechanism and replica set via the `MONGODB_USE_SSL`, `MONGODB_AUTH_MECHANISM`, `MONGODB_AUTH_SOURCE`, `MONGODB_REPLICA_SET` settings. (by @zakum1 and @regisb)

docs/configuration.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,17 @@ MongoDB
242242
*******
243243

244244
- ``RUN_MONGODB`` (default: ``true``)
245-
- ``MONGODB_HOST`` (default: ``"mongodb"``)
246245
- ``MONGODB_DATABASE`` (default: ``"openedx"``)
246+
- ``MONGODB_HOST`` (default: ``"mongodb"``)
247+
- ``MONGODB_PASSWORD`` (default: ``""``)
247248
- ``MONGODB_PORT`` (default: ``27017``)
248249
- ``MONGODB_USERNAME`` (default: ``""``)
249-
- ``MONGODB_PASSWORD`` (default: ``""``)
250+
- ``MONGODB_USE_SSL`` (default: ``false``)
251+
- ``MONGODB_REPLICA_SET`` (default: ``""``)
252+
- ``MONGODB_AUTH_MECHANISM`` (default: ``""``)
253+
- ``MONGODB_AUTH_SOURCE`` (default: ``"admin"``)
254+
255+
Note that most of these settings will have to be modified to connect to a MongoDB cluster that runs separately of Tutor, such as `Atlas <https://www.mongodb.com/atlas>`__. In particular, the authentication source, mechanism and the SSL connection parameters should not be specified as part of the `host URI <https://www.mongodb.com/docs/manual/reference/connection-string/>`__ but as separate Tutor settings. Supported values for ``MONGODB_AUTH_MECHANISM`` are the same as for pymongo (see the `pymongo documentation <https://pymongo.readthedocs.io/en/stable/examples/authentication.html>`__).
250256

251257
Redis
252258
*****

tutor/templates/apps/openedx/settings/partials/common_all.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
# Mongodb connection parameters: simply modify `mongodb_parameters` to affect all connections to MongoDb.
88
mongodb_parameters = {
9+
"db": "{{ MONGODB_DATABASE }}",
910
"host": "{{ MONGODB_HOST }}",
1011
"port": {{ MONGODB_PORT }},
11-
{% if MONGODB_USERNAME and MONGODB_PASSWORD %}
12-
"user": "{{ MONGODB_USERNAME }}",
13-
"password": "{{ MONGODB_PASSWORD }}",
14-
{% else %}
15-
"user": None,
16-
"password": None,
17-
{% endif %}
18-
"db": "{{ MONGODB_DATABASE }}",
19-
"replicaSet": None,
12+
"user": {% if MONGODB_USERNAME %}"{{ MONGODB_USERNAME }}"{% else %}None{% endif %},
13+
"password": {% if MONGODB_PASSWORD %}"{{ MONGODB_PASSWORD }}"{% else %}None{% endif %},
14+
# Connection/Authentication
15+
"ssl": {{ MONGODB_USE_SSL }},
16+
"authSource": "{{ MONGODB_AUTH_SOURCE }}",
17+
"replicaSet": {% if MONGODB_REPLICA_SET %}"{{ MONGODB_REPLICA_SET }}"{% else %}None{% endif %},
18+
{% if MONGODB_AUTH_MECHANISM %}"authMechanism": "{{ MONGODB_AUTH_MECHANISM }}",{% endif %}
2019
}
2120
DOC_STORE_CONFIG = mongodb_parameters
2221
CONTENTSTORE = {

tutor/templates/config/defaults.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ K8S_NAMESPACE: "openedx"
3434
LANGUAGE_CODE: "en"
3535
LMS_HOST: "www.myopenedx.com"
3636
LOCAL_PROJECT_NAME: "{{ TUTOR_APP }}_local"
37+
MONGODB_AUTH_MECHANISM: ""
38+
MONGODB_AUTH_SOURCE: "admin"
3739
MONGODB_HOST: "mongodb"
3840
MONGODB_DATABASE: "openedx"
3941
MONGODB_PORT: 27017
4042
MONGODB_USERNAME: ""
4143
MONGODB_PASSWORD: ""
44+
MONGODB_REPLICA_SET: ""
45+
MONGODB_USE_SSL: false
4246
OPENEDX_AWS_ACCESS_KEY: ""
4347
OPENEDX_AWS_SECRET_ACCESS_KEY: ""
4448
OPENEDX_CACHE_REDIS_DB: 1

0 commit comments

Comments
 (0)