{"id":4413,"date":"2020-03-24T17:20:31","date_gmt":"2020-03-24T15:20:31","guid":{"rendered":"http:\/\/www.laurentmarot.fr\/wordpress\/?p=4413"},"modified":"2020-04-29T13:22:37","modified_gmt":"2020-04-29T11:22:37","slug":"data-at-rest-encryption-with-mariadb","status":"publish","type":"post","link":"https:\/\/www.laurentmarot.fr\/wordpress\/?p=4413","title":{"rendered":"Data-at-Rest Encryption with MariaDB"},"content":{"rendered":"<h1>Data-at-Rest Encryption Overview<\/h1>\n<p>&nbsp;<\/p>\n<p>Source\u00a0 : <a href=\"https:\/\/mariadb.com\/kb\/en\/file-key-management-encryption-plugin\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/mariadb.com\/kb\/en\/file-key-management-encryption-plugin\/<\/a><\/p>\n<p>Encryption of tables and tablespaces was added in <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-1013-release-notes\/\">MariaDB 10.1.3<\/a>.<\/p>\n<p>Having tables encrypted makes it almost impossible for someone to access or steal a hard disk and get access to the original data. MariaDB got Data-at-Rest Encryption with <a href=\"https:\/\/mariadb.com\/kb\/en\/what-is-mariadb-101\/\">MariaDB 10.1<\/a>. This functionality is also known as \u00ab\u00a0<strong>Transparent Data Encryption<\/strong> (TDE)\u00a0\u00bb.<\/p>\n<p>This assumes that encryption keys are stored on another system.<\/p>\n<p>Using encryption has an overhead of roughly <em>3-5%<\/em>.<\/p>\n<p>MariaDB encryption is fully supported for the <a href=\"https:\/\/mariadb.com\/kb\/en\/xtradb-and-innodb\/\">XtraDB and InnoDB<\/a> storage engines. Encryption is also supported for the Aria storage engine, but only for tables created with <code>ROW_FORMAT=PAGE<\/code> (the default), and for the binary log (replication log).<\/p>\n<p>MariaDB allows the user to configure flexibly what to encrypt. In XtraDB or InnoDB, one can choose to encrypt:<\/p>\n<ul>\n<li>everything \u2014 all tablespaces (with all tables)<\/li>\n<li>individual tables<\/li>\n<li>everything, excluding individual tables<\/li>\n<\/ul>\n<p>Additionally, one can choose to encrypt XtraDB\/InnoDB log files (recommended).<\/p>\n<p>MariaDB&rsquo;s data-at-rest encryption requires the use of a <a href=\"https:\/\/mariadb.com\/kb\/en\/encryption-key-management\/\">key management and encryption plugin<\/a>. These plugins are responsible both for the management of encryption keys and for the actual encryption and decryption of data.<\/p>\n<p>MariaDB supports the use of <a href=\"https:\/\/mariadb.com\/kb\/en\/encryption-key-management\/#using-multiple-encryption-keys\">multiple encryption keys<\/a>. Each encryption key uses a 32-bit integer as a key identifier. If the specific plugin supports <a href=\"https:\/\/mariadb.com\/kb\/en\/encryption-key-management\/#rotating-keys\">key rotation<\/a>, then encryption keys can also be rotated, which creates a new version of the encryption key.<\/p>\n<p>How MariaDB manages encryption keys depends on which encryption key management solution you choose. Currently, MariaDB has three options:<\/p>\n<ul>\n<li><a href=\"https:\/\/mariadb.com\/kb\/en\/file-key-management-encryption-plugin\/\">File Key Management Plugin<\/a><\/li>\n<li><a href=\"https:\/\/mariadb.com\/kb\/en\/aws-key-management-encryption-plugin\/\">AWS Key Management Plugin<\/a><\/li>\n<li><a href=\"https:\/\/mariadb.com\/kb\/en\/eperi-key-management-encryption-plugin\/\">Eperi Key Management Plugin<\/a><\/li>\n<\/ul>\n<h3 id=\"file-key-management-plugin\" class=\"anchored_heading\">File Key Management Plugin<\/h3>\n<p>The File Key Management plugin that ships with MariaDB is a basic key management and encryption plugin that reads keys from a plain-text file. It can also serve as example and as a starting point when developing a key management plugin.<\/p>\n<p>For more information, see <a href=\"https:\/\/mariadb.com\/kb\/en\/file-key-management-encryption-plugin\/\">File Key Management Plugin<\/a>.<\/p>\n<h3 id=\"aws-key-management-plugin\" class=\"anchored_heading\">AWS Key Management Plugin<\/h3>\n<p>The AWS Key Management plugin is a key management and encryption plugin that uses the Amazon Web Services (AWS) Key Management Service (KMS). The AWS Key Management plugin depends on the <a href=\"https:\/\/github.com\/aws\/aws-sdk-cpp\">AWS SDK for C++<\/a>, which uses the <a href=\"https:\/\/github.com\/aws\/aws-sdk-cpp\/blob\/master\/LICENSE\">Apache License, Version 2.0<\/a>. This license is not compatible with MariaDB Server&rsquo;s <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-license\/\">GPL 2.0 license<\/a>, 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.<\/p>\n<p>For more information, see <a href=\"https:\/\/mariadb.com\/kb\/en\/aws-key-management-encryption-plugin\/\">AWS Key Management Plugin<\/a>.<\/p>\n<h3 id=\"eperi-key-management-plugin\" class=\"anchored_heading\">Eperi Key Management Plugin<\/h3>\n<p>The Eperi Key Management plugin is a key management and encryption plugin that uses the <a href=\"https:\/\/eperi.com\/database-encryption\/\">eperi Gateway for Databases<\/a>. The <a href=\"https:\/\/eperi.com\/database-encryption\/\">eperi Gateway for Databases<\/a> stores encryption keys on the key server outside of the database server itself, which provides an extra level of security. The <a href=\"https:\/\/eperi.com\/database-encryption\/\">eperi Gateway for Databases<\/a> also supports performing all data encryption operations on the key server as well, but this is optional.<\/p>\n<p>For more information, see <a href=\"https:\/\/mariadb.com\/kb\/en\/eperi-key-management-encryption-plugin\/\">Eperi Key Management Plugin<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<h1>File Key Management Encryption Plugin<\/h1>\n<p>&nbsp;<\/p>\n<p>The File Key Management plugin that ships with MariaDB is a <a href=\"https:\/\/mariadb.com\/kb\/en\/encryption-key-management\/\">key management and encryption plugin<\/a> that reads encryption keys from a plain-text file.<\/p>\n<p>The File Key Management plugin is the easiest <a href=\"https:\/\/mariadb.com\/kb\/en\/encryption-key-management\/\">key management and encryption plugin<\/a> to set up for users who want to use <a href=\"https:\/\/mariadb.com\/kb\/en\/data-at-rest-encryption\/\">data-at-rest encryption<\/a>. Some of the plugin&rsquo;s primary features are:<\/p>\n<ul>\n<li>It reads encryption keys from a plain-text key file.<\/li>\n<li>As an extra protection mechanism, the plain-text key file can be encrypted.<\/li>\n<li>It supports multiple encryption keys.<\/li>\n<li>It does <strong>not<\/strong> support key rotation.<\/li>\n<li>It supports two different algorithms for encrypting data.<\/li>\n<\/ul>\n<p>It can also serve as an example and as a starting point when developing a key management and encryption plugin with the <a href=\"https:\/\/mariadb.com\/kb\/en\/encryption-plugin-api\/\">encryption plugin API<\/a>.<\/p>\n<p>The File Key Management plugin is included in MariaDB packages as the <code>file_key_management.so<\/code> or <code>file_key_management.dll<\/code> shared library. The shared library is in the main server package, so no additional package installations are necessary.<\/p>\n<p>Although the plugin&rsquo;s shared library is distributed with MariaDB by default, the plugin is not actually installed by MariaDB by default. The plugin can be installed by providing the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/mysqld-options\/#-plugin-load\">--plugin-load<\/a><\/code> or the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/mysqld-options\/#-plugin-load-add\">--plugin-load-add<\/a><\/code> options. This can be specified as a command-line argument to <code><a href=\"https:\/\/mariadb.com\/kb\/en\/mysqld-options\/\">mysqld<\/a><\/code> or it can be specified in a relevant server <a href=\"https:\/\/mariadb.com\/kb\/en\/configuring-mariadb-with-option-files\/#option-groups\">option group<\/a> in an <a href=\"https:\/\/mariadb.com\/kb\/en\/configuring-mariadb-with-option-files\/\">option file<\/a>. For example:<\/p>\n<pre class=\"fixed\">[mariadb]\r\n...\r\nplugin_load_add = file_key_management\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-16-37-27.png\" rel=\"lightbox[4413]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-4422\" src=\"http:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-16-37-27-300x45.png\" alt=\"\" width=\"300\" height=\"45\" srcset=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-16-37-27-300x45.png 300w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-16-37-27.png 346w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>The default MariaDB option file is called my.cnf on Unix-like operating systems and my.ini on Windows. Depending on how you&rsquo;ve installed MariaDB, the default option file may be in a number of places, or it may not exist at all.<\/p>\n<p>In order to encrypt your tables with encryption keys using the File Key Management plugin, you first need to create the file that contains the encryption keys. The file needs to contain two pieces of information for each encryption key. First, each encryption key needs to be identified with a 32-bit integer as the key identifier. Second, the encryption key itself needs to be provided in hex-encoded form. These two pieces of information need to be separated by a semicolon.<\/p>\n<pre class=\"fixed\">$ sudo openssl rand -hex 32 &gt;&gt; \/etc\/mysql\/encryption\/keyfile\r\n$ sudo openssl rand -hex 32 &gt;&gt; \/etc\/mysql\/encryption\/keyfile\r\n$ sudo openssl rand -hex 32 &gt;&gt; \/etc\/mysql\/encryption\/keyfile\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The key file still needs to have a key identifier for each encryption key added to the beginning of each line. Key identifiers do not need to be contiguous. Open the new key file in your preferred text editor and add the key identifiers. For example, the key file would look something like the following after this step:<\/p>\n<p><a href=\"http:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-17-22-40.png\" rel=\"lightbox[4413]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-4424\" src=\"http:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-17-22-40-300x97.png\" alt=\"\" width=\"300\" height=\"97\" srcset=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-17-22-40-300x97.png 300w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/03\/Capture-du-2020-03-24-17-22-40.png 604w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>If the key file is unencrypted, then the File Key Management plugin only requires the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/file-key-management-encryption-plugin\/#file_key_management_filename\">file_key_management_filename<\/a><\/code> system variable to be configured.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"fixed\">[mariadb]\r\n...\r\nloose_file_key_management_filename = \/etc\/mysql\/encryption\/keyfile\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Note that the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/mysqld-options\/#-loose-\">loose<\/a><\/code> option prefix is specified. This option prefix is used in case the plugin hasn&rsquo;t been installed yet.<\/p>\n<p>&nbsp;<\/p>\n<p>The File Key Management plugin currently supports two encryption algorithms for encrypting data: <code>AES_CBC<\/code> and <code>AES_CTR<\/code>. Both of these algorithms use <a href=\"https:\/\/en.wikipedia.org\/wiki\/Advanced_Encryption_Standard\">Advanced Encryption Standard (AES)<\/a> in different modes. AES uses 128-bit blocks, and supports 128-bit, 192-bit, and 256-bit keys. The modes are:<\/p>\n<ul>\n<li>The <code>AES_CBC<\/code> mode uses AES in the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29\">Cipher Block Chaining (CBC)<\/a> mode.<\/li>\n<li>The <code>AES_CTR<\/code> mode uses AES in two slightly different modes in different contexts. When encrypting tablespace pages (such as pages in InnoDB, XtraDB, and Aria tables), it uses AES in the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Block_cipher_mode_of_operation#Counter_.28CTR.29\">Counter (CTR)<\/a> mode. When encrypting temporary files (where the cipher text is allowed to be larger than the plain text), it uses AES in the authenticated <a href=\"http:\/\/en.wikipedia.org\/wiki\/Galois\/Counter_Mode\">Galois\/Counter Mode (GCM)<\/a>.<\/li>\n<\/ul>\n<p>The recommended algorithm is <code>AES_CTR<\/code>, but this algorithm is only available when MariaDB is built with recent versions of <a href=\"https:\/\/www.openssl.org\/\">OpenSSL<\/a>. If the server is built with <a href=\"https:\/\/www.wolfssl.com\/products\/wolfssl\/\">wolfSSL<\/a> or <a href=\"https:\/\/www.wolfssl.com\/products\/yassl\/\">yaSSL<\/a>, then this algorithm is not available. See <a href=\"https:\/\/mariadb.com\/kb\/en\/tls-and-cryptography-libraries-used-by-mariadb\/\">TLS and Cryptography Libraries Used by MariaDB<\/a> for more information about which libraries are used on which platforms.<\/p>\n<ul>\n<li>Encrypting a table by setting the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/create-table\/#encrypted\">ENCRYPTED<\/a><\/code> table option to <code>YES<\/code>, and the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/innodb-system-variables\/#innodb_default_encryption_key_id\">innodb_default_encryption_key_id<\/a><\/code> system variable or the <code><a href=\"https:\/\/mariadb.com\/kb\/en\/create-table\/#encryption_key_id\">ENCRYPTION_KEY_ID<\/a><\/code> table option refers to a non-existent key identifier. In this case, <code><a href=\"https:\/\/mariadb.com\/kb\/en\/show-warnings\/\">SHOW WARNINGS<\/a><\/code> would return the following:<\/li>\n<\/ul>\n<pre class=\"fixed\">SHOW WARNINGS;\r\n+---------+------+---------------------------------------------------------------------+\r\n| Level   | Code | Message                                                             |\r\n+---------+------+---------------------------------------------------------------------+\r\n| Warning |  140 | InnoDB: ENCRYPTION_KEY_ID 500 not available                         |\r\n| Error   | 1005 | Can't create table `db1`.`tab3` (errno: 140 \"Wrong create options\") |\r\n| Warning | 1030 | Got error 140 \"Wrong create options\" from storage engine InnoDB     |\r\n+---------+------+---------------------------------------------------------------------+\r\n3 rows in set (0.00 sec)\r\n<\/pre>\n<p>see also https:\/\/severalnines.com\/blog\/exploring-different-ways-encrypt-your-mariadb-data<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Data-at-Rest Encryption Overview &nbsp; Source\u00a0 : https:\/\/mariadb.com\/kb\/en\/file-key-management-encryption-plugin\/ Encryption of tables and tablespaces was added in MariaDB 10.1.3. Having tables encrypted makes it almost impossible for someone to access or steal a hard disk and get access to the original data. MariaDB got Data-at-Rest Encryption with MariaDB 10.1. This functionality is also known as \u00ab\u00a0Transparent Data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4413"}],"collection":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4413"}],"version-history":[{"count":18,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4413\/revisions"}],"predecessor-version":[{"id":4578,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4413\/revisions\/4578"}],"wp:attachment":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}