Database encryption is an important part of protecting sensitive information, but encrypting database files is only one part of the process. MySQL also needs a secure place to store the encryption keys used to protect those files. If someone gains access to the encryption keys, the protection provided by data-at-rest encryption can be weakened.
Percona Server for MySQL provides the component_percona_keyring_encrypted_file component to address this requirement. It stores encryption keys in an encrypted file on the database server instead of keeping them as readable JSON data. The component uses a password to protect the keyring file and makes those keys available to MySQL features such as InnoDB tablespace encryption and encrypted database logs.
This article explains how the component works, how to configure it, how to verify that it is active, and what to consider when managing passwords, backups, and encryption keys in a production environment.
What Is the Percona Keyring Encrypted File Component?
A keyring is a secure storage mechanism for encryption keys. MySQL uses these keys when it needs to encrypt or decrypt database information. For example, when InnoDB encrypts a tablespace, it uses encryption keys managed through the configured keyring.
Percona Server for MySQL 8.4.13-13 introduced the component_percona_keyring_encrypted_file component. It stores keyring information in an encrypted file protected by a password.
This is different from the standard component_keyring_file component, which stores its keyring data as plaintext JSON on the filesystem. Although filesystem permissions can restrict access to that file, its contents are not encrypted by the component itself.
The encrypted file component uses PBKDF2 and AES to protect the keyring data. It derives an encryption key from the configured password and uses that key to encrypt the keyring payload.
The following table compares the two file-based options.
Feature | component_keyring_file | component_percona_keyring_encrypted_file |
Storage location | Local filesystem | Local filesystem |
Keyring file format | Plaintext JSON | Encrypted data |
Password protection | Not provided by the component | Required |
Encryption method | No file encryption | PBKDF2 and AES |
Suitable for | Basic local key storage | Password-protected local key storage |
Percona Server 8.4 support | Yes | Yes, from 8.4.13-13 |
The encrypted component is useful when you want to keep encryption keys on the database server but also want the keyring file itself to be protected by encryption.
It is important to understand that protecting the keyring file does not automatically encrypt database tables. The component makes encryption keys available to MySQL. You must separately enable data-at-rest encryption for the database objects and logs you want to protect.
How the Encrypted Keyring Works
The component stores its keyring payload as JSON internally, but the file written to disk is encrypted. When MySQL starts, the component reads the configured password, opens the encrypted keyring file, and makes the stored keys available to the server.
The encryption process uses the following steps:
The component takes the configured password.
PBKDF2-HMAC-SHA256 derives a 256-bit encryption key from that password.
The component generates a random salt and initialization vector.
AES encrypts the keyring payload.
The encrypted data is stored in the configured keyring file.
The default PBKDF2 iteration count is 600,000.
The encrypted file contains a version field, salt, iteration count, initialization vector, and ciphertext. This information allows the component to derive the required encryption key and decrypt the keyring when the server starts.
The password is therefore a critical part of the configuration. If the keyring file is available but the password is missing or incorrect, MySQL cannot access the keys stored inside it.
Preparing the MySQL Server
Before configuring the component, check the Percona Server version.
The encrypted keyring component is available in Percona Server for MySQL 8.4 starting with release 8.4.13-13. If you are using an earlier release, verify the available upgrade path before following this configuration.
You should also identify the MySQL installation paths.
Connect to MySQL and run:
SELECT VERSION();
SELECT @@plugin_dir;
SELECT @@datadir;
The plugin directory contains the component configuration file. The data directory contains database files and can also hold a local component manifest or configuration file when the corresponding options are enabled.
Do not place the encrypted keyring data file inside the MySQL data directory. Use a separate directory with restricted filesystem permissions.
For example, create a dedicated directory:
sudo mkdir -p /var/lib/mysql-keyring
sudo chown mysql:mysql /var/lib/mysql-keyring
sudo chmod 750 /var/lib/mysql-keyring
The MySQL server process needs read and write access to this directory because the component creates and updates the keyring file there.
Configuring the Component Manifest
Unlike ordinary SQL-installable components, the keyring component must load before InnoDB initializes. This is important because InnoDB may need encryption keys while opening tablespaces or recovering database logs.
For this reason, Percona Server uses a manifest file to load the keyring component during server startup.
The manifest file is named mysqld.my. For a typical Linux package installation, the global manifest is located in the directory containing the MySQL server binary, often /usr/sbin.
Create or update:
sudo nano /usr/sbin/mysqld.my
Add the following JSON configuration:
{
"read_local_manifest": false,
"components": "file://component_percona_keyring_encrypted_file"
}
The components property identifies the component that MySQL should load.
The read_local_manifest property controls whether the server should use a local manifest from the data directory. Setting it to false tells the server to use the component declaration in the global manifest.
If you run multiple MySQL instances on the same host and need a different keyring component for each instance, you can use a global manifest that delegates to a local manifest:
{
"read_local_manifest": true
}
The local manifest in the instance's data directory can then contain:
{
"components": "file://component_percona_keyring_encrypted_file"
}
The correct manifest location depends on how Percona Server was installed. Package installations, tarball installations, containers, and custom builds may use different locations. Confirm the directory containing the actual mysqld binary before creating the file.
Do not attempt to load this keyring component using INSTALL COMPONENT. That SQL statement runs after the SQL layer becomes available, which is too late for InnoDB initialization and crash recovery. The manifest is the supported loading mechanism.
Creating the Encrypted Keyring Configuration
After configuring the manifest, create the component configuration file.
The file is named:
component_percona_keyring_encrypted_file.cnf
The global configuration file normally resides in the MySQL plugin directory. You can confirm the directory using:
SELECT @@plugin_dir;
For example, a typical Debian or Ubuntu installation may use /usr/lib/mysql/plugin, while an RHEL-based installation may use /usr/lib64/mysql/plugin.
The component supports several configuration properties:
Property | Purpose |
path | Absolute path to the encrypted keyring data file |
read_only | Controls whether the component accepts key changes |
password | Password used to encrypt and decrypt the keyring file |
password_file | Path to a file containing the password |
read_local_config | Controls whether a local configuration file is read |
The read_only property is mandatory. Set it to false when MySQL needs to create or update keys. A read-only keyring rejects runtime changes, including adding or removing keys.
You must configure either password or password_file, but not both.
Option 1: Configure the password directly
Create the configuration file in the plugin directory:
sudo nano /usr/lib/mysql/plugin/component_percona_keyring_encrypted_file.cnf
Add the following configuration:
{
"path": "/var/lib/mysql-keyring/encrypted_keyring",
"read_only": false,
"password": "Replace-With-A-Strong-Secret"
}
Replace the example password with a strong, securely generated secret.
This configuration is straightforward, but the password is stored directly in the component configuration file. Anyone who can read that file may be able to obtain the password.
Option 2: Store the password in a separate file
For production environments, using a separate password file can make secret management easier.
Create a password file:
sudo nano /var/lib/mysql-keyring/keyring.password
Place the password inside it:
Replace-With-A-Strong-Secret
Update the component configuration:
{
"path": "/var/lib/mysql-keyring/encrypted_keyring",
"read_only": false,
"password_file": "/var/lib/mysql-keyring/keyring.password"
}
This keeps the password out of the main component configuration file. However, it does not eliminate the need to protect the password file. The MySQL server process must be able to read it, and other users should not have unnecessary access.
The component also supports read_local_config in the global configuration file. When enabled, the component reads its configuration from a local file in the data directory instead of using the other settings in the global file. This can be useful when different MySQL instances need separate configurations.
Setting Secure File Permissions
Correct file permissions are an important part of the keyring setup. An encrypted keyring provides limited protection if the password file or configuration file is readable by unauthorized users.
For a typical Linux installation, you can use the following permissions as a starting point.
Protect the manifest:
sudo chown root:root /usr/sbin/mysqld.my
sudo chmod 644 /usr/sbin/mysqld.my
Protect the component configuration:
sudo chown root:root \
/usr/lib/mysql/plugin/component_percona_keyring_encrypted_file.cnf
sudo chmod 640 \
/usr/lib/mysql/plugin/component_percona_keyring_encrypted_file.cnf
Protect the password file:
sudo chown mysql:mysql \
/var/lib/mysql-keyring/keyring.password
sudo chmod 600 \
/var/lib/mysql-keyring/keyring.password
The keyring directory should remain accessible to the MySQL server process:
sudo chown mysql:mysql /var/lib/mysql-keyring
sudo chmod 750 /var/lib/mysql-keyring
Adjust these paths and ownership settings according to your installation. The MySQL server user needs read access to the manifest, component configuration, and password file. It also needs read and write access to the keyring directory.
Starting and Verifying the Component
After creating the manifest and configuration files, restart MySQL:
sudo systemctl restart mysql
Once the server is running, connect to MySQL and inspect the keyring component status:
SELECT *
FROM performance_schema.keyring_component_status;
A successfully loaded component should report values similar to these:
Status key | Expected value |
Component_name | component_percona_keyring_encrypted_file |
Component_status | Active |
Data_file | Configured keyring file path |
Read_only | Yes or No, according to configuration |
Password | SET when an inline password is configured |
Password_file | Configured password file path, when used |
You can also run a smaller query:
SELECT STATUS_KEY, STATUS_VALUE
FROM performance_schema.keyring_component_status
WHERE STATUS_KEY IN (
'Component_name',
'Component_status',
'Data_file',
'Read_only'
);
The Active status confirms that the component is loaded and ready to provide encryption keys.
It does not confirm that database tables or logs are encrypted. You must enable data-at-rest encryption separately and verify the encryption settings for the relevant database objects.
Using the Keyring for Data-at-Rest Encryption
Once the encrypted keyring component is active, MySQL can use its keys for supported encryption features.
In Percona Server, these include InnoDB tablespace encryption, system tablespace encryption, redo and undo log encryption, and binary and relay log encryption.
For example, you can create an encrypted InnoDB table using:
CREATE TABLE customer_records (
id BIGINT PRIMARY KEY,
customer_name VARCHAR(150),
email VARCHAR(200)
)
ENGINE = InnoDB
ENCRYPTION = 'Y';
The ENCRYPTION = 'Y' option requests encryption for the table's InnoDB tablespace. The keyring component provides the key management support required by the encryption feature.
You can also set encryption as the default for a schema:
CREATE DATABASE secure_customer_data
DEFAULT ENCRYPTION = 'Y';
Tables created in the schema can inherit the schema's default encryption setting, subject to the applicable table and server configuration.
For production systems, do not assume that creating an encrypted table protects every database file. Review the encryption requirements for tablespaces, system tablespaces, redo logs, undo logs, binary logs, and relay logs separately.
Rotating Encryption Keys
Key rotation is an important part of database security. It reduces the period for which a particular encryption key remains in use and can support internal security policies.
For InnoDB master key rotation, use the supported SQL statement:
ALTER INSTANCE ROTATE INNODB MASTER KEY;
This operation rotates the InnoDB master encryption key. It is different from changing the password used to encrypt the keyring file.
Do not manually delete, replace, or edit the encrypted keyring file to rotate encryption keys. Existing encrypted database objects may depend on keys stored in that file. Removing the keyring data can make those objects inaccessible.
Changing the keyring password
Changing the password in the component configuration does not automatically re-encrypt an existing keyring file.
Percona's documented password-change procedure uses a temporary component_keyring_file component to migrate the keys. The process requires stopping MySQL, migrating the keys to the temporary unencrypted keyring, configuring the encrypted component with the new password, and migrating the keys back into a newly encrypted keyring file.
The general sequence is:
Prepare the temporary keyring configuration.
Stop the MySQL server.
Use mysql_migrate_keyring to migrate keys from the encrypted component to the temporary file component.
Configure the encrypted component with the new password.
Move the old encrypted keyring file to a secure backup location.
Migrate the keys back to the encrypted component.
Remove the temporary unencrypted keyring file after verifying the migration.
Start MySQL and verify that the encrypted component is active.
The migration utility supports source and destination component names and configuration directories. A representative command for migrating keys back into the encrypted component is:
mysql_migrate_keyring \
--verbose \
--component-dir=/usr/lib/mysql/plugin \
--source-keyring=component_keyring_file \
--source-keyring-configuration-dir=/var/lib/mysql \
--destination-keyring=component_percona_keyring_encrypted_file \
--destination-keyring-configuration-dir=/var/lib/mysql
Adjust the component directory and configuration directories to match your installation. Both components must have valid configuration files for the migration.
Keep the server stopped throughout the migration. The temporary file keyring stores keys without encryption, so protect it carefully and remove it after successful migration. Retain the original encrypted keyring file and its old password until you have verified that the new keyring can access the encrypted database objects.
Backup and Restore Considerations
A database backup is not complete if it contains encrypted tablespaces but does not include the keyring material required to decrypt them.
For a file-based encrypted keyring, your backup and recovery plan must preserve:
The encrypted keyring data file.
The password used to decrypt the keyring.
The component configuration and required manifest settings.
The encrypted database files and logs.
The filesystem permissions and ownership needed by the MySQL server.
The keyring file and password should be protected independently from ordinary database backup files. Avoid placing the password in an unprotected backup directory or storing it alongside the keyring without additional access controls.
During recovery, restore the keyring file and configure the correct password before starting MySQL with encrypted data. The destination server must be able to access the same key material that was used to encrypt the database objects.
Test the complete restore procedure on a separate host. A restore that succeeds on the original server does not necessarily prove that the backup contains everything required for disaster recovery.
For Percona XtraDB Cluster, the local keyring file is not automatically replicated between nodes. Each node must have access to the required keyring material before it starts with encrypted data. Plan the secure distribution of the keyring file and password as part of cluster provisioning and recovery.
Common Mistakes to Avoid
Mistake | Why it causes problems | Recommended approach |
Loading multiple keyring components | Percona Server supports only one active keyring at a time | Configure exactly one keyring component |
Using INSTALL COMPONENT | The SQL layer becomes available too late for keyring initialization | Load the component through mysqld.my |
Storing the password in an accessible file | Unauthorized users may obtain the keyring password | Restrict access to the configuration and password files |
Placing the keyring inside the data directory | This does not follow the component's required path configuration | Use an absolute path outside the data directory |
Changing the password without migrating keys | The existing encrypted file cannot simply be opened with the new password | Follow the documented key migration procedure |
Deleting the keyring file | Encrypted database objects may become unrecoverable | Preserve the keyring and its password |
Assuming Active means data is encrypted | Component availability and database encryption are separate things | Verify encryption settings independently |
Forgetting the keyring during backup | Restored encrypted data may not be accessible | Include keyring recovery in backup testing |
Troubleshooting Keyring Initialization
If MySQL fails to start after enabling the component, check the server error log first.
You can find the configured error log location using:
SELECT @@log_error;
If the server cannot start, inspect the MySQL error log directly from the operating system.
Common problems include:
The manifest file contains invalid JSON.
The component name in the manifest is incorrect.
The component configuration file is missing or incorrectly named.
Both password and password_file are configured.
The configured password is empty or incorrect.
The MySQL server process cannot read the password file.
The keyring directory does not exist or is not writable.
The keyring file path is relative or points inside the MySQL data directory.
If the component is loaded but reports Disabled, investigate the configuration and password errors in the server log. An incorrect password can prevent the component from decrypting an existing keyring file.
The component also supports reloading its configuration:
ALTER INSTANCE RELOAD KEYRING;
This can be useful after changing component configuration settings. The reload must be able to decrypt the existing keyring file with the configured password. A failed reload can leave the component disabled, so verify its status after the operation.
Advantages and Limitations
The encrypted file component provides a practical way to protect locally stored encryption keys without requiring an external key management service.
Its main advantages include:
Encryption of the keyring data file instead of storing the payload as plaintext JSON.
Integration with Percona Server's data-at-rest encryption features.
Password-based protection using PBKDF2 and AES.
Support for a separate password file.
Local storage that can be managed with standard filesystem permissions.
Compatibility with InnoDB tablespace and supported log encryption features.
There are also limitations to consider.
The keyring depends on a local file and a password. If either becomes unavailable, encrypted database data may become inaccessible. Password rotation requires a migration procedure rather than a simple configuration change. The component also does not provide the same centralized key lifecycle management as a dedicated key management system or hardware security module.
If your organization requires centralized access policies, key auditing, or externally managed key lifecycle controls, evaluate Percona's other supported keyring backends, such as KMIP, KMS, or Vault.
Best Practices for Production Environments
When using the encrypted keyring component in production, treat the keyring file and its password as critical recovery assets.
Use a separate password file with strict permissions instead of placing the password directly in a broadly accessible configuration file. Keep the keyring data outside the MySQL data directory, and ensure that only the required operating-system accounts can access it.
Maintain secure backups of the keyring file and password. Protect them against unauthorized access and accidental deletion. Include the keyring restoration steps in your database disaster recovery documentation.
Before upgrading Percona Server, changing the keyring password, moving database files, or changing component configuration, take a verified backup and test the procedure in a non-production environment.
Finally, monitor the component status and server error log. A keyring that is unavailable can affect database startup and access to encrypted data, so it should be treated as a critical database dependency.
Summary
The Percona Keyring Encrypted File Component provides password-protected storage for encryption keys in Percona Server for MySQL. It uses PBKDF2-HMAC-SHA256 and AES to encrypt the keyring file, helping protect the keys stored on the database server.
Setting it up requires a startup manifest, a component configuration file, a secure password, and correct filesystem permissions. Once the component is active, you can use it with supported MySQL data-at-rest encryption features.
The most important operational lesson is that the keyring file and its password must remain available for the lifetime of the encrypted data. Back up both, test restoration on another server, and use the documented migration procedure when changing the keyring password. These steps help prevent a security improvement from becoming a database recovery problem.
Percona Server for MySQLMySQL keyringencryption keysencrypted file keyringdata-at-rest encryptionPBKDF2AES
Join the conversation! Your thoughts help the community grow.