On this page
Amazon Web Services (AWS) Key Management Service (KMS) Encryption Plugin Setup Guide
Overview
MariaDB contains a robust, full instance, at-rest encryption. This feature uses a flexible plugin interface to allow actual encryption to be done using a key management approach that meets the customer's needs. MariaDB Server, starting with MariaDB 10.2, includes a plugin that uses the Amazon Web Services (AWS) Key Management Service (KMS) to facilitate separation of responsibilities and remote logging & auditing of key access requests.
Rather than storing the encryption key in a local file, this plugin keeps the master key in AWS KMS. When you first start MariaDB, the AWS KMS plugin will connect to the AWS Key Management Service and ask it to generate a new key. MariaDB will store that key on-disk in an encrypted form. The key stored on-disk cannot be used to decrypt the data; rather, on each startup, MariaDB connects to AWS KMS and has the service decrypt the locally-stored key(s). The decrypted key is stored in-memory as long as the MariaDB server process is running, and that in-memory decrypted key is used to encrypt the local data.
This guide is based on CentOS 7, using systemd with SELinux enabled. Some steps will differ if you use other operating systems or configurations.
Installing the Plugin's Package
The AWS Key Management plugin depends on the AWS SDK for C++, which uses the Apache License, Version 2.0. This license is not compatible with MariaDB Server's GPL 2.0 license, so we are not able to distribute packages that contain the AWS Key Management plugin. Therefore, the only way to currently obtain the plugin is to install it from source.
Installing from Source
When compiling MariaDB from source, the AWS Key Management plugin is not built by default in MariaDB 10.1, but it is built by default in MariaDB 10.2 and later, on systems that support it.
Compilation is controlled by the -DPLUGIN_AWS_KEY_MANAGEMENT=DYNAMIC -DAWS_SDK_EXTERNAL_PROJECT=1 cmake arguments.
The plugin uses AWS C++ SDK, which introduces the following restrictions:
- The plugin can only be built on Windows, Linux and macOS.
- The plugin requires that one of the following compilers is used:
gcc4.8 or later,clang3.3 or later, Visual Studio 2013 or later. - On Unix, the
libcurldevelopment package (e.g.libcurl3-devon Debian Jessie),uuiddevelopment package andopensslneed to be installed. - You may need to use a newer version of cmake than is provided by default in your OS.
Installing the Plugin
Even after the package that contains the plugin's shared library is installed on the operating system, the plugin is not actually installed by MariaDB by default. There are two methods that can be used to install the plugin with MariaDB.
The first method can be used to install the plugin without restarting the server. You can install the plugin dynamically by executing INSTALL SONAME or INSTALL PLUGIN. For example:
INSTALL SONAME 'aws_key_management';
The second method can be used to tell the server to load the plugin when it starts up. The plugin can be installed this way by providing the --plugin-load or the --plugin-load-add options. This can be specified as a command-line argument to mysqld or it can be specified in a relevant server option group in an option file. For example:
[mariadb]
...
plugin_load_add = aws_key_management
Sign up for Amazon Web Services
If you already have an AWS account, you can skip this section.
- Load http://aws.amazon.com/.
- Click "Create a Free Account" and complete the steps.
- You'll need to enter credit card information. Charges related only to your use of the AWS KMS service should be limited to about $1/month for the single master key we will create. If you use other services, additional charges may apply. Consult AWS Cloud Pricing Principles https://aws.amazon.com/pricing/ for more information about pricing of AWS services.
- You'll need to complete the AWS identify verification process.
Create an IAM User and/or Role
After creating an account or logging in to an existing account, follow these steps to create an IAM User or Role with restricted privileges that will use (but not administer) your master encryption key.
If you intend to run MariaDB Server on an EC2 instance, you should create a Role (or modify an existing Role already attached to your instance). If you intent to run MariaDB Server outside of AWS, you may want to create a User.
Creating an IAM Role
- Load the Identity and Access Management Console at https://console.aws.amazon.com/iam/.
- Click "Roles" in the left-hand sidebar
- Click "Create new role"
- Select "AWS Service Role"
- Click the "Select" button next to "Amazon EC2 / Allows EC2 instances to call AWS services on your behalf."
- Do not select any policies on the "Attach Policy" screen. Click "Next Step"
- Click "Next Step"
- Give your Role a "Role name"
- Click "Create role"
Creating an IAM User
- Load the Identity and Access Management Console at https://console.aws.amazon.com/iam/.
- Click "Users" in the left-hand sidebar.
- Click the "Create New Users" button
- Enter a single User Name of your choosing. We'll use "MDBEnc" for this demonstration. Keep the "Generate an access key for each user" box checked.