As we all know, data breaches occur all too often. After a data breach occurs, we are used to seeing security experts, company associates and other people advising us to change our passwords and safeguard our data by securing our infrastructure.
This is what the majority of developers do – we secure our infrastructure, maybe hire some information security consultants for advice on how to prevent data breaches in the future and forget about the data breach as time passes.
But have we ever thought how would we secure MySQL in case such an event occurs? This is what we will try to do in this post.
As far as security in MySQL is concerned, we have a wide range of options to look at:
These are the basic questions we need to answer if we want to understand how to secure MySQL – we will now look further into them.
If our information systems are suspected to have suffered a data breach, it’s a good idea to re-install MySQL on our servers – it’s also a good idea to start from securing the MySQL installation itself meaning that when we have re-installed MySQL on our server we should look at the following things:
root
MySQL user – this should seem obvious, but sometimes we forget the simplest things. Make sure that the password consists of uppercase, lowercase letters, numbers and special symbols.sudo rsync -a /var/lib/mysql /mount/volume-01
, then include the following lines in your /var/lib/mysql/my.cnf
file:socket=/mount/volume_01/mysql/mysql.sock
datadir=/mount/volume_01/mysql
. Change the directory according to your needs.secure_file_priv
system variable sets the directory from which import and export operations are allowed to execute – if the operations will not originate from this directory, the file(s) will not be imported into the server./var/lib/mysql/my.cnf
file and change the value of the secure_file_priv
variable to a different directory.The basic MySQL security steps depicted above should help you to secure your MySQL installation, but that’s only one part of MySQL’s security. Now we will the other side of it – MySQL access control.
In order to ensure proper MySQL access control, restrict the usage of certain statements only to certain users – weigh your options and only allow users access to statements that are necessary for them to perform their duties.
For example, if a user should only read from the database, he should be only allowed the usage of SELECT
statements – the choice of using multiple statements like ALTER
, UPDATE
and others might not be necessary.
Also consider revoking user access to certain statements – if you see that a certain user no longer needs to, for example, add indexes to the table, consider revoking his access to ALTER
statements, etc.
MySQL includes several plugins that are able to strengthen its security capabilities. We will not be discussing all of them in this chapter, but some of them are:
sha256_password
plugin:CREATE USER 'demo_user'@'localhost' IDENTIFIED WITH sha256_password;
old_passwords
variable to 2 (this will cause the PASSWORD()
function to use the SHA-256 hashing algorithm):SET old_passwords = 2;
SET PASSWORD FOR 'demo_user'@localhost = PASSWORD('demo_password');
validate_password
plugin aims to improve security by enabling password strength testing.validate_password
, and, if needed, modify the value of validate_password_policy
(the variable can be set to numeric or string values – 0
, 1
and 2
or the values of LOW
, MEDIUM
and STRONG
respectively) – the policy setting LOW
only tests password strength – by default, passwords must be at least 8 characters long. This length can be changed by modifying the variable validate_password_length
, a MEDIUM
policy setting adds certain conditions – passwords must contrain at least 1 numeric, lowercase, uppercase and special character. These values can also be changed by modifying the variables validate_password_number_count
, validate_password_mixed_case_count
and validate_password_special_char_count
.STRONG
password policy setting adds the condition that passwords that match or exceed the length of 4 characters must not match words in a dictionary file which can be specified by modifying the validate_password_dictionary_file
variable.audit_log
. Enterprise audit uses the audit API in order to enable the monitoring and logging of queries executed on MySQL servers. The plugin produces a log file containing content that was derived looking at the activity of the server.General database security, in the majority of cases, boils down to the usage of basic security measures for databases – we should use strong passwords for all of the accounts in use, developers should only allow people they trust to access data, prevent the database from being overloaded, avoid physical damage to the servers, avoid design flaws in software that deals with databases (SQL injection, for example, can be avoided by using prepared statements), also avoid data corruption or loss, etc.
Data is an essential part of your website – as such, backing up your files and database should be a no-brainer. Data corrupts. Hard drives fail. There are all kinds of scenarios where you can lose data and if you do not back it up, you can be in deep trouble.
Backing up your files and database is an extremely important part of any security routine. There are multiple tools and services that are designed to automate this task (you can even make one yourself by creating a bash script), you can store data on cloud storage, drives etc. – storage space nowadays is so cheap that it makes sense to back up pretty much everything.
And, in case a disaster does occur and your data gets wiped from the servers in production, it’s extremely important to also test your backups and see if you can restore your data quickly and efficiently – performing backup testing should be an essential part of any backup routine.
To summarize, in order to protect your MySQL database after a data breach it is a good idea to re-install MySQL on your server and restrict user access shortly after. Keep in mind that your user accounts should use strong passwords (use uppercase, lowercase letters, numbers, and, if possible, symbols), consider using MySQL security plugins, be sure to enforce database security practices both in MySQL and in associated software configurations and take care of your backups. Back up all of your critical data, make sure your backups are up to date and always test them.
If you have performed the steps outlined above, you should be well on your way to a better future for your MySQL database, however, securing your MySQL infrastructure is only one piece of the database puzzle: to keep your infrastructure safe, you should also consider performing a scan through a list of various known data breaches that have been already leaked on the web and then performing steps to secure yourself judging from that. Consider changing your passwords, enabling two-factor authentication, and keeping an eye out on various security-related blogs to learn more about the newest developments in the database space.
There have been rumors about a data breach targeting Schneider Electric. Did a data breach…
There have been rumors about the Fiskars Group – the company behind Fiskars scissors and…
Russia has fined Google more than two undecillion roubles because Google has refused to pay…
Why does RockYou 2024.txt look like a binary file when you open it up? Find…
Duolicious is a dating app that connects people who are “chronically online.” Did the Duolicious…
This blog will tell you what RockYou 2024 is, how RockYou 2024.txt came to be,…
View Comments