SlideShare a Scribd company logo
Achieving Compliances with MongoDB
Security
Presented by
MADHU SAI VAVILALA
Associate DB Engineer
Mydbops
Agenda
➔ Importance of Data Security
➔ Security Triad (C.I.A)
➔ A.A.A.
➔ Data Encryption at Rest
➔ TLS & SSL
➔ CSFLE
➔ Queryable Encryption
➔ MongoDB Security Recommendations
History Of DataBase
➔ Ancient data storage techniques
◆ Examples: Cave painting, Stone crafting, Pen and Paper,
Punched cards
➔ Necessity of data storage devices
◆ To avoid drawback with traditional data storage
techniques
● Latency to get required data
● Less security
● Need more space to store
➔ First non-electronic storage device
◆ Punch cards in Jaccard machines
➔ The first 'real' electronic storage device in 1947 (Manchester
Mark I Williams-Kilburn tube)
Importance of Data Security
➔ Ransomware Attack on 22,000 DB’s in 2020
➔ Security less MongoDB instances 308,000 at Q1 2021
➔ Q1 of 2022, 12 % instances peaked in the list
➔ IOT - Security = Internet Of Threats
➔ “ Privacy is not a right, it is an absolute necessity. ”
➔ Data is a costlier assert
➔ Avoid illegal access
➔ Protect from data corruption
Data Security Triad (C.I.A)
➔ Confidentiality:
Protection of data against the
unauthorized user.
➔ Integrity:
Prevention of unauthorized and
improper data modification.
➔ Availability:
An authorized user can able to access
the data without any interruption.
Confidentiality
Integrity Availability
C
A
I
Data
Security
Triad
A.A.A
➔ Authentication
◆ Verify Identity of User
◆ Internal Authentication
◆ External Authentication
➔ Authorization
◆ Actions performed by the user
◆ Inbuilt Roles
◆ Customized Roles
➔ Auditing
◆ Logging the activities of a user
Auditing
A
u
t
h
e
n
t
i
c
a
t
i
o
n
A
u
t
h
o
r
i
z
a
t
i
o
n
A3
Security
Brief Info About MongoDB
➔ NoSql DataBase
➔ Schema less
➔ Document-oriented
➔ JSON structure
➔ Supports BSON structure
➔ Terminology b/w RDBMS and MongoDB
◆ Table = Collection
◆ Row = Document
◆ Column = Key
➔ Scalability
MongoDB
Authentication
➔ Purposes of Authentication
◆ Connect a valid user
◆ Verify the proof of user
◆ Safe from the attackers
➔ Authentication Mechanisms
◆ SCRAM (Default)
◆ x.509 Certificate
◆ LDAP
◆ Kerberos
Enable Authentication in MongoDB
➔ Start MongoDB without authentication option
in config file.
➔ Connect to the server using the mongo shell
➔ Create an administrator in the admin database
with a root access.
➔ Exit from the mongo shell.
➔ Restart the MongoDB after adding the
authentication option in MongoDB config file.
Methods To Authenticate User in MongoDB
❖ mongo "mongodb://User:Password@<host>:<port>/admin"
❖ mongo -u User -p Password --authenticationDatabase admin
❖ db.auth("User", "Password")
➔ Validate user, password and AuthDB.
➔ Check port number
➔ Verify the method of authentication mechanism.
Validations If Authentication Failed
Authentication with x.509 Mechanism
➔ Certificate based authentication Mechanism
➔ Use certificates instead of traditional username and pwd
➔ Provides both Internal and External Authentication
➔ x.509 Certificate need a secure TLS/SSL connection
➔ $external is the authenticationDatabase
➔ The subject of client certificate is added in the $external DB
➔ $external is having only user details
Configuration x.509 Mechanism
➔ Create a root CA file in PEM format
➔ Create a TLS/SSL certificate
➔ Edit the config file
➔ Get the subject of a client PEM certificate
◆ openssl x509 -inform PEM -subject
-in <Clent PEM file>
➔ Create a user with the above subject in
$external Database
net:
tls:
mode: requireTLS
CAFile: <path to root CA PEM file>
certificateKeyFile: < TLS/SSL key
PEM file>
URI: mongo --tls --tlsCertificateKeyFile <path to client PEM file>
--tlsCAFile <path to root CA PEM file> --authenticationDatabase
'$external' --authenticationMechanism MONGODB-X509
Authorization
➔ Given who you are, what can you do?
➔ Allows user to perform the specified actions.
➔ Advantage
◆ Improved efficiency.
➔ Role Based Access Control
◆ Provide access to the user based on the actions performed.
Why Role Based Access control ?
Developer Insert Data
DBA Create Users
Data Scientist Read Data
➔ Various users are perform different
actions
➔ No need to provide root access to
all users
➔ Never trust users
Roles in MongoDB
Role: A detailed object consists of Actions with
privileges performed on resources.
Actions: Performable Activities.
Resources: The data on which the User going
to do activities.
> use admin
> db.createRole(
{
role: "dropCollectionUser",
privileges: [
{
actions: [ "dropCollection" ],
resource: { db: "DB",
collection: "" }
}
],
roles: []
}
)
Built-In Roles in MongoDB
DataBase User
[ read, readWrite ]
DataBase Admin
[ dbAdmin, userAdmin, dbOwner ]
SuperUser
[ root ]
Cluster Admin
[ ClusterManager, ClusterMonitor,
hostManager, ClusterAdmin ]
BackUp/Restore
[ backup, restore ]
All Database
[ readAnyDatabase,
readWriteAnyDatabase ]
DEMO For Authentication &
Authentication
Key File Authentication
➔ Internal Authentication Mechanism
➔ Security between members of the
replica set
➔ Shared key for each member
➔ To use keyfile authentication we
need to create database admin
users
Host OS
Key File
Key
Challenge/
Response
Host OS
Key File
MongoDB
Host OS
Key File
MongoDB MongoDB
Key
Challenge/
Response
Key
Challenge/
Response
Steps to Configure KeyFile Authentication
➔ Create a Key file
◆ openssl rand -base64 756 > <path-to-keyfile>
◆ chmod 400 <path-to-keyfile>
➔ Copy the keyfile to each replica set member.
➔ Modify the config file in each mongodb replica
member.
◆ > vi /etc/mongod.conf
➔ Restart the mongod process.
◆ > systemctl restart mongod
security:
keyFile: <path-to-keyfile>
replication:
replSetName: <replicaSetName>
It’s Nice To Know. Is
There Any Feature
Available in MONGODB
For Monitoring The
Users Activities ?
Auditing in MongoDB
➔ Track system activity.
➔ Recording user, system, and
application activities.
➔ Audit information must be reviewed.
Auditing
Records
Authentication
And
Authorization
Replica set
And
Sharded Cluster
CRUD
Operations
➔ Add accountability.
➔ Instigate Suspesious Activity.
➔ Monitor dataBase Activity.
Advantages
➔ Yaml Format.
➔ Feature included in the MongoDB Enterprise Only.
➔ compressionMode
◆ none (default)
◆ zstd
➔ destination
◆ file
◆ syslog
◆ console
➔ format
◆ JSON
◆ BSON
➔ path
◆ File Location
Configure File Options for Auditing
auditLog:
compressionMode: <string>
destination: <string>
format: <string>
path: <string>
filter: <string>
➔ Filter limit the types of operations
➔ Use Query selectors
➔ Allows regular Expressions
➔ Syntax
filter: { <field>: <expression1> }
Filter Option In Auditing
filter:{
atype: "authCheck",
"param.command":{
$in: [ "find", "insert", "delete", "update",
"findandmodify"]}
},
auditAuthorizationSuccess: true
All
Operations
Filtered
Operations
Stored to
Destination
File
Example
Audit Message Structure
{
atype: <string>, # Action type
ts : { $date: <timestamp> },
uuid : { $binary: <string>, $type: <string> },
local: { ip: <string>, port: <int> || isSystemUser: <boolean> || unix:
<string> },
remote: { ip: <string>, port: <int> || isSystemUser: <boolean> || unix:
<string> },
users : [ { user: <string>, db: <string> }, ... ],
roles: [ { role: <string>, db: <string> }, ... ],
param: <document>,
result: <int>
}
Versions vs Features
➔ Available from 2.6v
➔ MongoDB Enterprise and Atlas
➔ Filter option available from 3.0v
➔ Starting 5.0 a feature available that runtime audit configuration
and filter management.
➔ Starting 5.0 a UUID is added to the audit message.
➔ 5.3v auditLog.compressionMode → used to compress audit log.
➔ 6.0v onwards audit log encryption is available.
Achieving Auditing Feature with Community
➔ Percona server for MongoDB
➔ All features are same with MongoDB Enterprise
server
➔ Only Difference is UUID is not added in percona
MongoDB
➔ Free of cost
Even if the Data is
Locked by the
Users with PWD, Is
the data really safe
Data Encryption
➔ A mechanism that Protects the Data
➔ An information is converted into cipher Text
➔ Hides the exact Meaning
➔ Only authorized parties can understand
MongoDB involves three types of data:
➔ Data at rest
➔ Data in transit
➔ Data in use
Base Of Encryption
Science Mathematics
Cryptography
Encryption
Science ∩ Mathematics = Cryptography
Encryption ⊆ Cryptography
Key
PlainText CryptoAnalysis
Ciphertext
Terminology
Crypto = Secret
Graphy = Write
Data Encryption at Rest
➔ WiredTiger storage engine have native encryption.
➔ cipher algorithm i.e AES256-GCM
➔ This cipher algorithm support for linux.
➔ Involve symmetric key
➔ Options for sourcing master key
◆ Via 3rd party Key Management Appliance using KMIP
(Key Management Interoperability Protocol )
◆ Keyfile on local system (Not recommendable)
➔ Use unique individual keys for every node in a replica set.
Configure Data Encryption At Rest on Community
➔ Create a key file
◆ Base64 and 16 or 32 characters
➔ Edit the config file
➔ Add the encryption options
➔ Restart the mongod
security:
enableEncryption: true
encryptionKeyFile: <Certificate file>
encryptionCipherMode: "AES256-GCM"
{"t":{"$date":"2022-11-21T09:39:37.741+00:00"},"s":"I", "c":"STORAGE", "id":29039,
"ctx":"initandlisten","msg":"Encryption keys DB is initialized successfully"}
Validate
Configuring Steps
Note: It is configured in the percona mongo
grep "Encryption" < log file >
Ok!! Now the data is
safe at rest.
But what about
safety while Transit ?
Encrypting Data in Transit
Data is transacted through
➔ Transport Layer Security (TLS)
➔ Secure Socket Layer (SSL)
TLS/SSL are uses Certificates
➔ PEM files
➔ Issued by the certificate authority
➔ Self-signed certificate
Configure TSL/SSL and Connecting
➔ Create CA file
➔ Create PEM key file
➔ Edit the config file
➔ Add the TLS options
➔ Restart the mongod
net:
tls:
mode: requireSSL
PEMKeyFile: <pem file>
CAFile: <Certificate file>
mongo --tls --tlsPEMKeyFile <pem file> --tlsCAFile <CA file> --host
<host name>
Connection URI
Configuring Steps
A sample Demo To Implement Transit
Encryption with Percona MongoDB
Ok!! Good !
Now the data is safe
at transit.
But what about
safety while Using ?
Client Side Field Level Encryption
➔ Simple Definition
◆ The Client will deal with Encryption and
Decryption of Data using a secure key.
◆ Selectively encrypt individual document
fields.
◆ End-to-end encryption
Doctor’s prescription saves the life of patient, Same
way the Encryptions saves the information from
the data breaches.
Why CSFLE Is Important ?
➔ In-flight encryption protects all data traversing the network.
◆ But does not encrypt data in-memory or at-rest.
➔ At-rest encryption protects all stored data.
◆ But does not encrypt data in-memory or in-flight.
➔ With client-side encryption, the most sensitive data never
leaves applications in plain text.
➔ All encrypted fields on the client-side remain encrypted over
◆ stored in-memory,
◆ in system logs, at-rest,
◆ in backups – are rendered as ciphertext
Keys Involved
➔ Customer Master Key
◆ A root key
◆ Used to Encrypt or Decrypt the DEK
◆ Must be secured with KMS
➔ The Data Encryption Key
◆ A key generated by libmongocrypt
◆ Encrypted using the CMK
◆ Used to encrypt and decrypt data.
This Strategy is based on Envelope Encryption.
Process Of FLE
User
KMS
MongoDB Driver
MongoDB
MongoDB Server
1
2 3
4
5
6
db.coll.find({
Pin: “123”
}) Encrypted Search Key:“***”
{ Name: ‘A’,
age: 16
Pin: “***” }
{
Name: ‘A’,
age: 16
Pin: “123”
}
Process Of FLE
➔ When the application submits the query, the MongoDB driver first
analyzes it to determine if any encrypted fields are involved in the filter.
➔ Recognizing that the query is against an encrypted field, the driver
requests the field's encryption key from the external key manager.
➔ The key manager returns the keys to the MongoDB driver, which then
encrypts the queired field.
➔ The driver submits the query to the MongoDB server with the encrypted
fields rendered as ciphertext.
➔ The MongoDB server returns the encrypted results of the query to the
driver.
➔ The query results are decrypted with the keys held by the driver, and
returned to the authenticated client as readable plaintext.
Availability of CSFLE
➔ Versions: 4.2v +
➔ Divers: 20 + platforms of multiple languages (Node. Js, C, C#,
Python, Java etc.)
➔ Automatic Encryption: MongoDB Atlas and Enterprise versions.
➔ Manual Encryption: MongoDB Atlas and Enterprise versions
and community versions
Configure CSFLE on MongoDB Community
➔ Create a key file i.e CMK
➔ Assine the CMK value to LOCAL_KEY variable
➔ Frame ClientSideFieldLevelEncryptionOptions
➔ Connect to the mongo with above options
➔ Creation of Data Encryption Key
➔ Insert a document and encrypt the any field with
encrypt() function.
Configuring Steps
A sample Demo To Implement CSFLE
with MongoDB Community Server
The data field is encrypted,
well and Good. Then How
to query on the particular
Field even it is having less
cardinality ?
Queryable Encryption
➔ Allows user to search their data while it remains encrypted
➔ Data remains encrypted at insert, storage, and query.
➔ A Public Preview Feature
➔ Not recommended for production
Magical Features of Queryable Encryption
➔ Fully randomized encryption
➔ Expressive queries on encrypted data
➔ Client-side encryption
➔ Customer-managed encryption keys
➔ Industry standard cryptography primitives
➔ Field-level encryption
Scope of Necessity For QE
With the proliferation of different types of data being transmitted and stored in
the cloud, protecting data is increasingly important for companies.
➔ Bank Applications
➔ Stock brokerage firm
➔ Hospitals
➔ Human Resources
➔ Government Applications
➔ E-commerce applications etc.
Encrypted Collection Management
Queryable Encryption uses four data structures:
➔ Three metadata collections
When you create an encrypted collection using Queryable Encryption,
MongoDB creates three metadata collections:
● enxcol_.<collectionName>.esc, referred to as ESC
● enxcol_.<collectionName>.ecc, referred to as ECC
● enxcol_.<collectionName>.ecoc, referred to as ECOC
➔ A field in every document in the encrypted collection called __safeContent__
Note: It is critical that these data structures are not modified or deleted.
Write Operations Vs Metadata Collections
When writing a document, each indexed field requires writes to metadata
collections along with one write on the encrypted collection.
Operation ESC ECC ECOC
Insert 1 0 1
Update 1 1 2
Delete 0 1 1
Storage Issue with QE
➔ 2x or 3x times extra storage
➔ Depends on the number of indexed fields per document
➔ For every write Associated metadata collections will
update
IndexCompaction
➔ A process that prunes the metadata collections
➔ Should run when the size of ECOC exceeds 1 GB.
➔ To run index compaction,
db.collection.compactStructuredEncryptionData()
Availability of Queryable Encryption
➔ Versions: 6.0v
➔ Divers: 20 + platforms of multiple languages (Node.Js, C, C#,
Python, Java etc.)
➔ Automatic Encryption: MongoDB Atlas and Enterprise versions.
➔ Manual Encryption: MongoDB Atlas and Enterprise versions
and community versions.
Limitations of QE:
➔ Fully randomized encryption
➔ Manually create a unique Data Encryption Key for each field
➔ Manually run index compaction
➔ Standalone deployments are not supported
➔ Secondary reads are not supported
➔ Encrypted field names are immutable.
➔ Ignores collations
➔ Unique indexes and TTl indexes are not supported.
➔ Don’t support Views, Time Series Collections, or capped collection.
➔ Can’t encrypt _Id
Encryption Performance in MongoDB
➔ Data size α Latency
➔ Consider High load condition
◆ Writes 10% to 20% latency
◆ Reads < 5% (negligible)
➔ Encrypting and decrypting require more resources
➔ WiredTiger storage engine is more suitable. Because
◆ Page level encryption
◆ Throughput operations performs on the exact page only
◆ High performance, scalability, and security
MongoDB Security Recommendations
➔ Don’t directly expose the DB servers to the internet
➔ Avoid using the default port
➔ Use strong passwords
➔ Authenticate with db.auth()
➔ Never use the security.transitionToAuth option in config file.
➔ Limit the user actions, Use customized roles.
➔ Maintain data encryption.
Any
Queries
More questions and queries
info@mydbops.com
THANK YOU

More Related Content

What's hot (20)

PDF
Cassandra Introduction & Features
DataStax Academy
 
PDF
MongoDB Sharding Fundamentals
Antonios Giannopoulos
 
PDF
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Mydbops
 
PDF
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
PDF
BlueStore, A New Storage Backend for Ceph, One Year In
Sage Weil
 
PDF
Découverte de Elastic search
JEMLI Fathi
 
PDF
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
PostgreSQL-Consulting
 
PDF
MySQL Data Encryption at Rest
Mydbops
 
PDF
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB
 
PDF
Top-10-Features-In-MySQL-8.0 - Vinoth Kanna RS - Mydbops Team
Mydbops
 
PDF
InnoDB MVCC Architecture (by 권건우)
I Goo Lee.
 
PPTX
JSON improvements in MySQL 8.0
Mydbops
 
PDF
Introduction to MongoDB
Mike Dirolf
 
PDF
The MySQL Query Optimizer Explained Through Optimizer Trace
oysteing
 
PDF
Simplify CDC Pipeline with Spark Streaming SQL and Delta Lake
Databricks
 
PPTX
Mysql data replication
Tuấn Ngô
 
PPTX
Webinar: MongoDB Schema Design and Performance Implications
MongoDB
 
PPTX
Redis introduction
Federico Daniel Colombo Gennarelli
 
PDF
Better than you think: Handling JSON data in ClickHouse
Altinity Ltd
 
PDF
Introduction à ElasticSearch
Fadel Chafai
 
Cassandra Introduction & Features
DataStax Academy
 
MongoDB Sharding Fundamentals
Antonios Giannopoulos
 
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Mydbops
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
BlueStore, A New Storage Backend for Ceph, One Year In
Sage Weil
 
Découverte de Elastic search
JEMLI Fathi
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
PostgreSQL-Consulting
 
MySQL Data Encryption at Rest
Mydbops
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB
 
Top-10-Features-In-MySQL-8.0 - Vinoth Kanna RS - Mydbops Team
Mydbops
 
InnoDB MVCC Architecture (by 권건우)
I Goo Lee.
 
JSON improvements in MySQL 8.0
Mydbops
 
Introduction to MongoDB
Mike Dirolf
 
The MySQL Query Optimizer Explained Through Optimizer Trace
oysteing
 
Simplify CDC Pipeline with Spark Streaming SQL and Delta Lake
Databricks
 
Mysql data replication
Tuấn Ngô
 
Webinar: MongoDB Schema Design and Performance Implications
MongoDB
 
Better than you think: Handling JSON data in ClickHouse
Altinity Ltd
 
Introduction à ElasticSearch
Fadel Chafai
 

Similar to Achieving compliance With MongoDB Security (20)

PPTX
Percona Live 2021 - MongoDB Security Features
Jean Da Silva
 
PDF
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
MongoDB
 
PPTX
Low Hanging Fruit, Making Your Basic MongoDB Installation More Secure
MongoDB
 
PDF
MongoDB .local Bengaluru 2019: New Encryption Capabilities in MongoDB 4.2: A ...
MongoDB
 
PPTX
Securing Your Enterprise Web Apps with MongoDB Enterprise
MongoDB
 
PPTX
Securing MongoDB to Serve an AWS-Based, Multi-Tenant, Security-Fanatic SaaS A...
MongoDB
 
PDF
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
PPTX
Eagle6 mongo dc revised
MongoDB
 
PPTX
Eagle6 Enterprise Situational Awareness
MongoDB
 
PPTX
Webinar: Securing your data - Mitigating the risks with MongoDB
MongoDB
 
PPTX
Webinar: Compliance and Data Protection in the Big Data Age: MongoDB Security...
MongoDB
 
PDF
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
cgmonroe
 
PDF
Engineering an Encrypted Storage Engine
MongoDB
 
PPTX
Securing Your Deployment with MongoDB and Red Hat's Identity Management in Re...
MongoDB
 
PPTX
Document Validation in MongoDB 3.2
MongoDB
 
PPTX
MongoDB World 2018: Low Hanging Fruit: Making Your Basic MongoDB Installation...
MongoDB
 
PPTX
K8s best practices from the field!
DoiT International
 
PDF
MongoDB World 2019: New Encryption Capabilities in MongoDB 4.2: A Deep Dive i...
MongoDB
 
PPTX
Mojo – Simple REST Server
hendrikvb
 
PDF
Digital Forensics and Incident Response in The Cloud Part 3
Velocidex Enterprises
 
Percona Live 2021 - MongoDB Security Features
Jean Da Silva
 
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
MongoDB
 
Low Hanging Fruit, Making Your Basic MongoDB Installation More Secure
MongoDB
 
MongoDB .local Bengaluru 2019: New Encryption Capabilities in MongoDB 4.2: A ...
MongoDB
 
Securing Your Enterprise Web Apps with MongoDB Enterprise
MongoDB
 
Securing MongoDB to Serve an AWS-Based, Multi-Tenant, Security-Fanatic SaaS A...
MongoDB
 
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
Eagle6 mongo dc revised
MongoDB
 
Eagle6 Enterprise Situational Awareness
MongoDB
 
Webinar: Securing your data - Mitigating the risks with MongoDB
MongoDB
 
Webinar: Compliance and Data Protection in the Big Data Age: MongoDB Security...
MongoDB
 
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
cgmonroe
 
Engineering an Encrypted Storage Engine
MongoDB
 
Securing Your Deployment with MongoDB and Red Hat's Identity Management in Re...
MongoDB
 
Document Validation in MongoDB 3.2
MongoDB
 
MongoDB World 2018: Low Hanging Fruit: Making Your Basic MongoDB Installation...
MongoDB
 
K8s best practices from the field!
DoiT International
 
MongoDB World 2019: New Encryption Capabilities in MongoDB 4.2: A Deep Dive i...
MongoDB
 
Mojo – Simple REST Server
hendrikvb
 
Digital Forensics and Incident Response in The Cloud Part 3
Velocidex Enterprises
 
Ad

More from Mydbops (20)

PDF
Scaling TiDB for Large-Scale Application
Mydbops
 
PDF
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 
PDF
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mydbops
 
PDF
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Mydbops
 
PDF
AWS Blue Green Deployment for Databases - Mydbops
Mydbops
 
PDF
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
Mydbops
 
PDF
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
Mydbops
 
PDF
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Mydbops
 
PDF
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
PDF
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Mydbops
 
PDF
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
Mydbops
 
PDF
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
PDF
Demystifying Real time Analytics with TiDB
Mydbops
 
PDF
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
PDF
Efficient MySQL Indexing and what's new in MySQL Explain
Mydbops
 
PDF
Scale your database traffic with Read & Write split using MySQL Router
Mydbops
 
PDF
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Mydbops
 
PDF
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mydbops
 
PDF
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mydbops
 
PDF
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Mydbops
 
Scaling TiDB for Large-Scale Application
Mydbops
 
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mydbops
 
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Mydbops
 
AWS Blue Green Deployment for Databases - Mydbops
Mydbops
 
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
Mydbops
 
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
Mydbops
 
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Mydbops
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Mydbops
 
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
Mydbops
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
Demystifying Real time Analytics with TiDB
Mydbops
 
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Efficient MySQL Indexing and what's new in MySQL Explain
Mydbops
 
Scale your database traffic with Read & Write split using MySQL Router
Mydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mydbops
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Mydbops
 
Ad

Recently uploaded (20)

PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PPT
Testing and final inspection of a solar PV system
MuhammadSanni2
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPTX
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
Testing and final inspection of a solar PV system
MuhammadSanni2
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Distribution reservoir and service storage pptx
dhanashree78
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 

Achieving compliance With MongoDB Security

  • 1. Achieving Compliances with MongoDB Security Presented by MADHU SAI VAVILALA Associate DB Engineer Mydbops
  • 2. Agenda ➔ Importance of Data Security ➔ Security Triad (C.I.A) ➔ A.A.A. ➔ Data Encryption at Rest ➔ TLS & SSL ➔ CSFLE ➔ Queryable Encryption ➔ MongoDB Security Recommendations
  • 3. History Of DataBase ➔ Ancient data storage techniques ◆ Examples: Cave painting, Stone crafting, Pen and Paper, Punched cards ➔ Necessity of data storage devices ◆ To avoid drawback with traditional data storage techniques ● Latency to get required data ● Less security ● Need more space to store ➔ First non-electronic storage device ◆ Punch cards in Jaccard machines ➔ The first 'real' electronic storage device in 1947 (Manchester Mark I Williams-Kilburn tube)
  • 4. Importance of Data Security ➔ Ransomware Attack on 22,000 DB’s in 2020 ➔ Security less MongoDB instances 308,000 at Q1 2021 ➔ Q1 of 2022, 12 % instances peaked in the list ➔ IOT - Security = Internet Of Threats ➔ “ Privacy is not a right, it is an absolute necessity. ” ➔ Data is a costlier assert ➔ Avoid illegal access ➔ Protect from data corruption
  • 5. Data Security Triad (C.I.A) ➔ Confidentiality: Protection of data against the unauthorized user. ➔ Integrity: Prevention of unauthorized and improper data modification. ➔ Availability: An authorized user can able to access the data without any interruption. Confidentiality Integrity Availability C A I Data Security Triad
  • 6. A.A.A ➔ Authentication ◆ Verify Identity of User ◆ Internal Authentication ◆ External Authentication ➔ Authorization ◆ Actions performed by the user ◆ Inbuilt Roles ◆ Customized Roles ➔ Auditing ◆ Logging the activities of a user Auditing A u t h e n t i c a t i o n A u t h o r i z a t i o n A3 Security
  • 7. Brief Info About MongoDB ➔ NoSql DataBase ➔ Schema less ➔ Document-oriented ➔ JSON structure ➔ Supports BSON structure ➔ Terminology b/w RDBMS and MongoDB ◆ Table = Collection ◆ Row = Document ◆ Column = Key ➔ Scalability MongoDB
  • 8. Authentication ➔ Purposes of Authentication ◆ Connect a valid user ◆ Verify the proof of user ◆ Safe from the attackers ➔ Authentication Mechanisms ◆ SCRAM (Default) ◆ x.509 Certificate ◆ LDAP ◆ Kerberos
  • 9. Enable Authentication in MongoDB ➔ Start MongoDB without authentication option in config file. ➔ Connect to the server using the mongo shell ➔ Create an administrator in the admin database with a root access. ➔ Exit from the mongo shell. ➔ Restart the MongoDB after adding the authentication option in MongoDB config file.
  • 10. Methods To Authenticate User in MongoDB ❖ mongo "mongodb://User:Password@<host>:<port>/admin" ❖ mongo -u User -p Password --authenticationDatabase admin ❖ db.auth("User", "Password") ➔ Validate user, password and AuthDB. ➔ Check port number ➔ Verify the method of authentication mechanism. Validations If Authentication Failed
  • 11. Authentication with x.509 Mechanism ➔ Certificate based authentication Mechanism ➔ Use certificates instead of traditional username and pwd ➔ Provides both Internal and External Authentication ➔ x.509 Certificate need a secure TLS/SSL connection ➔ $external is the authenticationDatabase ➔ The subject of client certificate is added in the $external DB ➔ $external is having only user details
  • 12. Configuration x.509 Mechanism ➔ Create a root CA file in PEM format ➔ Create a TLS/SSL certificate ➔ Edit the config file ➔ Get the subject of a client PEM certificate ◆ openssl x509 -inform PEM -subject -in <Clent PEM file> ➔ Create a user with the above subject in $external Database net: tls: mode: requireTLS CAFile: <path to root CA PEM file> certificateKeyFile: < TLS/SSL key PEM file> URI: mongo --tls --tlsCertificateKeyFile <path to client PEM file> --tlsCAFile <path to root CA PEM file> --authenticationDatabase '$external' --authenticationMechanism MONGODB-X509
  • 13. Authorization ➔ Given who you are, what can you do? ➔ Allows user to perform the specified actions. ➔ Advantage ◆ Improved efficiency. ➔ Role Based Access Control ◆ Provide access to the user based on the actions performed.
  • 14. Why Role Based Access control ? Developer Insert Data DBA Create Users Data Scientist Read Data ➔ Various users are perform different actions ➔ No need to provide root access to all users ➔ Never trust users
  • 15. Roles in MongoDB Role: A detailed object consists of Actions with privileges performed on resources. Actions: Performable Activities. Resources: The data on which the User going to do activities. > use admin > db.createRole( { role: "dropCollectionUser", privileges: [ { actions: [ "dropCollection" ], resource: { db: "DB", collection: "" } } ], roles: [] } )
  • 16. Built-In Roles in MongoDB DataBase User [ read, readWrite ] DataBase Admin [ dbAdmin, userAdmin, dbOwner ] SuperUser [ root ] Cluster Admin [ ClusterManager, ClusterMonitor, hostManager, ClusterAdmin ] BackUp/Restore [ backup, restore ] All Database [ readAnyDatabase, readWriteAnyDatabase ]
  • 17. DEMO For Authentication & Authentication
  • 18. Key File Authentication ➔ Internal Authentication Mechanism ➔ Security between members of the replica set ➔ Shared key for each member ➔ To use keyfile authentication we need to create database admin users Host OS Key File Key Challenge/ Response Host OS Key File MongoDB Host OS Key File MongoDB MongoDB Key Challenge/ Response Key Challenge/ Response
  • 19. Steps to Configure KeyFile Authentication ➔ Create a Key file ◆ openssl rand -base64 756 > <path-to-keyfile> ◆ chmod 400 <path-to-keyfile> ➔ Copy the keyfile to each replica set member. ➔ Modify the config file in each mongodb replica member. ◆ > vi /etc/mongod.conf ➔ Restart the mongod process. ◆ > systemctl restart mongod security: keyFile: <path-to-keyfile> replication: replSetName: <replicaSetName>
  • 20. It’s Nice To Know. Is There Any Feature Available in MONGODB For Monitoring The Users Activities ?
  • 21. Auditing in MongoDB ➔ Track system activity. ➔ Recording user, system, and application activities. ➔ Audit information must be reviewed. Auditing Records Authentication And Authorization Replica set And Sharded Cluster CRUD Operations ➔ Add accountability. ➔ Instigate Suspesious Activity. ➔ Monitor dataBase Activity. Advantages
  • 22. ➔ Yaml Format. ➔ Feature included in the MongoDB Enterprise Only. ➔ compressionMode ◆ none (default) ◆ zstd ➔ destination ◆ file ◆ syslog ◆ console ➔ format ◆ JSON ◆ BSON ➔ path ◆ File Location Configure File Options for Auditing auditLog: compressionMode: <string> destination: <string> format: <string> path: <string> filter: <string>
  • 23. ➔ Filter limit the types of operations ➔ Use Query selectors ➔ Allows regular Expressions ➔ Syntax filter: { <field>: <expression1> } Filter Option In Auditing filter:{ atype: "authCheck", "param.command":{ $in: [ "find", "insert", "delete", "update", "findandmodify"]} }, auditAuthorizationSuccess: true All Operations Filtered Operations Stored to Destination File Example
  • 24. Audit Message Structure { atype: <string>, # Action type ts : { $date: <timestamp> }, uuid : { $binary: <string>, $type: <string> }, local: { ip: <string>, port: <int> || isSystemUser: <boolean> || unix: <string> }, remote: { ip: <string>, port: <int> || isSystemUser: <boolean> || unix: <string> }, users : [ { user: <string>, db: <string> }, ... ], roles: [ { role: <string>, db: <string> }, ... ], param: <document>, result: <int> }
  • 25. Versions vs Features ➔ Available from 2.6v ➔ MongoDB Enterprise and Atlas ➔ Filter option available from 3.0v ➔ Starting 5.0 a feature available that runtime audit configuration and filter management. ➔ Starting 5.0 a UUID is added to the audit message. ➔ 5.3v auditLog.compressionMode → used to compress audit log. ➔ 6.0v onwards audit log encryption is available.
  • 26. Achieving Auditing Feature with Community ➔ Percona server for MongoDB ➔ All features are same with MongoDB Enterprise server ➔ Only Difference is UUID is not added in percona MongoDB ➔ Free of cost
  • 27. Even if the Data is Locked by the Users with PWD, Is the data really safe
  • 28. Data Encryption ➔ A mechanism that Protects the Data ➔ An information is converted into cipher Text ➔ Hides the exact Meaning ➔ Only authorized parties can understand MongoDB involves three types of data: ➔ Data at rest ➔ Data in transit ➔ Data in use
  • 29. Base Of Encryption Science Mathematics Cryptography Encryption Science ∩ Mathematics = Cryptography Encryption ⊆ Cryptography Key PlainText CryptoAnalysis Ciphertext Terminology Crypto = Secret Graphy = Write
  • 30. Data Encryption at Rest ➔ WiredTiger storage engine have native encryption. ➔ cipher algorithm i.e AES256-GCM ➔ This cipher algorithm support for linux. ➔ Involve symmetric key ➔ Options for sourcing master key ◆ Via 3rd party Key Management Appliance using KMIP (Key Management Interoperability Protocol ) ◆ Keyfile on local system (Not recommendable) ➔ Use unique individual keys for every node in a replica set.
  • 31. Configure Data Encryption At Rest on Community ➔ Create a key file ◆ Base64 and 16 or 32 characters ➔ Edit the config file ➔ Add the encryption options ➔ Restart the mongod security: enableEncryption: true encryptionKeyFile: <Certificate file> encryptionCipherMode: "AES256-GCM" {"t":{"$date":"2022-11-21T09:39:37.741+00:00"},"s":"I", "c":"STORAGE", "id":29039, "ctx":"initandlisten","msg":"Encryption keys DB is initialized successfully"} Validate Configuring Steps Note: It is configured in the percona mongo grep "Encryption" < log file >
  • 32. Ok!! Now the data is safe at rest. But what about safety while Transit ?
  • 33. Encrypting Data in Transit Data is transacted through ➔ Transport Layer Security (TLS) ➔ Secure Socket Layer (SSL) TLS/SSL are uses Certificates ➔ PEM files ➔ Issued by the certificate authority ➔ Self-signed certificate
  • 34. Configure TSL/SSL and Connecting ➔ Create CA file ➔ Create PEM key file ➔ Edit the config file ➔ Add the TLS options ➔ Restart the mongod net: tls: mode: requireSSL PEMKeyFile: <pem file> CAFile: <Certificate file> mongo --tls --tlsPEMKeyFile <pem file> --tlsCAFile <CA file> --host <host name> Connection URI Configuring Steps
  • 35. A sample Demo To Implement Transit Encryption with Percona MongoDB
  • 36. Ok!! Good ! Now the data is safe at transit. But what about safety while Using ?
  • 37. Client Side Field Level Encryption ➔ Simple Definition ◆ The Client will deal with Encryption and Decryption of Data using a secure key. ◆ Selectively encrypt individual document fields. ◆ End-to-end encryption Doctor’s prescription saves the life of patient, Same way the Encryptions saves the information from the data breaches.
  • 38. Why CSFLE Is Important ? ➔ In-flight encryption protects all data traversing the network. ◆ But does not encrypt data in-memory or at-rest. ➔ At-rest encryption protects all stored data. ◆ But does not encrypt data in-memory or in-flight. ➔ With client-side encryption, the most sensitive data never leaves applications in plain text. ➔ All encrypted fields on the client-side remain encrypted over ◆ stored in-memory, ◆ in system logs, at-rest, ◆ in backups – are rendered as ciphertext
  • 39. Keys Involved ➔ Customer Master Key ◆ A root key ◆ Used to Encrypt or Decrypt the DEK ◆ Must be secured with KMS ➔ The Data Encryption Key ◆ A key generated by libmongocrypt ◆ Encrypted using the CMK ◆ Used to encrypt and decrypt data. This Strategy is based on Envelope Encryption.
  • 40. Process Of FLE User KMS MongoDB Driver MongoDB MongoDB Server 1 2 3 4 5 6 db.coll.find({ Pin: “123” }) Encrypted Search Key:“***” { Name: ‘A’, age: 16 Pin: “***” } { Name: ‘A’, age: 16 Pin: “123” }
  • 41. Process Of FLE ➔ When the application submits the query, the MongoDB driver first analyzes it to determine if any encrypted fields are involved in the filter. ➔ Recognizing that the query is against an encrypted field, the driver requests the field's encryption key from the external key manager. ➔ The key manager returns the keys to the MongoDB driver, which then encrypts the queired field. ➔ The driver submits the query to the MongoDB server with the encrypted fields rendered as ciphertext. ➔ The MongoDB server returns the encrypted results of the query to the driver. ➔ The query results are decrypted with the keys held by the driver, and returned to the authenticated client as readable plaintext.
  • 42. Availability of CSFLE ➔ Versions: 4.2v + ➔ Divers: 20 + platforms of multiple languages (Node. Js, C, C#, Python, Java etc.) ➔ Automatic Encryption: MongoDB Atlas and Enterprise versions. ➔ Manual Encryption: MongoDB Atlas and Enterprise versions and community versions
  • 43. Configure CSFLE on MongoDB Community ➔ Create a key file i.e CMK ➔ Assine the CMK value to LOCAL_KEY variable ➔ Frame ClientSideFieldLevelEncryptionOptions ➔ Connect to the mongo with above options ➔ Creation of Data Encryption Key ➔ Insert a document and encrypt the any field with encrypt() function. Configuring Steps
  • 44. A sample Demo To Implement CSFLE with MongoDB Community Server
  • 45. The data field is encrypted, well and Good. Then How to query on the particular Field even it is having less cardinality ?
  • 46. Queryable Encryption ➔ Allows user to search their data while it remains encrypted ➔ Data remains encrypted at insert, storage, and query. ➔ A Public Preview Feature ➔ Not recommended for production Magical Features of Queryable Encryption ➔ Fully randomized encryption ➔ Expressive queries on encrypted data ➔ Client-side encryption ➔ Customer-managed encryption keys ➔ Industry standard cryptography primitives ➔ Field-level encryption
  • 47. Scope of Necessity For QE With the proliferation of different types of data being transmitted and stored in the cloud, protecting data is increasingly important for companies. ➔ Bank Applications ➔ Stock brokerage firm ➔ Hospitals ➔ Human Resources ➔ Government Applications ➔ E-commerce applications etc.
  • 48. Encrypted Collection Management Queryable Encryption uses four data structures: ➔ Three metadata collections When you create an encrypted collection using Queryable Encryption, MongoDB creates three metadata collections: ● enxcol_.<collectionName>.esc, referred to as ESC ● enxcol_.<collectionName>.ecc, referred to as ECC ● enxcol_.<collectionName>.ecoc, referred to as ECOC ➔ A field in every document in the encrypted collection called __safeContent__ Note: It is critical that these data structures are not modified or deleted.
  • 49. Write Operations Vs Metadata Collections When writing a document, each indexed field requires writes to metadata collections along with one write on the encrypted collection. Operation ESC ECC ECOC Insert 1 0 1 Update 1 1 2 Delete 0 1 1
  • 50. Storage Issue with QE ➔ 2x or 3x times extra storage ➔ Depends on the number of indexed fields per document ➔ For every write Associated metadata collections will update IndexCompaction ➔ A process that prunes the metadata collections ➔ Should run when the size of ECOC exceeds 1 GB. ➔ To run index compaction, db.collection.compactStructuredEncryptionData()
  • 51. Availability of Queryable Encryption ➔ Versions: 6.0v ➔ Divers: 20 + platforms of multiple languages (Node.Js, C, C#, Python, Java etc.) ➔ Automatic Encryption: MongoDB Atlas and Enterprise versions. ➔ Manual Encryption: MongoDB Atlas and Enterprise versions and community versions.
  • 52. Limitations of QE: ➔ Fully randomized encryption ➔ Manually create a unique Data Encryption Key for each field ➔ Manually run index compaction ➔ Standalone deployments are not supported ➔ Secondary reads are not supported ➔ Encrypted field names are immutable. ➔ Ignores collations ➔ Unique indexes and TTl indexes are not supported. ➔ Don’t support Views, Time Series Collections, or capped collection. ➔ Can’t encrypt _Id
  • 53. Encryption Performance in MongoDB ➔ Data size α Latency ➔ Consider High load condition ◆ Writes 10% to 20% latency ◆ Reads < 5% (negligible) ➔ Encrypting and decrypting require more resources ➔ WiredTiger storage engine is more suitable. Because ◆ Page level encryption ◆ Throughput operations performs on the exact page only ◆ High performance, scalability, and security
  • 54. MongoDB Security Recommendations ➔ Don’t directly expose the DB servers to the internet ➔ Avoid using the default port ➔ Use strong passwords ➔ Authenticate with db.auth() ➔ Never use the security.transitionToAuth option in config file. ➔ Limit the user actions, Use customized roles. ➔ Maintain data encryption.