MySQL server internal security-Secure data Directory Access

Source: Internet
Author: User
Tags chmod file system log mysql query readable file permissions mysql database
mysql| Security | security | access | server | data | Data Directory This chapter focuses on what you can do to maintain the security and integrity of MySQL installations as a MySQL administrator. We've talked a little bit about security issues in chapter 11th, such as the importance of setting the initial mysqlroot password and how to create a user account. This content is discussed as part of the startup and running Setup process
Of In this chapter, we will discuss the following security-related issues in more detail:
Why is security important and what attacks should we be wary of?
What risks you will face from users in the server host (internal security  long 鍪?br> What risks (external security) do you face from clients connected to the server on the network?
The MySQL administrator is responsible for securing the contents of the database so that records can only be accessed by strictly authenticated users. This includes internal security and external security.
Internal security concerns file system-level issues, such as protecting the MySQL data directory from users who have the machine account running the server. However, if the file permissions on the contents of the data directory are too arbitrary, and someone can simply replace the files corresponding to these tables, internal security will not be able to ensure that the proper establishment of the network client visits
Ask for control of the authorization table.
External security concerns the client's external connections, such as preventing the MySQL server from being attacked by a network-incoming connection request for database content access. To establish a MySQL authorization table, they do not allow access to the database managed by the server (unless a valid name and password is provided).
This chapter provides guidance on issues that you should be aware of and how to prevent unauthorized access at both the internal and external levels.

The MySQL server provides a flexible permission system that is implemented through the authorization table in the MySQL database. You can set the contents of these tables to allow or deny database access to clients. This provides security for network access data that is not authenticated. However, if other users on the server host have direct access to the contents of the data directory, the
will not be able to establish good security for the network accessing the data. Unless you know that you are the only person registered on a machine running a MySQL server, you need to be concerned about the likelihood that other users on that machine will have access to the data directory.
Here's what you want to protect:
Database files. It is obvious that you want to maintain the confidentiality of databases maintained by the server. The owner of the database usually takes into account the proprietary nature of the database content. Even if they do not consider it, the most important is to make the content of the database public, without causing those content to be compromised due to the low security of the database directory.
Log files. The general and update logs must be secure because they contain the query text. This is quite a concern because anyone with log file access can monitor transactions that occur in the database.
A more specific security concern with log files is that queries such as Grant and set PASSWORD are recorded in the log. The general and update log files contain sensitive query text, which includes passwords (MySQL uses password encryption, but this only applies to connections established after password settings). The procedure for setting up a password is contained in queries such as Grant, INSERT, or set PASSWORD, but these queries are recorded as plain text. If an attacker has read access to the log, he can find sensitive information simply by running grep on words such as grant or password in the log.
Obviously, you don't want other users on the server host to have write access to the data directory files, because then they can trample on state files or database tables. But read access is also dangerous. If the table file is readable, it is trivial to steal the file and let MySQL itself display the contents of the table in plain text. You can follow these steps
To proceed in a sudden:
1 Install your MySQL server on the server host, but use a different port, socket, and data file than the official server.
2 run mysql_install_db initialize your data directory. This will allow you to access the server as the root user of MySQL, so you will have full control over the server access mechanism. It also creates a test database.
3 Copy the corresponding file of the table you want to steal to the test subdirectory under the server data directory.
4) Start the crime server. You can access these tables at your own discretion. Show table from test shows that you have a backup of the stolen tables, and SELECT * will display the entire contents of any of these tables.
5 If it is worse, open the server's anonymous user account license so that anyone can connect to the server from anywhere to visit your test database. Now, you have released these stolen watches to the world.
Think about what just happened, and then turn it upside down. Do you want someone to do this to you? Of course not.
By executing ls-l in the data directory, you can determine whether the data directory contains unsafe files or directories. You should view files or directories that have permission to open groups or other permissions. The following is a partial list of unsafe data directories that are part of the database directory in the data directory:

As you can see, some database directories have the right permissions, while others do not. The case in this case is due to time. Older servers create less restrictive permissions, and older servers are less restrictive in setting permissions than newer servers (note that more restrictive directories, Menager and T P, have more new dates) than those on the server. The current version of MySQL ensures that these files are readable only to users who are running on the server.
Let's schedule these permissions so that only users of the server can access them. The main protection means to free UNIX file system itself provides tools that can set the ownership and manner of files and directories. Action steps are as follows:
1) Locate in the Data directory:
% CD DataDir
2 Set the ownership of all files under the data directory to the account running the server (this step must be performed as root). In this book, the author uses mysqladm and MYSQLG R P for the username and group name of this account. You can modify ownership by using one of the following commands:
# Chown-r MYSQLADMIN.MYSQLGRP
# Find. -follow-type D-print | Xargs Chown Mysqladmin.mysqlgrp
3 Modify the Data directory and database directory so that they are readable only for mysqladm. This prevents other users from accessing the contents of the data directory. You can use one of the following commands to run either as root or as Mysqladm (the latter is better to minimize the number of commands to run as root):
% Chmod-r go-rwx
% find. -follow-type D-print | Xargs chmod go-rwx
4 The Mysqladm user to set the content of the data directory ownership and manner. You should now make sure that you always run with Mysqladm because it is now the only user who has access to the data directory. The process of running the server as a non-root user is described in chapter 11th.
After the above steps, you will have the following license rights:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.