Key Management Secrets Engine with Azure Key Vault
Note
Key Management Secrets Engine requires Vault Enterprise Advanced Data Protection (ADP) license.
Challenge
You need to use security features of cloud providers, which involve encryption keys issued and stored by the provider in its own key management system (KMS), but you must also maintain root of trust and control of the encryption key lifecycle.
Solution
The Vault Key Management Secrets Engine provides distribution and lifecycle management features for cloud provider keys.
Currently, it manages keys for the following cloud providers.
Personas
The end-to-end scenario described in this tutorial involves one persona:
admin
a user with with privileged permissions to configure secrets engines.
Prerequisites
To perform the tasks described in this tutorial, you need to have:
- A Microsoft Azure account with sufficient permissions to manage applications, service principles, and key vaults.
- Vault Enterprise with the Advanced Data Protection Module at version 1.6 or later.
Policy requirements
Each persona requires a different set of capabilities. These are expressed in policies. If you are not familiar with policies, complete the policies tutorial.
The admin tasks require these capabilities.
Start Vault dev server
In a new terminal session, start a Vault dev server with the value of the initial root token set to root
.
The Vault dev server defaults to listening at 127.0.0.1:8200
. The server is also automatically 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.
In another new terminal session, export an environment variable for the vault
CLI to address the dev server.
Then 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.
Refer to Dev Options to learn more about Vault dev server options.
The Vault dev server is now ready for use.
Scenario Introduction
You will configure a Microsoft Azure Key Vault instance, then use the Vault CLI, HTTP API or web UI to configure a Vault development mode server and enable management of the Key Vault key with the Key Management secrets engine.
After initial configuration, you will perform some lifecycle operations with the secrets engine, like writing, reading, updating, and rotating keys.
- Configure Azure Key Vault
- Enable Key Management secrets engine
- Write keys
- Read keys
- Create KMS provider
- Distribute keys to key vault
- Rotate key
Configure Azure Key Vault
To follow this tutorial, you must configure an Azure Key Vault instance and assign an access policy that provides the key management policy to a service principal. You then need to generate a credential that Vault will use to connect to and manage the Key Vault.
In this tutorial, the Azure Key Vault instance is named learn-key-vault.
You can refer to the How to: Use the portal to create an Azure AD application and service principal that can access resources and Assign a Key Vault access policy using the Azure portal documentation for further details on these steps.
When complete, you should have a key vault available as shown in this screenshot.
You need to note the value of key vault name (learn-keyvault-52246b in this example) to use when you configure Vault later.
Terraform configuration example
If you are familiar with Terraform, you can use it to deploy the necessary Azure infrastructure for this tutorial with the following configuration example.
Enable Key Management secrets engine
You must first enable an instance of the Key Management Secrets engine before you can use it.
The default behavior without specifying a path to enable the
secrets engine on is to enable it at the path keymgmt/
.
Enable the secrets engine.
The secrets engine is now enabled and ready for use.
Write keys
The Key Management secrets engine currently supports generation of the key types specified in Key Types.
Based on the Compatibility section of the documentation, Azure Key Vault currently supports use of RSA-2048, RSA-3072, and RSA-4096 key types.
Write a pair of RSA-2048 keys to the secrets engine.
With this command line syntax, you are instructing Vault to write a new key of type rsa-2048 to the path keymgmt/key/rsa-1
. The key that is written is for general purpose use, but you will set its specific use later.
You can do the same again to write the second key, but change the path to keymgmt/key/rsa-2
.
Read keys
Now, to learn about the content of a key, you can read it back. Let's read the rsa-1 key, use JSON as the output, and pipe that into jq
.
Notice the value of latest_version
; it is 1 since this is the first version of the key that Vault knows about. This will figure into the example on key rotation later.
Read the second key.
Create KMS provider
The next step is to create the KMS provider configuration in Vault; this corresponds to the key vault instance you previously created in Azure.
Create the KMS provider at the path keymgmt/kms/keyvault
.
In this command line example, you specified 5 pieces of information to successfully configure the key vault instance.
- The full path to this KMS provider instance in Vault (
keymgmt/kms/keyvault
). - A key collection, which corresponds to the name of the key vault instance in Azure.
- The KMS provider is set to "azurekeyvault".
- Azure client ID credential, that can also be specified with AZURE_CLIENT_ID environment variable.
- Azure client secret credential, that can also be specified with AZURE_CLIENT_SECRET environment variable.
- Azure tenant ID credential, that can also be specified with AZURE_TENANT_ID environment variable.
Distribute keys to key vault
To use the keys you wrote in step 3, you must first distribute them to the key vault you just created in step 5. Add the rsa-1 key to the key vault at the path keymgmt/kms/keyvault/key/rsa-1
.
Here you are instructing Vault to distribute the key and specify that its purpose is only to encrypt and decrypt. The protection type is dependent on the cloud provider and the value is either hsm
or software
. In the case of Azure, you specify hsm
for the protection type. The key will be securely delivered to the key vault instance according to the Azure Bring Your Own Key (BYOK) specification.
Write the second key to the path keymgmt/kms/keyvault/key/rsa-2
next, but specify that its purpose is only for signing.
Verify keys
You can use the vault
CLI to list the keys that have been distributed to the Azure Key Vault instance.
You can also visit the Azure UI to confirm the key distribution.
Inspecting the key rsa-1 shows its current version.
Clicking into the key further also shows more details, like permitted operations, which in this case include only Encrypt and Decrypt.
Inspecting the key rsa-2 shows its permitted operations, which includes only Sign.
Rotate key
Key rotation is a fundamental part of the key management lifecycle. Let's use Vault to rotate the rsa-1 key and then verify its version with the vault
CLI and Azure UI.
Rotate the key.
Note
This command line uses the force flag (-f
) because there are no parameters passed as key/value pairs and in such cases, it is required to avoid an error.
Confirm key rotation
You can confirm successful key rotation by reading the key with the CLI, and getting the value of .data.latest_version
.
The key is now at version 2; in the Azure UI, the key will be expected to have a different version string than the original value under CURRENT VERSION and the original version string (e27d7baeacc543e4bfde70891d4be4b3) should be present under OLDER VERSIONS as shown in the Azure UI screenshot.
Summary
You have learned the basics about the Key Management secrets engine, including configuring Azure, enabling the secrets engine, and performing basic key lifecycle management operations.
From here, you can learn about other Vault secrets engines by going through the Secrets Management tutorials.