SlideShare a Scribd company logo
#MDBlocal
Matthew Aylard
Using Client Side Encryption in MongoDB 4.2
LONDON
#MDBLocal
Introducing…
#MDBLocal
#MDBLocal
db.coll.insert({
_id: 1,
name: "Doris",
ssn: "457-55-5462"
})
#MDBLocal
#MDBLocal
doc = db.coll.find_one({
ssn: "457-55-5462"
})
#MDBLocal
#MDBLocal
print (doc)
#MDBLocal
{
_id: 1
name: "Doris",
ssn: "457-55-5462"
}
#MDBLocal
#MDBLocal
#MDBLocal
db.coll.insert({
name: "Doris",
ssn: "457-55-5462"
})
{
insert: "coll",
documents: [{
name: "Doris",
ssn: BinData(6, "a10x…")
}]
}
You see: MongoDB sees:
Encrypt before sending
#MDBLocal
{
_id: 1
name: "Doris",
ssn: BinData(6, "a10x…")
}
Driver receives: You see:
{
_id: 1
name: "Doris",
ssn: "457-55-5462"
}
Decrypt after receiving
#MDBLocal
How does this differ from…?
•… encryption in-transit (TLS)
•… encryption at-rest (encrypted storage engine)
#MDBLocal
Attacker
Query
Client
Disk
insert write
MongoDB
Auth
db.coll.insert({ name: "Doris", ssn: "457-55-5462" })
#MDBLocal
Client
Disk
insert write
MongoDB
Attacker
Snoop
TLS
db.coll.insert({ name: "Doris", ssn: "457-55-5462" })
#MDBLocal
Client
Disk
insert write
MongoDB
Attacker
insert
TLS
db.coll.insert({ name: "Doris", ssn: "457-55-5462" })
#MDBLocal
Client
Disk
insert write
MongoDB
Attacker
Steal
ESE
db.coll.insert({ name: "Doris", ssn: "457-55-5462" })
#MDBLocal
Client
Disk
insert write
MongoDB
Attacker
Login
Client Side Encryption
db.coll.insert({ name: "Doris", ssn: "457-55-5462" })
#MDBLocal
Client
Disk
insert write
MongoDB
Boundaries of unencrypted data
#MDBLocal
Client
Disk
insert write
MongoDB
… with Encrypted Storage Engine
#MDBLocal
Client
Disk
insert write
MongoDB
… and TLS
#MDBLocal
Client
Disk
insert write
MongoDB
with Client Side Encryption
#MDBLocal
#MDBLocal
Client
Disk
insert write
MongoDB
ssn: BinData(6, "a10x…")
#MDBLocal
db.coll.update({}, {
$set: { ssn: "457-55-5462" }
})
{
update: "coll",
updates: [{
q:{},
u: {
$set: { ssn: BinData(6, "a10x…") }
}
}]
}
You see: MongoDB sees:
Update that overwrites value
#MDBLocal
db.coll.aggregate([{
$project: { name_ssn: {$concat: [ "$name", " - ", "$ssn" ] } }
}]
Aggregate acting on the data
#MDBLocal
Find with equality query
* For deterministic encryption
db.coll.find({ssn: "457-55-5462" }) {
find: "coll",
filter: { ssn: BinData(6, "a10x…") }
}
You see: MongoDB sees:
#MDBLocal
Find with equality query
* For deterministic encryption
db.test.find(
{
$and: [
{
$or: [
{ ssn : { $in : [ "457-55-5462", "153-96-2097" ]} },
{ ssn: { $exists: false } }
]
},
{ name: "Doris" }
]
}
)
You see:
#MDBLocal
Find with equality query
* For deterministic encryption
MongoDB sees:
{
find: "coll",
filter: {
$and: [
{
$or: [
{ ssn : { $in : [ BinData(6, "a10x…"), BinData(6, "8dk1…") ]} },
{ ssn: { $exists: false } }
]
},
{ name: "Doris" }
]
}
}
#MDBLocal
MongoDB
Attacker
Login
#MDBLocal
#MDBLocal
#MDBLocal
Doris
Private stuff in storage
#MDBLocal
PoliceDoris
Private stuff in storage
#MDBLocal
Vault key
Held only by you
Vault
#MDBLocal
#MDBLocal
Encrypted Data
MongoDB
Encryption Key
#MDBLocal
#MDBLocal
{ _id: 1, ssn: BinData(0, "A81…"), name: "Kevin" }
{ _id: 2, ssn: BinData(0, "017…"), name: "Eric" }
{ _id: 3, ssn: BinData(0, "5E1…"), name: "Albert" }
…
#MDBLocal
#MDBLocal
Destroy the key
Provably delete all user data.
GDPR "right-to-be-forgotten"
#MDBLocal
#MDBLocal
client = MongoClient(
auto_encryption_opts=opts)
#MDBLocal
Not sensitive
{
#MDBLocal
One key for all vaults
#MDBLocal
One key per vault
#MDBLocal
{
name: "Doris"
ssn: "457-55-5462",
email: "Doris@gmail.com",
credit_card: "4690-6950-9373-8791",
comments: [ …. ],
avatar: BinData(0, "0fi8…"),
profile: { likes: {…}, dislikes: {…} }
}
#MDBLocal
#MDBLocal
#MDBLocal
Describes JSON
{
bsonType: "object",
properties: {
a: {
bsonType: "int"
maximum: 10
}
b: { bsonType: "string" }
},
required: ["a", "b"]
}
{
a: 5,
b: "hi"
}
{
a: 11,
b: false
}
JSON Schema
#MDBLocal
{
bsonType: "object",
properties: {
ssn: {
encrypt: { … }
}
},
required: ["ssn"]
}
JSON Schema "encrypt"
#MDBLocal
encrypt: {
keyId: <UUID[]> or <string>,
algorithm: <string>
bsonType: <string> or <string[]>
}
bsonType indicates the type of underlying data.
algorithm indicates how to encrypt (Random or Deterministic).
keyId indicates the key used to encrypt.
#MDBLocal
opts = AutoEncryptionOptions(
schema_map = { "db.coll": <schema> }
…)
Client side Schema
#MDBLocal
Remote Schema Fallback
db.createCollection("coll", { validator: { $jsonSchema: … } } )
Misconfigured
Client insert "457-55-5462"
error, that should be
encrypted
MongoDB
#MDBLocal
What if
… the server lies about the schema?
Misconfigured
Client insert "457-55-5462"
Evil MongoDB
ok :)
#MDBLocal
schema_map
Sub-options
#MDBLocal
#MDBLocal
Key vault
Key vault key
Held only by you
#MDBLocal
#MDBLocal
#MDBLocal
Stores encrypted keys
#MDBLocal
opts = AutoEncryptionOptions(
schema_map = { "db.coll": <schema> },
key_vault_namespace = "db.keyvault"
…)
#MDBLocal
schema_map
Sub-options
key_vault_namespace
#MDBLocal
What if
… attacker drops key vault collection?
#MDBLocal
Keep at home
opts = AutoEncryptionOptions(
schema_map = { "db.coll": <schema> },
key_vault_namespace = "db.keyvault",
key_vault_client = <client>
…)
#MDBLocal
schema_map
Sub-options
key_vault_namespace
key_vault_client
#MDBLocal
#MDBLocal
(Key Management Service)
#MDBLocal
Protects keys Stores keys
KMS
Key vault key
Key vault
Key vault
collection
#MDBLocal
Decryption requires
#MDBLocal
opts = AutoEncryptionOptions(
schema_map = { "db.coll": <schema> },
key_vault_namespace = "db.keys",
kms_providers = <creds>
…)
#MDBLocal
schema_map
Sub-options
key_vault_namespace
key_vault_client
kms_providers
#MDBLocal
#MDBLocal
db.coll.insert({
name: "Doris",
ssn: "457-55-5462"
})
Get encrypted key
Decrypt the key with KMSDecrypt the key with KMS
Encrypt 457-55-5462
Send insert
Compare to JSON schema
#MDBLocal
#MDBLocal
#MDBLocal
Authenticated Encryption with Associated Data using the
Advanced Encryption Standard (256) with Cipher Block Chaining
and Hashed-based Message Authentication Code using the Secure
Hash Algorithm (512).
#MDBLocal
AEAD_AES_256_CBC_HMAC_SHA_512
Provides confidentiality + integrity
#MDBLocal
AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic
AEAD_AES_256_CBC_HMAC_SHA_512-Random
#MDBLocal
coll.insert({ ssn: "457-55-5462" }) { ssn: BinData(6, "a10x…") }
You see: MongoDB stores:
coll.insert({ ssn: "457-55-5462" }) { ssn: BinData(6, "f991…") }
…Random
#MDBLocal
coll.insert({ ssn: "457-55-5462" }) { ssn: BinData(6, "a10x…") }
You see: MongoDB stores:
coll.insert({ ssn: "457-55-5462" }) { ssn: BinData(6, "a10x…") }
…Deterministic
#MDBLocal
Can be queried
doc = db.coll.find({
ssn: "457-55-5642"
})
{
find: "coll",
filter: { ssn: BinData(0, "a10x…") }
}
Driver sends:
{ ssn: BinData(6, "a10x…") }
MongoDB returns:
…Deterministic
#MDBLocal
Only for binary comparable types.
db.coll.find({ a: { b: 1.0 } })
{ a: { b: NumberInt(1) } }
{ a: { b: 1.0 } }
{ a: { b: NumberLong(1) } }
MongoDB returns:
…Deterministic
#MDBLocal
{ a: { b: NumberInt(1) } }
{ a: { b: 1.0 } }
{ a: { b: NumberLong(1) } }
{ a: BinData(6, "19d0…") }
{ a: BinData(6, "b515…") }
{ a: BinData(6, "801f…") }
Encrypted as:
#MDBLocal
db.coll.find({ a: { b: 1.0 } })
{ a: { b: 1.0 } }
MongoDB returns:
"a" encrypted
#MDBLocal
#MDBLocal
{ ssn: BinData(6, "AWNkTYTCw89Ss1DPzV3/2pSRDNGNJ9NB" }
New binary subtype
Older drivers and older MongoDB will treat as a black box.
#MDBLocal
byte algorithm
byte[16] key_id
byte original_bson_type
byte* payload
Ciphertext
#MDBLocal
byte algorithm
byte[16] key_id
byte original_bson_type
byte* payload
key_id + algorithm describes how to decrypt.
No JSON Schema necessary!
Ciphertext
#MDBLocal
byte algorithm
byte[16] key_id
byte original_bson_type
byte* payload
Provides extra server-side validation.
But prohibits single-value types (MinKey, MaxKey, Undefined, Null) and Boolean
Ciphertext
#MDBLocal
byte algorithm
byte[16] key_id
byte original_bson_type
byte* payload
Payload includes encoded IV and padding block, and HMAC.
Ciphertext adds between 66 to 82 bytes of overhead.
Ciphertext
#MDBLocal
#MDBLocal
{
_id: UUID(…)
keyAltNames: [ "mykey" ],
keyMaterial: BinData(0, "39aJ…"),
… (some metadata) …
}
> db.keyvault.find()
Identify
(Cached locally only in memory)
#MDBLocal
#MDBLocal
#MDBLocal
#MDBLocal
#MDBLocal
#MDBLocal
IMMORAL Authority
DICTATORLAND
Users
Global Shards
#MDBLocal
EAST
DICTATORLAND
#MDBLocal
EAST
DICTATORLAND
{ _id: 1, body: BinData(6, "A81…") }
{ _id: 2, body: BinData(6, "017…") }
{ _id: 3, body: BinData(6, "5E1…") }
…
#MDBLocal
Demo
THANK YOU
#MDBlocal
Using Client Side
Encryption in MongoDB 4.2
[DEV/OPS]
Matthew Aylard
https://www.surveymonkey.com/r/KFB3PDD
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2

More Related Content

PDF
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
PDF
MongoDB .local Chicago 2019: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
PDF
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
PDF
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
PDF
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
PDF
Blockchain Technologies for Data Science
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Chicago 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
Blockchain Technologies for Data Science

What's hot (19)

PPTX
MongoDB 3.2 - Analytics
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
PPTX
Powering Systems of Engagement
PDF
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
PPTX
MongoDB - Back to Basics - La tua prima Applicazione
PDF
MongoDB Performance Tuning
PDF
Javascript Object Signing & Encryption
PPTX
Back to Basics: My First MongoDB Application
PPTX
JOSE Can You See...
PDF
Deciphering Explain Output
PDF
Webinar: Building Your First App with MongoDB and Java
KEY
The Ruby/mongoDB ecosystem
PDF
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
KEY
Schema design
PPTX
Back to Basics Webinar 5: Introduction to the Aggregation Framework
PDF
MongoDB Launchpad 2016: What’s New in the 3.4 Server
PPTX
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
PPTX
Introduction to MongoDB
PPTX
Indexing Strategies to Help You Scale
MongoDB 3.2 - Analytics
Webinar: General Technical Overview of MongoDB for Dev Teams
Powering Systems of Engagement
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB - Back to Basics - La tua prima Applicazione
MongoDB Performance Tuning
Javascript Object Signing & Encryption
Back to Basics: My First MongoDB Application
JOSE Can You See...
Deciphering Explain Output
Webinar: Building Your First App with MongoDB and Java
The Ruby/mongoDB ecosystem
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
Schema design
Back to Basics Webinar 5: Introduction to the Aggregation Framework
MongoDB Launchpad 2016: What’s New in the 3.4 Server
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Introduction to MongoDB
Indexing Strategies to Help You Scale
Ad

Similar to MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2 (20)

PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local Bengaluru 2019: New Encryption Capabilities in MongoDB 4.2: A ...
PDF
Achieving compliance With MongoDB Security
PDF
MongodB Internals
PDF
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
PDF
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
PPTX
Hacking MongoDB at RelateIQ, A Salesforce Company
PDF
Building your first app with MongoDB
PPTX
Webinar: Architecting Secure and Compliant Applications with MongoDB
PPTX
Percona Live 2021 - MongoDB Security Features
PPTX
Dev Jumpstart: Build Your First App with MongoDB
PDF
MongoDB
PDF
MongoDB World 2019: New Encryption Capabilities in MongoDB 4.2: A Deep Dive i...
PPTX
introtomongodb
PPTX
Server discovery and monitoring with MongoDB
PPT
Webinar: Technical Introduction to Native Encryption on MongoDB
PDF
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
PPTX
Webinar: Securing your data - Mitigating the risks with MongoDB
PDF
MongoDB .local London 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
PPTX
lecture_34e.pptx
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Bengaluru 2019: New Encryption Capabilities in MongoDB 4.2: A ...
Achieving compliance With MongoDB Security
MongodB Internals
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Hacking MongoDB at RelateIQ, A Salesforce Company
Building your first app with MongoDB
Webinar: Architecting Secure and Compliant Applications with MongoDB
Percona Live 2021 - MongoDB Security Features
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
MongoDB World 2019: New Encryption Capabilities in MongoDB 4.2: A Deep Dive i...
introtomongodb
Server discovery and monitoring with MongoDB
Webinar: Technical Introduction to Native Encryption on MongoDB
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
Webinar: Securing your data - Mitigating the risks with MongoDB
MongoDB .local London 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
lecture_34e.pptx
Ad

More from Lisa Roth, PMP (10)

PPTX
MongoDB .local London 2019: New Product Announcements: MongoDB Atlas Autoscal...
PDF
MongoDB .local London 2019: Gaining ML insight on Google Cloud with Google Vi...
PDF
MongoDB .local London 2019: The Human Element in an Automated World: Building...
PDF
MongoDB .local London 2019: Diverse Representations in Design
PDF
MongoDB .local London 2019: Launch Re-entry! How to Return to the Technical W...
PDF
MongoDB .local London 2019: Using AWS to Transform Customer Data in MongoDB i...
PDF
MongoDB .local London 2019: Streaming Data on the Shoulders of Giants
PDF
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
PDF
MongoDB .local London 2019: Fast Machine Learning Development with MongoDB
PDF
MongoDB .local London 2019: A Complete Methodology to Data Modeling for MongoDB
MongoDB .local London 2019: New Product Announcements: MongoDB Atlas Autoscal...
MongoDB .local London 2019: Gaining ML insight on Google Cloud with Google Vi...
MongoDB .local London 2019: The Human Element in an Automated World: Building...
MongoDB .local London 2019: Diverse Representations in Design
MongoDB .local London 2019: Launch Re-entry! How to Return to the Technical W...
MongoDB .local London 2019: Using AWS to Transform Customer Data in MongoDB i...
MongoDB .local London 2019: Streaming Data on the Shoulders of Giants
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Fast Machine Learning Development with MongoDB
MongoDB .local London 2019: A Complete Methodology to Data Modeling for MongoDB

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Spectroscopy.pptx food analysis technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Understanding_Digital_Forensics_Presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
KodekX | Application Modernization Development
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectroscopy.pptx food analysis technology

MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2