Manage client encryption keys with Vault as a KMIP server
Note
The KMIP secrets engine requires a Vault Enterprise Advanced Data Protection (ADP) license or HCP Vault Dedicated Plus tier cluster.
Challenge
The OASIS Key Management Interoperability Protocol (KMIP) standard is a widely adopted protocol for handling cryptographic workloads and secrets management for enterprise infrastructure such as databases, network storage, and virtual/physical servers.
When an organization has services and applications that need to perform cryptographic operations (e.g.: transparent database encryption, full disk encryption, etc.), it often delegates the key management task to an external provider via the KMIP protocol. As a result, your organization may have existing services or applications that implement KMIP or use wrapper clients with libraries/drivers that implement KMIP. This makes it difficult for an organization to adopt the Vault API in place of KMIP.
Solution
Vault Enterprise provides a KMIP secrets engine which allows Vault to act as a KMIP server for clients that retrieve cryptographic keys for encrypting data via the KMIP protocol.
Vault's KMIP secrets engine manages its own listener to service KMIP requests which operate on KMIP managed objects. Vault policies do not come into play during these KMIP requests. The KMIP secrets engine determines the set of KMIP operations the clients are allowed to perform based on the roles that are applied to the TLS client certificate.
This enables the existing systems to continue using the KMIP APIs instead of Vault APIs.
Prerequisites
To perform the tasks described in this tutorial, you need to have Vault Enterprise with the Advanced Data Protection module or a HCP Vault Dedicated Plus tier cluster.
Note
The Vault Community Edition binary can be used to configure a Vault Enterprise or HCP Vault Dedicated Plus tier cluster.
- Access to a Vault Enterprise license with the ADP module to run Vault in dev mode. If you do not have a license you can request one from your customer success team or use an HCP Vault Dedicated Plus tier cluster.
- Vault binary installed
- Docker installed
- jq installed
Policy requirements
For the purpose of this tutorial, you can use root
token to work
with Vault. However, it is recommended that root tokens are only used for just
enough initial setup or in emergencies. As a best practice, use tokens with
appropriate set of policies based on your role in the organization.
To perform all tasks demonstrated in this tutorial, your policy must include the following permissions:
If you are not familiar with policies, complete the policies tutorial.
Lab setup
Vault setup
Open a terminal and export an environment variable with a valid Vault Enterprise license.
Start Vault Enterprise in a container.
The Vault dev server is set to listen on all addresses using port
8200
. The server is initialized and unsealed.Insecure operation
Do not run a Vault dev server in production. This approach starts a Vault server with an in-memory database and runs in an insecure way.
Export an environment variable for the
vault
CLI to address the Vault server.Export an environment variable for the
vault
CLI to authenticate with the Vault server.Note
For these tasks, you can use Vault's root token. However, it is recommended that root tokens are only used for enough initial setup or in emergencies. As a best practice, use an authentication method or token that meets the policy requirements.
The Vault server is ready to proceed with the lab.
KMIP client setup
Create a working directory. You will store the necessary files in this location to use when configuring the KMIP client.
Change in to the new directory.
Store the working directory as an environment variable.
Start a MongoDB Enterprise container and mount the
TUTORIAL_TEMP
directory. You will use MongoDB as an example KMIP client.MongoDB will connect to Vault Enterprise using the Docker bridge network.
If you do not have a local image of the MongoDB Enterprise Server container, Docker will pull the image.
Example output:
Verify you can connect to the MongoDB container.
The shell will change to the MongoDB container.
Example output:
Verify the
TEMP_DIR
directory mounted.Disconnect from the MongoDB container.
You are now ready to begin the tutorial.
Enable and configure the KMIP secrets engine
The first step is to enable the kmip
secrets engine at a desired path. In this
tutorial, you are going to enable the kmip
secrets engine at /kmip
.
Enable the
kmip
secrets engine.Configure the
kmip
server to listen on port5696
.Example output:
Review the
kmip
secrets engine configuration.When the KMIP engine is configured, it generates and stores a key-pair and uses it to sign a root CA which is used to sign an intermediate CA. The intermediate CA is used to sign the server TLS certificate used by the KMIP listener to identify itself during the TLS handshake.
By default, the certificate type (
default_tls_client_key_type
) isec
(Elliptic Curve). If you need RSA instead, specify the certificate type (tls_ca_key_type
) and bits (tls_ca_key_bits
) when you configure thekmip
server.Retrieve the generated CA certificate and save it in a file named
vault-ca.pem
.
Create scopes and roles
Scopes partition KMIP managed object storage into multiple named buckets. (NOTE: Scopes cannot be nested.)
Roles in the KMIP secrets engine determine the set of KMIP operations that KMIP clients are allowed to perform.
Create a new scope named, "finance".
List the existing scopes.
Create a new role, "accounting" under the
finance
scope.By setting the
operation_all
parameter totrue
, the created role is granted to perform all KMIP client-server operations. Refer to Manage KMIP roles to learn how to modify the allowed operation list.List existing roles under
finance
scope.Read the
accounting
role definition.
Client certificate generation
Once the scope was created and a role was created under the scope, the next step is to get the certificate for the KMIP client.
Note
Available certificate formats are: pem
, pem_bundle
, or der
.
If pem_bundle
was chosen, the certificate
field will contain the private
key, certificate, and ca_chain, concatenated.
Generate a certificate in PEM format, and save it in a file named
credential.json
.The resulting
credential.json
contains the certificates that your KMIP client will use to establish a connection with Vault KMIP server.Example output:
Extract the certificate from the
credential.json
usingjq
tool and save it in a file namedcert.pem
.Extract the private key from the
credential.json
usingjq
tool and save it in a file namedkey.pem
.List the certification serial numbers associated with the
accounting
role.You can lookup the client certificate by its serial number as shown in the example. You can copy the output from the command above, or retrieve it from the
credential.json
file.Example output:
KMIP client configuration
In the Enable and configure the KMIP secrets engine,
you saved the CA certificate in a file named, ca.pem
. You then created a role named
"accounting" with all supported KMIP operations allowed. Based on the role, a client certificate
was generated and saved in a file, cert.pem
and its private key in key.pem
.
You will now use the certificates to configure a KMIP client.
Use mongod
daemon
process to configure the KMIP settings.
Combine the cert.pem and key.pem and save it as
client.pem
.Connect to the MongoDB container.
Create a data directory.
Use the
mongod
command to specify the cert & key file locations.Example output:
The command output shows the created KMIP key ID:
Stop the MongoDB process by typing
ctrl c
.Exit the container shell.
Stop the MongoDB container.
Revoke a client certificate
You can also revoke existing client certificates if necessary.
Revoke a client certificate by its serial number.
Example output:
Verify that it no longer exists.
Manage KMIP roles
In the Create scopes and roles section the accounting
role was permitted to perform all KMIP
operations (operation_all
). However, you should practice least privilege and avoid granting more permissions than necessary.
When you grant KMIP operations, the argument convention is
operation_<KMIP_operation>
. For example, to grant a Create
operation, the
parameter becomes operation_create
.
Note
Refer to the KMIP Secrets Engine doc for the list of supported KMIP operations.
Update the
accounting
role and grant onlyActivate
,Create
, andGet
operations.Example output:
Verify the changes.
Delete the
accounting
role.
Delete scopes
If you need to delete scopes, follow this step.
Delete the finance
scope.
The force
parameter allows deleting a scope which has some
managed objects created with.
Additional Discussion
Review KMIP certificates
Vault policies do not come into play during these KMIP requests.
The KMIP secrets engine determines the set of KMIP operations the
clients are allowed to perform based on the roles (accounting
).
Review the generated client certificate file.
Notice the Subject properties: Subject: OU=5J7Ck, CN=ImYFE
The OU
corresponds to the scope (finance
) and CN
corresponds to the role
(accounting
). If you have access to the Vault's storage backend, you would
find persisted data with those IDs.
For example:
You can read the allowed operations for the role using the
sys/raw
endpoint if it's
enabled.
When a situation requires you to delete the client certificate, simply revoke the certificate as described in Revoke a client certificate.
MySQL Enterprise Edition
This section assumes that you already have an instance of MySQL Enterprise Edition running with your own license.
The keyring_okv
keyring plugin uses the KMIP 1.1 protocol to communicate
securely as a client of a KMIP back end. Follow the MySQL online
documentation
to create okvclient.ora
file, and an ssl
directory to place the certificate
and key files for keyring_ova
to work properly.
Also, install the keyring_udf
plugin and the user-defined functions (UDFs) as
described in the MySQL
documentation.
Now, generate a new random key with a given ID, type, and length, and store it in the keyring.
Clean up
1. Stop the Vault Enterprise container.
2. Remove the local files and TUTORIAL_TEMP
directory.