Utilities and examples for Field-Level Encryption.
This repository includes a very simple example of automatic encryption and decryption in example.py.
Note, example.py only works on macOS (if even that).
- Run
mongod. - Install mockupcryptd and run:
> mongocryptd Listening with domain socket /tmp/mongocryptd.sock URI is mongodb://%2Ftmp%2Fmongocryptd.sock - Create an AWS account with an IAM user with privileges to create and use keys on KMS. Note down the AWS access key ID and secret access key.
- Create a customer master key (CMK) in the AWS console. Note down the resulting key id.
- Install the AWS CLI tools
and run:
> aws configure - Install the example dependencies a new Python virtual environment. This is important, since the example
uses a forked and modified pymongo.
> virtualenv venv > . ./venv/bin/activate > pip install -r requirements - Run the included setup script
> python setup_key_vault.py - Run the example. This uses an example schema and automatically encrypts an "ssn" field. AWS credentials are passed through environment variables.
> export AWS_REGION="us-east-1" > export AWS_ACCESS_KEY_ID="abc" > export AWS_SECRET_ACCESS_KEY="def" > python example.py Inserted and got back: {"ssn": "457-55-5642", "_id": {"$oid": "5c2a6f6e871516551fb90632"}, "name": "Todd Davis"} But 'ssn' is stored as encrypted data. Use mongo shell to see.
Setting the environment variable MONGOCRYPT_TRACE shows underlying tracing in libmongocrypt.
- mockupcryptd - a mock mongocryptd.
- libmongocrypt - a prototype C library for FLE. Communicates with KMS, mongocryptd, and does encryption.
- pymongocrypt a hacky Python wrapper around libmongocrypt.
- (coming soon) mockupkms