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

What's hot (19)

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

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
MongoDB
 
PPTX
Webinar: Schema Design
MongoDB
 
PPTX
Running Production MongoDB Lightning Talk
chrisckchang
 
PPTX
Dev Jumpstart: Schema Design Best Practices
MongoDB
 
PPTX
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
PDF
Awesome Tools 2017
Noel De Martin Fernandez
 
PDF
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
Horacio Gonzalez
 
PDF
MongoDB全機能解説2
Takahiro Inoue
 
PDF
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
Horacio Gonzalez
 
KEY
Schema Design with MongoDB
rogerbodamer
 
PPTX
Introduction to MongoDB
Algiers Tech Meetup
 
PDF
One BSON to Rule Them
David Golden
 
PPTX
Python With MongoDB in advanced Python.pptx
Ramakrishna Reddy Bijjam
 
PDF
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
PDF
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
PDF
MongoDB @ Frankfurt NoSql User Group
Chris Harris
 
PPTX
Back to Basics Webinar 3: Schema Design Thinking in Documents
MongoDB
 
PPTX
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
PDF
MongoD Essentials
zahid-mian
 
PPTX
Querying mongo db
Bogdan Sabău
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
Webinar: Schema Design
MongoDB
 
Running Production MongoDB Lightning Talk
chrisckchang
 
Dev Jumpstart: Schema Design Best Practices
MongoDB
 
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
Awesome Tools 2017
Noel De Martin Fernandez
 
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
Horacio Gonzalez
 
MongoDB全機能解説2
Takahiro Inoue
 
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
Horacio Gonzalez
 
Schema Design with MongoDB
rogerbodamer
 
Introduction to MongoDB
Algiers Tech Meetup
 
One BSON to Rule Them
David Golden
 
Python With MongoDB in advanced Python.pptx
Ramakrishna Reddy Bijjam
 
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
MongoDB @ Frankfurt NoSql User Group
Chris Harris
 
Back to Basics Webinar 3: Schema Design Thinking in Documents
MongoDB
 
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
MongoD Essentials
zahid-mian
 
Querying mongo db
Bogdan Sabău
 
Ad

More from Lisa Roth, PMP (10)

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

Recently uploaded (20)

PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
July Patch Tuesday
Ivanti
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 

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