Using the keyring_vault Plugin with Percona Server for MySQL 5.7

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.

Share this post

Comments (10)

  • 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.

    September 17, 2018 at 8:30 pm
  • 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:

    October 12, 2018 at 7:03 am
  • 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!

    January 8, 2020 at 3:01 pm
    • 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; 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.

      January 9, 2020 at 4:53 pm
      • Will Luo

        Stas, this line from the log sounds like your Vault is not listening on

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

        January 24, 2020 at 6:41 pm
    • Jericho Rivera


      Indeed only Vault kv v1 is supported as stated here: An added step after unsealing Vault is to create the secrets engine with

      vault secrets enable -path=secret -version=1 kv

      I’m glad that the write-up is helpful.

      January 11, 2020 at 10:05 am
  • 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)

    April 14, 2020 at 7:10 am
  • 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 Permission denied’”

    August 14, 2020 at 3:55 am
    • Arun

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

      setsebool mysql_connect_any on
      setsebool mysql_connect_http on

      September 2, 2020 at 6:18 pm
  • daniel

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

    curl –cacert /etc/vault_ca/vault.pem -X GET -H “X-Vault-Request: true” -H “X-Vault-Token:*************”


    this is my “keyring_vault.conf” :

    secret_mount_point =v1/secret/dc/master
    token = s.7YGc0gCXGJsmoT44txWvWr2M
    vault_ca = /etc/vault_ca/vault.pem

    August 14, 2020 at 4:04 am

Comments are closed.

Use Percona's Technical Forum to ask any follow-up questions on this blog topic.