Skip to content

Add TLS/SSL encryption feature to mongodbdriver #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytpcc/MONGODB_EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ denormalize = True
retry_writes = True
# user = username
# passwd = passwd
ssl = False
ssl_certfile = client.pem
ssl_ca_certs = ca.pem
ssl_pem_passphrase = passphrase
36 changes: 28 additions & 8 deletions pytpcc/drivers/mongodbdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,19 @@
## ==============================================
class MongodbDriver(AbstractDriver):
DEFAULT_CONFIG = {
"uri": ("The mongodb connection string or URI", "mongodb://localhost:27017"),
"name": ("Database name", "tpcc"),
"denormalize": ("If true, data will be denormalized using MongoDB schema design best practices", True),
"notransactions": ("If true, transactions will not be used (benchmarking only)", False),
"findandmodify": ("If true, all things to update will be fetched via findAndModify", True),
"secondary_reads": ("If true, we will allow secondary reads", True),
"retry_writes": ("If true, we will enable retryable writes", True),
"uri": ("The mongodb connection string or URI", "mongodb://localhost:27017"),
"name": ("Database name", "tpcc"),
"denormalize": ("If true, data will be denormalized using MongoDB schema design best practices", True),
"notransactions": ("If true, transactions will not be used (benchmarking only)", False),
"findandmodify": ("If true, all things to update will be fetched via findAndModify", True),
"secondary_reads": ("If true, we will allow secondary reads", True),
"retry_writes": ("If true, we will enable retryable writes", True),
"causal_consistency": ("If true, we will perform causal reads ", True),
"shards": ("If >1 then sharded", "1")
"shards": ("If >1 then sharded", "1"),
"ssl": ("If true, PyMongo will be configured to connect to the server using TLS", False),
"ssl_certfile": ("The path to a client certificate", ""),
"ssl_ca_certs": ("The path to a CA file", ""),
"ssl_pem_passphrase": ("The password or passphrase to decrypt encrypted private keys", "")
}
DENORMALIZED_TABLES = [
constants.TABLENAME_ORDERS,
Expand Down Expand Up @@ -232,6 +236,10 @@ def __init__(self, ddl):
self.result_doc = {}
self.warehouses = 0
self.shards = 1
self.ssl = False
self.ssl_certfile = None
self.ssl_ca_certs = None
self.ssl_pem_passphrase = None

## Create member mapping to collections
for name in constants.ALL_TABLES:
Expand Down Expand Up @@ -268,6 +276,14 @@ def loadConfig(self, config):
self.secondary_reads = config['secondary_reads'] == 'True'
if self.secondary_reads:
self.read_preference = "nearest"
self.ssl = config['ssl'] == 'True'
if self.ssl:
if config['ssl_certfile'] != "":
self.ssl_certfile = config['ssl_certfile']
if config['ssl_ca_certs'] != "":
self.ssl_ca_certs = config['ssl_ca_certs']
if config['ssl_pem_passphrase'] != "":
self.ssl_pem_passphrase = config['ssl_pem_passphrase']

if 'write_concern' in config and config['write_concern'] and config['write_concern'] != '1':
# only expecting string 'majority' as an alternative to w:1
Expand Down Expand Up @@ -298,6 +314,10 @@ def loadConfig(self, config):
display_uri = uri[0:pindex]+usersecret+uri[pindex:]

self.client = pymongo.MongoClient(real_uri,
ssl=self.ssl,
ssl_certfile=self.ssl_certfile,
ssl_ca_certs=self.ssl_ca_certs,
ssl_pem_passphrase=self.ssl_pem_passphrase,
retryWrites=self.retry_writes,
readPreference=self.read_preference,
readConcernLevel=self.read_concern)
Expand Down