Percona Secure Configuration
Secure configuration recommendations for Percona Server for MySQL in HEAL.
Version: MySQL 8.x
Note: Test each change in a non-production environment before you apply it to production. HEAL services connect to Percona with the dbadmin and appsonedb accounts, and replication (in high-availability deployments) uses the replicator account. After you change accounts, hosts, authentication, or SSL settings, make sure that HEAL can still connect.
Configuring the Audit Log#
Auditing is the process of recording the activity that occurs on databases or applications. Auditing can help you detect and prioritize security threats and data breaches.
Risk/Impact#
Risk Rating: High
Auditing system access enhances detection and timely termination of unauthorized access.
It ensures security incidents are identified and provides evidence for analysis. Insufficient auditing leads to a lack of an audit trail for unauthorized access.
Verification/Implementation steps#
Follow the below steps to secure the feature:
1. Install the Percona audit log plugin, so that all the activities are logged:
INSTALL PLUGIN audit_log SONAME 'audit_log.so';
2. In the [mysqld] section of my.cnf, set what is logged, the log format, and size-based log rotation. Adjust the values to the organization's security policy, for example:
audit_log_policy=ALL
audit_log_format=JSON
audit_log_rotate_on_size=104857600
audit_log_rotations=10
Restart Percona for the settings to take effect.
3. Backups of logs should be done on a specific interval of time as per the organization's security policy.
4. All types of logs such as alert logs, access logs, warning logs, info logs, etc. should be enabled to ensure that all the activities are being audited.
Note: Percona also provides the Audit Log Filter component, the newer replacement for the audit log plugin. Do not install both.
Configure NTP#
Time server (using NTP) is used for synchronizing the system time on all devices and servers across the organization.
Risk/Impact#
Risk Rating: Medium
Mismatch in time details in the logs from different devices can lead to errors in the correlated event information.
Verification/Implementation steps#
To synchronize the time of an appliance with the NTP server or across cluster members, use chrony, the default time synchronization service on RHEL 8 and later:
sudo yum install chrony
sudo systemctl enable --now chronyd
Add the organization's NTP servers to /etc/chrony.conf, restart chronyd, and check that the time is synchronized:
sudo systemctl restart chronyd
chronyc tracking
Latest Security Patches#
Security patches protect against the latest vulnerabilities. They are released whenever a vulnerability is detected and needs to be installed.
Risk/Impact#
Risk Rating: High
Server can get affected by the latest vulnerabilities and may get compromised.
Verification/Implementation steps#
Download and install the latest security patches released by OEM (ensure the patches are tested on a test server for dependencies before they are installed on Production servers).
Note: If the Server is integrated with Patch Management Server such as BMC, then the control can be marked as not applicable.
Unwanted services are Disabled#
Many services on the server are not essential; however, these services are a potential point of attack. Therefore, all non-essential services should be disabled.
Risk/Impact#
Risk Rating: High
Vulnerabilities found in unused services can be exploited by malicious users for compromising the server.
Verification/Implementation steps#
Ensure the unused services are disabled.
Configuring Backups#
In general, backup is used to restore utility and the services that you installed.
Risk/Impact#
Risk Rating: Medium
It is useful in deployments where backups are stored in a separate location to protect against catastrophic loss.
Verification/Implementation steps#
To take a backup of the database, follow the following steps:
1. Make sure to provide access to the backup directory for the user.
2. Back up the databases with mysqldump (logical backup) or Percona XtraBackup (physical backup). Keep the credentials in an option file that only its owner can read (chmod 600), not on the command line. For example, an option file:
[client]
user=<backup user>
password=<password>
host=<Percona host>
port=<Percona port>
And the backup command:
mysqldump --defaults-extra-file=<option file> --single-transaction --routines --events --triggers --all-databases > <backup directory>/heal-db-backup.sql
3. Specify the backup directory by ensuring the below points:
- Backups should be made at a specific interval of time as per the organization's security policy.
- Backups should be taken on a different server in a secure manner.
- The backup process should be followed as per the process defined in the backup and retention policy of the department/organization.
TLS 1.2 and above protocol will be Enabled#
TLS 1.2 and above protocol will be Enabled.
TLS provides a high level of security for sessions between an Ethernet-connected client application and a server application, which have no prior knowledge of each other and do not exchange encryption keys.
Risk/Impact#
Risk Rating: High
An attacker may try to break the integrity of data and collect the sensitive information.
Verification/Implementation steps#
Ensure that only TLS 1.2 and above is enabled. In the [mysqld] section of my.cnf, set:
tls_version=TLSv1.2,TLSv1.3
Restart Percona, and then verify the enabled protocols:
SHOW GLOBAL VARIABLES LIKE 'tls_version';
Configure strong cipher suites according to the organization's security policy: ssl_cipher for TLS 1.2 and tls_ciphersuites for TLS 1.3.
Configure password policy#
A strong password policy is required to control user password characteristics, including minimum length. Strong password and account lockout settings need to be configured to help prevent password-based attacks from being successful.
Risk/Impact#
Risk Rating: High
An attacker will be able to guess the password easily, if the users are using the weak passwords.
Verification/Implementation steps#
Ensure the steps below are as follows:
1. A proper configuration of the password policy.
2. Password policy such as password history, maximum password age, minimum password age, minimum password length, and password complexity is configured according to the organization's security policy.
Review Super user/Admin Roles#
Security administrators can control access to their databases in a way that mirrors the structure of their organizations (they can create roles in the database that map directly to the job functions in their organizations).
Risk/Impact#
Risk Rating: Medium
The assignment of privileges is simplified.
Instead of assigning the same privileges to each user individually, an administrator can assign them to a role representing a specific job function and then grant that role to all relevant users.
Verification/Implementation steps#
Ensure that multiple super user/admin roles are not assigned on the system.
Permission and ownership#
Ensure the below files have appropriate permission and ownership.
1. log_bin_basename
2. audit_log_file
3. general_log_file
MySQL utilizes several log files for different operational purposes:
- Binary Log
- Error Log
- Slow Query Log
- Relay Log
- General Log
Risk/Impact#
Risk Rating: Medium
These log files are stored on the host operating system. Their accessibility is provided by the operating system's file permissions and ownership settings. Also, non-MySQL users may have access to these log files.
Verification/Implementation steps#
Follow the below steps to secure the feature:
a. log_bin_basename and general_log_file
Execute the following commands for each log file location requiring corrected permissions and ownership:
chmod 660 <log file>
chown mysql:mysql <log file>
b. audit_log_file
Execute the following commands for the audit_log_file discovered in the audit procedure:
chmod 660 <audit_log_file>
chown mysql:mysql <audit_log_file>
Password Hashing Method#
Ensure that all the accounts use a strong password hashing method.
In MySQL 8.x, the password hashing method of each account is set by its authentication plugin. The old_passwords variable and the weak mysql_old_password plugin no longer exist.
Accepted plugins are as follows:
a. caching_sha2_password (the default in MySQL 8.x)
b. sha256_password
c. mysql_native_password
Risk/Impact#
Risk Rating: Medium
A weaker password hashing algorithm makes passwords weaker and more vulnerable to attacks.
Verification/Implementation steps#
List the authentication plugin of each account:
SELECT user, host, plugin FROM mysql.user;
Ensure that every account uses one of the accepted plugins. Do not add old_passwords to my.cnf: MySQL 8.x does not recognize it, and mysqld does not start.
secure_auth#
In earlier MySQL versions, the secure_auth option determined whether the server permits connections from clients using accounts with passwords stored in the mysql_old_password format.
In MySQL 8.x, the mysql_old_password format is no longer supported and the secure_auth option was removed, so secure authentication is always enforced.
Risk/Impact#
Risk Rating: Medium
Allowing connections from accounts using the mysql_old_password format weakens authentication security, making the system vulnerable to attacks and unauthorized access.
Verification/Implementation steps#
No configuration is required on MySQL 8.x. Do not add secure_auth to my.cnf: MySQL 8.x does not recognize the option, and mysqld does not start.
NO_AUTO_CREATE_USER#
In earlier MySQL versions, NO_AUTO_CREATE_USER was an option for sql_mode that prevents a GRANT statement from automatically creating a user when authentication information is not provided.
In MySQL 8.x, this protection is built in: a GRANT statement can no longer create a user, and the NO_AUTO_CREATE_USER option was removed.
Risk/Impact#
Risk Rating: Medium
If a GRANT statement can create user accounts without authentication details, unauthorized or unintended accounts can be created, increasing the risk of security breaches and unauthorized access to the database.
Verification/Implementation steps#
No configuration is required on MySQL 8.x. Do not add NO_AUTO_CREATE_USER to the sql_mode setting: MySQL 8.x rejects the value, and mysqld does not start.
Create each account explicitly with CREATE USER before you grant privileges to it:
CREATE USER '<user>'@'<host>' IDENTIFIED BY '<clear password>';
GRANT <privileges> ON <database>.* TO '<user>'@'<host>';
Passwords will be set for all MySQL Accounts#
In MySQL, accounts with blank passwords permit users to log in without using any password.
Risk/Impact#
Risk Rating: High
User accounts with blank passwords can easily log in to MySQL; this configuration poses significant security risks.
Verification/Implementation steps#
List the accounts that do not have a password:
SELECT user, host FROM mysql.user WHERE authentication_string = '';
For each row returned, set a password for the given user. For example:
ALTER USER '<user>'@'<host>' IDENTIFIED BY '<clear password>';
Note: Replace <user>, <host>, and <clear password> with appropriate values.
Passwords Policy#
Password complexity includes password characteristics such as length, case, and character sets.
Risk/Impact#
Risk Rating: High
An easy characteristic password can be decoded easily, which poses significant security risks.
Verification/Implementation steps#
Perform the following actions to remediate this setting:
a. Make sure that the [mysqld] section of my.cnf loads the validate_password plugin, and set the policy according to the organization's password policy:
plugin-load-add=validate_password.so
validate_password_policy=<LOW | MEDIUM | STRONG>
validate_password_length=<minimum password length>
Restart Percona for the settings to take effect.
b. Set or change passwords with ALTER USER, so that they are checked against the policy. For example:
ALTER USER '<user>'@'<host>' IDENTIFIED BY '<clear password>';
Note: Replace <user>, <host>, and <clear password> with appropriate values.
Prevent Users from having Wildcard Hostnames#
MySQL can make use of host wildcards when granting permission to users on specific databases.
For Example: you may grant a given privilege to '<user>'@'%'.
Risk/Impact#
Risk Rating: Medium
Allowing users with wildcard hostnames (e.g., <user>@'%') can expose the database to unauthorized access from any IP address. This increases the risk of potential security breaches, unauthorized logins, and data compromise, as access is not restricted to specific trusted hosts.
Verification/Implementation steps#
Perform the following actions to remediate this setting:
1. List the accounts that have a wildcard host:
SELECT user, host FROM mysql.user WHERE host = '%';
2. For each account returned, either restrict the account to a specific host or drop the account.
To restrict the account to a specific host:
RENAME USER '<user>'@'%' TO '<user>'@'<host>';
To drop the account:
DROP USER '<user>'@'%';
Note: Before you restrict or drop an account, check which hosts connect with it. HEAL services connect to Percona from several hosts, and an account that is restricted to one host can no longer be used from the others.
Removed Anonymous Account#
Anonymous accounts are users with empty usernames (''). Anonymous accounts have no passwords, so anyone can use them to connect to the MySQL server.
Risk/Impact#
Risk Rating: Medium
Anonymous accounts pose a serious security risk as they allow unauthenticated access to the MySQL server. This can lead to unauthorized data access, and potential exploitation by attackers.
Verification/Implementation steps#
Perform the following actions to remediate this setting:
1. List the anonymous accounts:
SELECT user, host FROM mysql.user WHERE user = '';
2. Drop each anonymous account:
DROP USER ''@'<host>';
Note: As an alternative, you may execute the mysql_secure_installation utility.
ssl_type#
The ssl_type will be set to ANY, X509, or SPECIFIED.
All network traffic must use SSL/TLS when traveling over untrusted networks. SSL/TLS should be enforced on a per-user basis for users (remote users) who enter the system through the network.
Risk/Impact#
Risk Rating: High
Failing to enforce SSL/TLS for remote users exposes sensitive data to interception, man-in-the-middle attacks, and unauthorized access.
Verification/Implementation steps#
List the remote accounts and their SSL requirement:
SELECT user, host, ssl_type FROM mysql.user WHERE host NOT IN ('localhost', '127.0.0.1', '::1');
Use the ALTER USER statement to require the use of SSL for an account. In MySQL 8.x, the GRANT statement can no longer set this requirement.
ALTER USER '<user>'@'<host>' REQUIRE SSL;
Note: An account that requires SSL can no longer be used by clients that connect without TLS. Some HEAL components connect to Percona without TLS, so do not require SSL on the accounts that HEAL services use (dbadmin, appsonedb, and replicator).
MASTER_SSL_VERIFY_SERVER_CERT#
The ‘MASTER_SSL_VERIFY_SERVER_CERT’ will be set to ‘YES’ or ‘1’.
In the MySQL slave context, the setting MASTER_SSL_VERIFY_SERVER_CERT indicates whether the slave should verify the master's certificate. This configuration item may be set to Yes or No, and unless SSL has been enabled on the slave, the value will be ignored.
Risk/Impact#
Risk Rating: Medium
If MASTER_SSL_VERIFY_SERVER_CERT is not set to YES or 1, the MySQL slave may connect to an untrusted or compromised master server, leading to potential data breaches, man-in-the-middle attacks, and unauthorized data replication.
Verification/Implementation steps#
To remediate this setting, run the following statements on the replica. In MySQL 8.0.23 and later, the setting is named SOURCE_SSL_VERIFY_SERVER_CERT:
STOP REPLICA;
CHANGE REPLICATION SOURCE TO SOURCE_SSL=1, SOURCE_SSL_CA='<CA certificate file>', SOURCE_SSL_VERIFY_SERVER_CERT=1;
START REPLICA;
Note: With this setting, the replica checks that the source server's certificate is valid and that it matches the host name the replica connects to. Use the CA certificate that signed the source server's certificate, and make sure that the certificate matches the source host name. Otherwise, the replica cannot connect and replication stops.
User accounts created by default should be disabled or renamed#
Accounts that are not used but are active could be a serious security risk. Accounts that have not been used for a long period should be removed, if not required.
Risk/Impact#
Risk Rating: Low
For an attacker it would be easy to guess the default username to get access to the system and try to perform a brute force attack.
Verification/Implementation steps#
List the accounts, and review which of them are still required:
SELECT user, host, account_locked FROM mysql.user;
To disable a default account that is not required, lock it:
ALTER USER '<user>'@'<host>' ACCOUNT LOCK;
To rename it:
RENAME USER '<user>'@'<host>' TO '<new user>'@'<host>';
To remove it:
DROP USER '<user>'@'<host>';
Note: Do not drop or rename the reserved accounts mysql.sys, mysql.session, and mysql.infoschema, which MySQL creates locked and requires, or the accounts that HEAL services use (dbadmin, appsonedb, and replicator).