Skip to content

Commit 172f77d

Browse files
committed
adding configuration for TLS on top of mongoDB
1 parent 8f1fd7a commit 172f77d

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

beacon/connections/mongo/__init__.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pymongo.mongo_client import MongoClient
22
from beacon.connections.mongo import conf
3-
import os
43

54
if conf.database_cluster:
65
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
@@ -18,9 +17,7 @@
1817
conf.database_auth_source
1918
)
2019

21-
if os.path.isfile(conf.database_certificate):
22-
uri += '&tls=true&tlsCertificateKeyFile={}'.format(conf.database_certificate)
23-
if os.path.isfile(conf.database_cafile):
24-
uri += '&tlsCAFile={}'.format(conf.database_cafile)
20+
if conf.database_certificate != '' and conf.database_cafile != '':
21+
uri += '&tls=true&tlsCertificateKeyFile={}&tlsCAFile={}'.format(conf.database_certificate, conf.database_cafile)
2522

2623
client = MongoClient(uri)

docker-compose.remote.yml

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ services:
5757
db:
5858
image: mongo:5
5959
command: --wiredTigerCacheSizeGB 4
60+
#command: --wiredTigerCacheSizeGB 4 --sslMode requireSSL --tlsCertificateKeyFile test-server1.pem --tlsCAFile test-ca.pem
6061
hostname: mongo
6162
container_name: mongoprod
6263
ports:
@@ -71,6 +72,9 @@ services:
7172
- ./beacon/connections/mongo/data/db:/data/db
7273
- ./beacon/connections/mongo/data/configdb:/data/configdb
7374
- ./beacon/connections/mongo/data/caseLevelData:/data/caseLevelData
75+
#- ./test-server1.pem:/test-server1.pem
76+
#- ./test-ca.pem:/test-ca.pem
77+
#- ./test-client.pem:/test-client.pem
7478
#command: --verbose
7579

7680
beacon-ri-tools:

docker-compose.yml

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ services:
6868
db:
6969
image: mongo:5
7070
command: --wiredTigerCacheSizeGB 4
71+
#command: --wiredTigerCacheSizeGB 4 --sslMode requireSSL --tlsCertificateKeyFile test-server1.pem --tlsCAFile test-ca.pem
7172
hostname: mongo
7273
container_name: mongoprod
7374
ports:
@@ -82,6 +83,9 @@ services:
8283
- ./beacon/connections/mongo/data/db:/data/db
8384
- ./beacon/connections/mongo/data/configdb:/data/configdb
8485
- ./beacon/connections/mongo/data/caseLevelData:/data/caseLevelData
86+
#- ./test-server1.pem:/test-server1.pem
87+
#- ./test-ca.pem:/test-ca.pem
88+
#- ./test-client.pem:/test-client.pem
8589
networks:
8690
- pub
8791
#command: --verbose

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ aiohttp-middlewares==2.4.0
88
aiohttp-jinja2==1.5
99
aiohttp-session==2.9.0
1010
asyncpg==0.24.0
11-
cryptography==39.0.1
11+
cryptography==41.0.5
1212
PyJWT==2.7.0
1313
python-dotenv==1.0.1
1414
jsonschema==4.21.1
@@ -17,6 +17,7 @@ loguru==0.7.2
1717
pyyaml==6.0.1
1818
dataclasses-json==0.5.6
1919
pymongo[srv]==4.0.1
20+
pyopenssl==23.3.0
2021
coverage==7.6.0
2122
requests==2.25.1
2223
pydantic==2.6.2

0 commit comments

Comments
 (0)