SlideShare a Scribd company logo
1 of 50
Download to read offline
MariaDB Security Best Practices
● This talk is about security best practices that should be used
with MariaDB
● It is not:
○ A tutorial
○ A discussion on MariaDB specific features
Agenda
Restricting
hosts and ports
● Access to MariaDB should be allowed from:
○ Replicas / masters / galera nodes
○ Proxies
○ Monitoring
○ Service discovery
○ …potentially other tools…
○ Jumphosts (SSH)
Restricting access
● Proxies, service discovery need to be reachable from the
applications
● Monitoring needs be reachable from the world, via HTTPS
port
● MariaDB should not be reachable from other nodes
● Jumphost should be reachable from the world, only SSH port
Restricting access
● On cloud platforms this can usually be achieved with security
groups
● As a general rule, hosts in the same SG can communicate to
each other
● If you don't run your databases in the cloud, consider using
a VPN
Restricting access
● Access should only be permitted using the proper ports
● This can be achieved with SG rules, too
● But if security is paramount, don't fear redundancy
○ For example, use both SG rules and IPTables
Restricting access
● Up to version 10.11, Galera had no protection for this case:
○ A malicious user attaches a new Galera node to an
existing cluster
○ The new node obtains an SST with a method that doesn't
require authentication
● So, before that version, Galera needed to run in a VPN or
security group with strict rules
Restricting access
● Now, you can whitelist nodes that are supposed to be part of
the cluster:
wsrep_allowlist=10.10.10.10,20.20.20.20,30.30.30.30
● This variable is not dynamic
● To add a new node, restart the nodes one by one
Restricting access
Users
● Instead of MariaDB users we should say accounts
● An account is:
username@'host'
MariaDB Users
A host can be:
● A hostname
● An IPv4 or IPv6
● A LIKE pattern
○ eg: 'app__.mywebsite.com'
● A netmask
○ eg: '10.0.1.1/255.255.255'
○ '10.0.1.1/24'
MariaDB Users
● root should only connect from localhost
○ No password, after connecting to the OS via SSH
○ Can be done with UNIX_SOCKET authentication plugin
○ This is the default
● Don't let root connect from anywhere else
MariaDB Users
● Each application of microservice should have a different user
● Ensure they connect from the proper subnet mask
● Or from the proper hostname
ms_authentication@10.0.1.1/24
ms_authentication@auth-__.myapp.com
MariaDB Users
● Users can connect from several places
● And even have different permissions depending on where
they connect from
● I don't recommend this practices (usually)
● Use prefixes like app- or ms- to distinguish
apps/microservices from human users
MariaDB Users
Permissions
Permissions can be granted at several levels:
● Global (read everything)
GRANT SELECT ON *.* TO user@host;
● Database (any table from a DB)
GRANT SELECT ON db.* TO user@host;
● Table (single table)
GRANT SELECT ON db.tab TO user@host;
● Column (only read certain columns)
GRANT SELECT *(id, col_a, col_b) ON db.tab
TO user@host;
MariaDB Permissions
● Normally, an application/microservice user should have
permissions on a single database:
GRANT SELECT, INSERT, UPDATE, DELETE ON auth.*
TO ms_auth@host;
● Typically, you also want to have a read-only user to scale
reads to replicas:
GRANT SELECT ON auth.*
TO ms_auth_ro@host;
● Migrations should be done by a separate user:
GRANT CREATE, CREATE VIEW, ALTER, INDEX, DROP, DROP
HISTORY, TRIGGER ON auth.*
TO ms_auth_migrations@host;
MariaDB Permissions
● Human users are typically:
○ Data analysts
○ Business analysts
○ Managers
…who know SQL
MariaDB Permissions
● Human users should only have SELECT permission, and
optionally CREATE TEMPORARY TABLES
● But they shouldn't have any permission on columns that
contain PII (personal identifiable information)
● Which means:
○ Private data: name, email, phone, etc
○ Information that allows to identify a user: user id, etc
This is required by GDPR and other regulations
MariaDB Permissions
How to do this? Here's an idea:
● Keep a table with the list of PII columns:
{db, table, column}
● A script should query the information_schema.COLUMNS
table, and get a list of columns that are not in the
pii_column table
● Grant SELECT permission on those columns
MariaDB Permissions
● But even in this way:
○ Permissions might not be strict enough to prevent certain
queries that should be forbidden
○ A user could be granted too many permissions by
mistake
○ A MariaDB bug could allow a user to perform critical
operations
● So I recommend to turn the Audit Log on
MariaDB Roles
Roles
● Human users shouldn't be granted permissions directly
● Each human users should be assigned one or more roles:
CREATE ROLE business_analyst;
GRANT SELECT ON *.* TO business_analyst;
GRANT business_analyst TO briard_laure@host;
MariaDB Roles
● Roles can be assigned to other roles:
-- all analysts can run certain stored procedures
CREATE ROLE analyst;
-- some analysts can see sales information
CREATE ROLE analyst_sales;
GRANT analyst TO analyst_sales;
-- some analysts can see employees information
CREATE ROLE analyst_employee;
GRANT analyst TO analyst_employee;
MariaDB Roles
Good practices for creating a tree of roles:
● Only do it if your permissions logic is sufficiently complex
● It should be a tree, not a graph (only 1 parent)
● Only "leaf roles" are assigned to users
MariaDB Roles
Authentication
Plugins
● Authentication plugins determine how users log into MariaDB
● Each user can be assigned one or more authentication
plugins
● Some plugins are pre-installed
● Others are in the plugin_dir. They can be installed:
INSTALL SONAME 'auth_ed25519';
● Some authentication plugins need support in the client
● Non-official MariaDB connectors and GUIs might not support
a plugin you need
Authentication Plugins
Default authentication plugins:
● mysql_native_password - default
● mysql_old_password - for backward compatibility
● unix_socket - default for root
● named_pipe - Windows
Authentication Plugins: GSSAPI
● PAM is a framework for multiple authentication methods, used on
Linux / UNIX
● Each authentication method is implemented as a PAM module:
○ pam_google_authenticator
○ pam_ldap
○ MS Active Directory
○ pam_unix: use /etc/shadow
○ pam_ssh: Log in via SSH keys
○ pam_time: Restrict login based on time
○ pam_user_map: Maps multiple PAM users to the same
MariaDB user
It's possible to use multiple modules for the same user
Authentication Plugins: PAM
SSL
● Starting from MariaDB 11.3, SSL is enabled by default
● However, it's hardly useful if you don't require clients to
connect via SSH
Backup security
As a minimum, you should do this:
CREATE USER xyz REQUIRE SSL;
But in this way, a self-signed certificate is accepted
Backup security
You can require:
● an issuer
● a subject
● a cipher
● or any combination of these
REQUIRE SUBJECT '/CN/Federico/O=Vettabase Ltd/C=UK'
AND ISSUER '...'
AND CIPHER 'SHA-DES-CBC3-EDH-RSA';
Backup security
SQL Encryption
MariaDB has several SQL functions for encrypting data
INSERT INTO user (pwd, …) VALUES (
CRYPT('Hello, world!', 'zzXf')
);
Problem:
The clear password will be sent over a network and possibly
logged
Encryption in SQL
● MariaDB 11.2 improved AES_ENCRYPT() and
AES_DECRYPT():
AES_ENCRYPT(str, key, [, iv [, mode]])
● And introduced KDF(), that can generate good keys:
AES_ENCRYPT(
str,
KDF('foo', 'bar', 'infa', 'hkdf'),
[, iv
[, mode]]
)
Encryption in SQL
● Not knowing the key makes it harder to brute-force the
encrypted secret
● So the results of KDF() and AES_ENCRYPT() should be
stored on different database servers
Encryption in SQL
Encryption at rest
● Encryption at rest means that clear data is sent and received
by applications, but it's encrypted on disk
● This protects you by whoever gains access to:
○ the OS
○ the physical disk
● Hard disk thefts are possible and, for certain data sets,
they can make a person rich
Encryption at rest
● MariaDB can encrypt:
○ InnoDB .ibd files
○ InnoDB ibdata and ib_logfile* files
○ Aria .MAD and .MAI files (including temporary tables)
○ Binary log
○ Relay log
○ Temporary files: long transactions, filesort
Encryption at rest
● MariaDB does not encrypt:
○ Galera cache
○ Slow and general logs
○ Audit log
○ Error log
○ Aria log (only relevant for non-temporary tables)
○ Other storage engines
● Other files not encrypted, but not critical:
○ .frm files (table definitions)
Encryption at rest
● It is vital that:
○ The key is not stored on the same disk as data, but
ideally it shouldn't be stored on the same server
○ The keys are rotated
● Encryption key management plugins take care of this:
○ File Key Management Plugin
○ Hashicorp Key Management Plugin (Vault)
○ Eperi Key Management Plugin
○ AWS Key Management Plugin
Encryption at rest
File Key Management Plugin
● Multiple keys are supported
● But no key rotation
● Keys stored on the same server
● Keys can be manually crypted
Encryption at rest
Hashicorp Key Management Plugin
● Multiple keys are supported
● Key rotation is supported
● Keys are stored in Hashicorp Vault
● Vault authentication is done via a token
Encryption at rest
● Encryption at rest is an interesting example of how MariaDB
is enriched by community contributions:
○ Originally implemented by eperi
○ Tablespace encryption by Google
Encryption at rest
Backup security
● Physical backups of encrypted data are encrypted
● Consider encrypting other backup types
● But keep in mind that decrypting a backup can take time, and
when you do it your servers might be down
● So you need a wise balance between security and speed
● If you encrypt AND compress backups, first encrypt them,
then compress them
Backup security
● If you send backups to other locations, make sure you use
secure connections
● If you keep backups on local physical devices, make sure
they are stored securely
Backup security
MariaDB Security Best Practices

More Related Content

Similar to MariaDB Security Best Practices

Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesDimas Prasetyo
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at DecisivTeleport
 
Large Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQLLarge Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQLDaniël van Eeden
 
The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesDave Stokes
 
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...ScyllaDB
 
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios CoreNagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios CoreNagios
 
Using advanced security and data-protection features
Using advanced security and data-protection featuresUsing advanced security and data-protection features
Using advanced security and data-protection featuresMariaDB plc
 
What to expect from MariaDB Platform X5, part 1
What to expect from MariaDB Platform X5, part 1What to expect from MariaDB Platform X5, part 1
What to expect from MariaDB Platform X5, part 1MariaDB plc
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopVelocidex Enterprises
 
[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares
[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares
[Pass the SALT 2021] Hosting Identity in the Cloud with free softwaresWorteks
 
DevOops & How I hacked you DevopsDays DC June 2015
DevOops & How I hacked you DevopsDays DC June 2015DevOops & How I hacked you DevopsDays DC June 2015
DevOops & How I hacked you DevopsDays DC June 2015Chris Gates
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database AuditingJuan Berner
 
DerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShellDerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShellScott Sutherland
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGPablo Garbossa
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsJean-François Gagné
 
Managing secrets at scale
Managing secrets at scaleManaging secrets at scale
Managing secrets at scaleAlex Schoof
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS
 
Slides: Introducing the new ClusterControl 1.2.9 - with live demo
Slides: Introducing the new ClusterControl 1.2.9 - with live demo Slides: Introducing the new ClusterControl 1.2.9 - with live demo
Slides: Introducing the new ClusterControl 1.2.9 - with live demo Severalnines
 

Similar to MariaDB Security Best Practices (20)

Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practices
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at Decisiv
 
Large Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQLLarge Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQL
 
The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL Databases
 
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
 
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios CoreNagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
 
Using advanced security and data-protection features
Using advanced security and data-protection featuresUsing advanced security and data-protection features
Using advanced security and data-protection features
 
What to expect from MariaDB Platform X5, part 1
What to expect from MariaDB Platform X5, part 1What to expect from MariaDB Platform X5, part 1
What to expect from MariaDB Platform X5, part 1
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
 
[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares
[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares
[Pass the SALT 2021] Hosting Identity in the Cloud with free softwares
 
DevOops & How I hacked you DevopsDays DC June 2015
DevOops & How I hacked you DevopsDays DC June 2015DevOops & How I hacked you DevopsDays DC June 2015
DevOops & How I hacked you DevopsDays DC June 2015
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
 
DerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShellDerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShell
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 
Managing secrets at scale
Managing secrets at scaleManaging secrets at scale
Managing secrets at scale
 
Plam16 jan
Plam16 janPlam16 jan
Plam16 jan
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and Installation
 
SignalR
SignalRSignalR
SignalR
 
Slides: Introducing the new ClusterControl 1.2.9 - with live demo
Slides: Introducing the new ClusterControl 1.2.9 - with live demo Slides: Introducing the new ClusterControl 1.2.9 - with live demo
Slides: Introducing the new ClusterControl 1.2.9 - with live demo
 

More from Federico Razzoli

Webinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDBWebinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDBFederico Razzoli
 
MariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedFederico Razzoli
 
Webinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationWebinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationFederico Razzoli
 
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Federico Razzoli
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsFederico Razzoli
 
Recent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeRecent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeFederico Razzoli
 
Advanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfFederico Razzoli
 
Automate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with AnsibleAutomate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with AnsibleFederico Razzoli
 
Creating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDBCreating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDBFederico Razzoli
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresFederico Razzoli
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engineFederico Razzoli
 
Database Design most common pitfalls
Database Design most common pitfallsDatabase Design most common pitfalls
Database Design most common pitfallsFederico Razzoli
 
JSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB DatabasesJSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB DatabasesFederico Razzoli
 
How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2Federico Razzoli
 
MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)Federico Razzoli
 
Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)Federico Razzoli
 
MySQL Query Optimisation 101
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101Federico Razzoli
 

More from Federico Razzoli (20)

Webinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDBWebinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDB
 
MariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
 
Webinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationWebinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstration
 
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
 
Recent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeRecent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy life
 
Advanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
 
Automate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with AnsibleAutomate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with Ansible
 
Creating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDBCreating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDB
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
Database Design most common pitfalls
Database Design most common pitfallsDatabase Design most common pitfalls
Database Design most common pitfalls
 
MySQL and MariaDB Backups
MySQL and MariaDB BackupsMySQL and MariaDB Backups
MySQL and MariaDB Backups
 
JSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB DatabasesJSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB Databases
 
How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2
 
MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)
 
Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
MySQL Query Optimisation 101
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101
 

Recently uploaded

Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

MariaDB Security Best Practices

  • 2. ● This talk is about security best practices that should be used with MariaDB ● It is not: ○ A tutorial ○ A discussion on MariaDB specific features Agenda
  • 4. ● Access to MariaDB should be allowed from: ○ Replicas / masters / galera nodes ○ Proxies ○ Monitoring ○ Service discovery ○ …potentially other tools… ○ Jumphosts (SSH) Restricting access
  • 5. ● Proxies, service discovery need to be reachable from the applications ● Monitoring needs be reachable from the world, via HTTPS port ● MariaDB should not be reachable from other nodes ● Jumphost should be reachable from the world, only SSH port Restricting access
  • 6. ● On cloud platforms this can usually be achieved with security groups ● As a general rule, hosts in the same SG can communicate to each other ● If you don't run your databases in the cloud, consider using a VPN Restricting access
  • 7. ● Access should only be permitted using the proper ports ● This can be achieved with SG rules, too ● But if security is paramount, don't fear redundancy ○ For example, use both SG rules and IPTables Restricting access
  • 8. ● Up to version 10.11, Galera had no protection for this case: ○ A malicious user attaches a new Galera node to an existing cluster ○ The new node obtains an SST with a method that doesn't require authentication ● So, before that version, Galera needed to run in a VPN or security group with strict rules Restricting access
  • 9. ● Now, you can whitelist nodes that are supposed to be part of the cluster: wsrep_allowlist=10.10.10.10,20.20.20.20,30.30.30.30 ● This variable is not dynamic ● To add a new node, restart the nodes one by one Restricting access
  • 10. Users
  • 11. ● Instead of MariaDB users we should say accounts ● An account is: username@'host' MariaDB Users
  • 12. A host can be: ● A hostname ● An IPv4 or IPv6 ● A LIKE pattern ○ eg: 'app__.mywebsite.com' ● A netmask ○ eg: '10.0.1.1/255.255.255' ○ '10.0.1.1/24' MariaDB Users
  • 13. ● root should only connect from localhost ○ No password, after connecting to the OS via SSH ○ Can be done with UNIX_SOCKET authentication plugin ○ This is the default ● Don't let root connect from anywhere else MariaDB Users
  • 14. ● Each application of microservice should have a different user ● Ensure they connect from the proper subnet mask ● Or from the proper hostname ms_authentication@10.0.1.1/24 ms_authentication@auth-__.myapp.com MariaDB Users
  • 15. ● Users can connect from several places ● And even have different permissions depending on where they connect from ● I don't recommend this practices (usually) ● Use prefixes like app- or ms- to distinguish apps/microservices from human users MariaDB Users
  • 17. Permissions can be granted at several levels: ● Global (read everything) GRANT SELECT ON *.* TO user@host; ● Database (any table from a DB) GRANT SELECT ON db.* TO user@host; ● Table (single table) GRANT SELECT ON db.tab TO user@host; ● Column (only read certain columns) GRANT SELECT *(id, col_a, col_b) ON db.tab TO user@host; MariaDB Permissions
  • 18. ● Normally, an application/microservice user should have permissions on a single database: GRANT SELECT, INSERT, UPDATE, DELETE ON auth.* TO ms_auth@host; ● Typically, you also want to have a read-only user to scale reads to replicas: GRANT SELECT ON auth.* TO ms_auth_ro@host; ● Migrations should be done by a separate user: GRANT CREATE, CREATE VIEW, ALTER, INDEX, DROP, DROP HISTORY, TRIGGER ON auth.* TO ms_auth_migrations@host; MariaDB Permissions
  • 19. ● Human users are typically: ○ Data analysts ○ Business analysts ○ Managers …who know SQL MariaDB Permissions
  • 20. ● Human users should only have SELECT permission, and optionally CREATE TEMPORARY TABLES ● But they shouldn't have any permission on columns that contain PII (personal identifiable information) ● Which means: ○ Private data: name, email, phone, etc ○ Information that allows to identify a user: user id, etc This is required by GDPR and other regulations MariaDB Permissions
  • 21. How to do this? Here's an idea: ● Keep a table with the list of PII columns: {db, table, column} ● A script should query the information_schema.COLUMNS table, and get a list of columns that are not in the pii_column table ● Grant SELECT permission on those columns MariaDB Permissions
  • 22. ● But even in this way: ○ Permissions might not be strict enough to prevent certain queries that should be forbidden ○ A user could be granted too many permissions by mistake ○ A MariaDB bug could allow a user to perform critical operations ● So I recommend to turn the Audit Log on MariaDB Roles
  • 23. Roles
  • 24. ● Human users shouldn't be granted permissions directly ● Each human users should be assigned one or more roles: CREATE ROLE business_analyst; GRANT SELECT ON *.* TO business_analyst; GRANT business_analyst TO briard_laure@host; MariaDB Roles
  • 25. ● Roles can be assigned to other roles: -- all analysts can run certain stored procedures CREATE ROLE analyst; -- some analysts can see sales information CREATE ROLE analyst_sales; GRANT analyst TO analyst_sales; -- some analysts can see employees information CREATE ROLE analyst_employee; GRANT analyst TO analyst_employee; MariaDB Roles
  • 26. Good practices for creating a tree of roles: ● Only do it if your permissions logic is sufficiently complex ● It should be a tree, not a graph (only 1 parent) ● Only "leaf roles" are assigned to users MariaDB Roles
  • 28. ● Authentication plugins determine how users log into MariaDB ● Each user can be assigned one or more authentication plugins ● Some plugins are pre-installed ● Others are in the plugin_dir. They can be installed: INSTALL SONAME 'auth_ed25519'; ● Some authentication plugins need support in the client ● Non-official MariaDB connectors and GUIs might not support a plugin you need Authentication Plugins
  • 29. Default authentication plugins: ● mysql_native_password - default ● mysql_old_password - for backward compatibility ● unix_socket - default for root ● named_pipe - Windows Authentication Plugins: GSSAPI
  • 30. ● PAM is a framework for multiple authentication methods, used on Linux / UNIX ● Each authentication method is implemented as a PAM module: ○ pam_google_authenticator ○ pam_ldap ○ MS Active Directory ○ pam_unix: use /etc/shadow ○ pam_ssh: Log in via SSH keys ○ pam_time: Restrict login based on time ○ pam_user_map: Maps multiple PAM users to the same MariaDB user It's possible to use multiple modules for the same user Authentication Plugins: PAM
  • 31. SSL
  • 32. ● Starting from MariaDB 11.3, SSL is enabled by default ● However, it's hardly useful if you don't require clients to connect via SSH Backup security
  • 33. As a minimum, you should do this: CREATE USER xyz REQUIRE SSL; But in this way, a self-signed certificate is accepted Backup security
  • 34. You can require: ● an issuer ● a subject ● a cipher ● or any combination of these REQUIRE SUBJECT '/CN/Federico/O=Vettabase Ltd/C=UK' AND ISSUER '...' AND CIPHER 'SHA-DES-CBC3-EDH-RSA'; Backup security
  • 36. MariaDB has several SQL functions for encrypting data INSERT INTO user (pwd, …) VALUES ( CRYPT('Hello, world!', 'zzXf') ); Problem: The clear password will be sent over a network and possibly logged Encryption in SQL
  • 37. ● MariaDB 11.2 improved AES_ENCRYPT() and AES_DECRYPT(): AES_ENCRYPT(str, key, [, iv [, mode]]) ● And introduced KDF(), that can generate good keys: AES_ENCRYPT( str, KDF('foo', 'bar', 'infa', 'hkdf'), [, iv [, mode]] ) Encryption in SQL
  • 38. ● Not knowing the key makes it harder to brute-force the encrypted secret ● So the results of KDF() and AES_ENCRYPT() should be stored on different database servers Encryption in SQL
  • 40. ● Encryption at rest means that clear data is sent and received by applications, but it's encrypted on disk ● This protects you by whoever gains access to: ○ the OS ○ the physical disk ● Hard disk thefts are possible and, for certain data sets, they can make a person rich Encryption at rest
  • 41. ● MariaDB can encrypt: ○ InnoDB .ibd files ○ InnoDB ibdata and ib_logfile* files ○ Aria .MAD and .MAI files (including temporary tables) ○ Binary log ○ Relay log ○ Temporary files: long transactions, filesort Encryption at rest
  • 42. ● MariaDB does not encrypt: ○ Galera cache ○ Slow and general logs ○ Audit log ○ Error log ○ Aria log (only relevant for non-temporary tables) ○ Other storage engines ● Other files not encrypted, but not critical: ○ .frm files (table definitions) Encryption at rest
  • 43. ● It is vital that: ○ The key is not stored on the same disk as data, but ideally it shouldn't be stored on the same server ○ The keys are rotated ● Encryption key management plugins take care of this: ○ File Key Management Plugin ○ Hashicorp Key Management Plugin (Vault) ○ Eperi Key Management Plugin ○ AWS Key Management Plugin Encryption at rest
  • 44. File Key Management Plugin ● Multiple keys are supported ● But no key rotation ● Keys stored on the same server ● Keys can be manually crypted Encryption at rest
  • 45. Hashicorp Key Management Plugin ● Multiple keys are supported ● Key rotation is supported ● Keys are stored in Hashicorp Vault ● Vault authentication is done via a token Encryption at rest
  • 46. ● Encryption at rest is an interesting example of how MariaDB is enriched by community contributions: ○ Originally implemented by eperi ○ Tablespace encryption by Google Encryption at rest
  • 48. ● Physical backups of encrypted data are encrypted ● Consider encrypting other backup types ● But keep in mind that decrypting a backup can take time, and when you do it your servers might be down ● So you need a wise balance between security and speed ● If you encrypt AND compress backups, first encrypt them, then compress them Backup security
  • 49. ● If you send backups to other locations, make sure you use secure connections ● If you keep backups on local physical devices, make sure they are stored securely Backup security