Encryption Plugin API
MariaDB's data-at-rest encryption requires the use of a key management and encryption plugin. These plugins are responsible both for the management of encryption keys and for the actual encryption and decryption of data.
MariaDB supports the use of multiple encryption keys. Each encryption key uses a 32-bit integer as a key identifier. If the specific plugin supports key rotation, encryption keys can also be rotated, which creates a new version of the encryption key.
See Data at Rest Encryption and Encryption Key Management for more information.
Encryption Plugin API
The Encryption plugin API was created to allow a plugin to:
implement key management, provide encryption keys to the server on request and change them according to internal policies.
implement actual data encryption and decryption with the algorithm defined by the plugin.
This is how the API reflects that:
The first method is used for key rotation. A plugin that doesn't support key rotation — for example, file_key_management — can return a fixed version for any valid key id. Note that it still has to return an error for an invalid key id. The version ENCRYPTION_KEY_NOT_ENCRYPTED means that the data should not be encrypted.
The second method is used for key management, the server uses it to retrieve the key corresponding to a specific key identifier and a specific key version.
The last five methods deal with encryption. Note that they take the key to use and key identifier and version. This is needed because the server can derive a session-specific, user-specific, or a tablespace-specific key from the original encryption key as returned by get_key(), so the key argument doesn't have to match the encryption key as the plugin knows it. On the other hand, the encryption algorithm may depend on the key identifier and version (and in the example_key_management plugin it does) so the plugin needs to know them to be able to encrypt the data.
Encryption methods are optional — if unset (as in the debug_key_management plugin), the server will fall back to AES_CBC.
Current Encryption Plugins
The MariaDB source tree has four encryption plugins. All these plugins are fairly simple and can serve as good examples of the Encryption plugin API.
file_key_management
It reads encryption keys from a plain-text file. It supports two different encryption algorithms. It supports multiple encryption keys. It does not support key rotation. See File Key Management Plugin for details.
aws_key_management
The AWS Key Management plugin uses the Amazon Web Services (AWS) Key Management Service (KMS) to generate and store AES keys on disk, in encrypted form, using the Customer Master Key (CMK) kept in AWS KMS. When MariaDB Server starts, the plugin will decrypt the encrypted keys, using the AWS KMS "Decrypt" API function. MariaDB data will then be encrypted and decrypted using the AES key. It supports multiple encryption keys. It supports key rotation.
See AWS Key Management Plugin for details.
example_key_management
Uses random time-based generated keys, ignores key identifiers, supports key versions and key rotation. Uses AES_ECB and AES_CBC as encryption algorithms and changes them automatically together with key versions.
debug_key_management
Key is generated from the version, user manually controls key rotation. Only supports key identifier 1, uses only AES_CBC.
Encryption Service
Encryption is generally needed on the very low level inside the storage engine. That is, the storage engine needs to support encryption and have access to the encryption and key management functionality. The usual way for a plugin to access some functionality in the server is via a service. In this case the server provides the Encryption Service for storage engines (and other interested plugins) to use. These service functions are directly hooked into encryption plugin methods (described above).
Service functions are declared as follows:
There are also convenience helpers to check for a key or key version existence and to encrypt or decrypt a block of data with one function call.
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

