keyring_vault store database encryption keysThis is the first of a two-part series on using the keyring_vault plugin with Percona Server for MySQL 5.7. The second part, Backing up Percona Server for MySQL with keyring_vault plugin enabledwalks through how to use Percona Xtrabackup to backup from this instance and restore to another server and set it up as a slave with keyring_vault plugin.

What is the keyring_vault plugin?

The keyring_vault is a plugin that allows the database to interface with a Hashicorp Vault server to store and secure encryption keys. The Vault server then acts as a centralized encryption key management solution which is critical for security and for compliance with various security standards.

Configuring Vault

Create SSL certificates to be used by Vault. You can use the sample ssl.conf template below to generate the necessary files.

Then run the two commands below to generate the cert and key files and the certificate chain:

Once the SSL certificates are created start Vault with the sample configuration below. Take note that you should follow the suggested best practices when deploying Vault in production, this example is to get us by with a simple working setup.

Assuming Vault started up fine and you are able to unseal Vault, the next step is to create the policy file. For more details on initializing and unsealing Vault please read the manual here.

Create a Vault policy named dc1-secrets using the dc1.hcl file like this:

Next, create a token associated with the newly created policy:

Setting up MySQL

The following instructions should work starting from Percona Server for MySQL 5.7.20-18 and through later versions.

Configure my.cnf with the following variables:

Create the keyring_vault.conf file in the path above with the following contents:

Here we are using the vault.pem file generated by combining the vault.crt and vault.key files. Observe that our secret_mount_point is secret/dc1/master. We want to make sure that this mount point is unique across all servers, this is in fact advised in the manual here.

Ensure that the CA certificate is owned by mysql user:

Initialize the MySQL data directory on the Master:

For production systems, we do not recommend using --initialize-insecure option, this is just to skip additional steps in this tutorial.

Finally, start mysqld instance and then test the setup by creating an encrypted table.

At this point, you should have Percona Server for MySQL instance with tablespace encryption using Vault.

Researching database security?

You might also enjoy this pre-recorded webinar securing your database servers from external attacks presented by my colleague Colin Charles.

10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Toshiba Support

all the information you have shared are very much useful for all the computer user. I get to know proper ideas about the SQL. keep sharing this type of ideas.

Stud wall

We are providing best Steel wall & House stud framing services in Australia. A stud wall includes a frame of timber or metal studs secured to the floor, ceiling and walls, which is then covered with plasterboard. We are 24*7 available for the customer help. For more information just visit our site: http://www.newworldconstruction.com.au/steel-wall-and-house-stud-framing.html

Will Luo

Thanks for the writeup, Jericho! Just wanted to share that it looks like as of mysql 5.7.23-23, the keyring_vault plugin is using v1 API of Vault’s kv engine, but currently by default Vault uses v2 when you create a new kv secrets engine. MySQL wasn’t able to store the secrets into Vault until I changed the API version of back to v1.

But other than that everything still work as described here. Thanks again for the nice writeup!

Stas

I followed all the points, but at my start the percona gives such a message:
[ERROR] Plugin keyring_vault reported: 'CURL returned this error code: 7 with error message : Failed connect to 127.0.0.1:8200; Connection refused'
pers_1 | 2020-01-09T21:39:49.936418Z 0 [ERROR] Plugin keyring_vault reported: 'Could not retrieve list of keys from Vault.'
pers_1 | 2020-01-09T21:39:49.936423Z 0 [ERROR] Plugin keyring_vault reported: 'Error while loading keyring content. The keyring might be malformed'
pers_1 | 2020-01-09T21:39:49.936427Z 0 [ERROR] Plugin keyring_vault reported: 'keyring_vault initialization failure. Please check that the keyring_vault_config_file points to readable keyring_vault configuration file. Please also make sure Vault is running and accessible. The keyring_vault will stay unusable until correct configuration file gets provided.'

Maybe someone knows what could be the problem?

When starting the vault server I use tls_disable = 1, because as a server I use a localhost that does not support https.
Also my db is launched through docker.

thank you all in advance.

Will Luo

Stas, this line from the log sounds like your Vault is not listening on 127.0.0.1:8200.

“[ERROR] Plugin keyring_vault reported: ‘CURL returned this error code: 7 with error message : Failed connect to 127.0.0.1:8200; Connection refused'”

Umapathi Balijapelli

I am getting this error message :

2020-04-14T08:43:47.410773Z 0 [Warning] unknown variable ‘loose_keyring_vault_config=/var/lib/mysql-keyring/keyring_vault.conf’

My Percona Mysql version is : 5.7.29-32 Percona Server (GPL)

daniel

I have created secret with version 1 of kv. In percona 8.0(last version), it always show: [ERROR] Plugin keyring_vault reported: ‘Plugin keyring_vault reported: ‘CURL returned this error code: 7 with error message : Failed to connect to 10.211.55.4: Permission denied’”

Arun

I has similar problem. For me it had to do with SELinux.

setsebool mysql_connect_any on
setsebool mysql_connect_http on

daniel

but,In the same server, I use curl in cli.it works. the comment text like this:

curl –cacert /etc/vault_ca/vault.pem -X GET -H “X-Vault-Request: true” -H “X-Vault-Token:*************” https://10.211.55.4:8200/v1/secret/dc
{“request_id”:”3d33fef2-6c39-39ff-b794-b71f05859f3a”,”lease_id”:””,”renewable”:false,”lease_duration”:2764800,”data”:{“master”:”asdfasddfasdf”},”wrap_info”:null,”warnings”:null,”auth”:null}

reuslt:
“request_id”:”3d33fef2-6c39-39ff-b794-b71f05859f3a”,”lease_id”:””,”renewable”:false,”lease_duration”:2764800,”data”:{“master”:”asdfasddfasdf”},”wrap_info”:null,”warnings”:null,”auth”:null}

this is my “keyring_vault.conf” :

vault_url=https://10.211.55.4:8200
secret_mount_point =v1/secret/dc/master
token = s.7YGc0gCXGJsmoT44txWvWr2M
vault_ca = /etc/vault_ca/vault.pem