1---
2layout: docs
3page_title: Key Management - Secrets Engines
4description: >-
5  The Key Management secrets engine provides a consistent workflow for distribution and lifecycle
6  management of cryptographic keys in various key management service (KMS) providers.
7---
8
9# Key Management Secrets Engine
10
11-> **Note**: This secrets engine requires [Vault
12Enterprise](https://www.hashicorp.com/products/vault/) (1.6.0+) with the Advanced Data
13Protection Module.
14
15The Key Management secrets engine provides a consistent workflow for distribution and lifecycle
16management of cryptographic keys in various key management service (KMS) providers. It allows
17organizations to maintain centralized control of their keys in Vault while still taking advantage
18of cryptographic capabilities native to the KMS providers.
19
20The secrets engine generates and owns original copies of key material. When an operator decides
21to distribute and manage the lifecycle of a key in one of the [supported KMS providers](#kms-providers),
22a copy of the key material is distributed. This provides additional durability and disaster
23recovery means for the complete lifecycle of the key in the KMS provider.
24
25Key material will always be securely transferred in accordance with the
26[key import specification](#kms-providers) of the supported KMS providers.
27
28## Setup
29
30Most secrets engines must be configured in advance before they can perform their
31functions. These steps are usually completed by an operator or configuration
32management tool.
33
341. Enable the Key Management secrets engine:
35
36   ```text
37   $ vault secrets enable keymgmt
38   Success! Enabled the keymgmt secrets engine at: keymgmt/
39   ```
40
41   By default, the secrets engine will mount at the name of the engine. To enable
42   the secrets engine at a different path, use the `-path` argument.
43
44## Usage
45
46After the secrets engine is mounted and a user/machine has a Vault token with
47the proper permission, it can use this secrets engine to generate, distribute, and
48manage the lifecycle of cryptographic keys in [supported KMS providers](#kms-providers).
49
501. Create a named cryptographic key of a specified type:
51
52   ```text
53   $ vault write -f keymgmt/key/example-key type="rsa-2048"
54   Success! Data written to: keymgmt/key/example-key
55   ```
56
57   Keys created by the secrets engine are considered general-purpose until
58   they're distributed to a KMS provider.
59
601. Configure a KMS provider:
61
62   ```text
63   $ vault write keymgmt/kms/example-kms \
64       provider="azurekeyvault" \
65       key_collection="keyvault-name" \
66       credentials=client_id="a0454cd1-e28e-405e-bc50-7477fa8a00b7" \
67       credentials=client_secret="eR%HizuCVEpAKgeaUEx" \
68       credentials=tenant_id="cd4bf224-d114-4f96-9bbc-b8f45751c43f"
69   ```
70
71   Conceptually, a KMS provider resource represents a destination for keys to be distributed to
72   and subsequently managed in. It is configured using a generic set of parameters. The values
73   supplied to the generic set of parameters will differ depending on the specified `provider`.
74
75   This operation creates a KMS provider that represents a named Azure Key Vault instance.
76   This is accomplished by specifying the `azurekeyvault` provider along with other provider-specific
77   parameter values. For details on how to configure each supported KMS provider, see the
78   [KMS Providers](#kms-providers) section.
79
801. Distribute a key to a KMS provider:
81
82   ```text
83   $ vault write keymgmt/kms/example-kms/key/example-key \
84       purpose="encrypt,decrypt" \
85       protection="hsm"
86   ```
87
88   This operation distributes a **copy** of the named key to the KMS provider with a specific
89   `purpose` and `protection`. The `purpose` defines the set of cryptographic capabilities
90   that the key will have in the KMS provider. The `protection` defines where cryptographic
91   operations are performed with the key in the KMS provider. See the API documentation for a list of
92   supported [purpose](/api/secret/key-management#purpose) and [protection](/api/secret/key-management#protection)
93   values.
94
95   ~> **Note:** The amount of time it takes to distribute a key to a KMS provider is proportional to the
96   number of versions that the key has. If a timeout occurs when distributing a key to a KMS
97   provider, you may need to increase the [VAULT_CLIENT_TIMEOUT](https://www.vaultproject.io/docs/commands#vault_client_timeout).
98
991. Rotate a key:
100
101   ```text
102   $ vault write -f keymgmt/key/example-key/rotate
103   ```
104
105   Rotating a key creates a new key version that contains new key material. The key will be rotated
106   in both Vault and the KMS provider that the key has been distributed to. The new key version
107   will be enabled and set as the current version for cryptographic operations in the KMS provider.
108
1091. Enable or disable key versions:
110
111   ```text
112   $ vault write keymgmt/key/example-key min_enabled_version=2
113   ```
114
115   The `min_enabled_version` of a key can be updated in order to enable or disable sequences of
116   key versions. All versions of the key less than the `min_enabled_version` will be disabled for
117   cryptographic operations in the KMS provider that the key has been distributed to. Setting a
118   `min_enabled_version` of `0` means that all key versions will be enabled.
119
1201. Remove a key from a KMS provider:
121
122   ```text
123   $ vault delete keymgmt/kms/example-kms/key/example-key
124   ```
125
126   This operation results in the key being deleted from the KMS provider. The key will still exist
127   in the secrets engine and can be redistributed to a KMS provider at a later time.
128
129   To permanently delete the key from the secrets engine, the [delete key](/api/secret/key-management#delete-key)
130   API may be invoked.
131
132## Key Types
133
134The Key Management secrets engine supports generation of the following key types:
135
136- `aes256-gcm96` - AES-GCM with a 256-bit AES key and a 96-bit nonce (symmetric)
137- `rsa-2048` - RSA with bit size of 2048 (asymmetric)
138- `rsa-3072` - RSA with bit size of 3072 (asymmetric)
139- `rsa-4096` - RSA with bit size of 4096 (asymmetric)
140
141## KMS Providers
142
143The Key Management secrets engine supports lifecycle management of keys in the following
144KMS providers:
145
146- [Azure Key Vault](/docs/secrets/key-management/azurekeyvault)
147- [AWS KMS](/docs/secrets/key-management/awskms)
148
149Refer to the provider-specific documentation for details on how to properly configure each provider.
150
151## Compatibility
152
153The following table defines which key types are compatible with each KMS provider.
154
155| Key Type       | Azure Key Vault | AWS KMS |
156| -------------- | --------------- | ------- |
157| `aes256-gcm96` | No              | **Yes** |
158| `rsa-2048`     | **Yes**         | No      |
159| `rsa-3072`     | **Yes**         | No      |
160| `rsa-4096`     | **Yes**         | No      |
161
162## Learn
163
164Refer to the [Key Management Secrets Engine](https://learn.hashicorp.com/tutorials/vault/key-management-secrets) guide for
165a step-by-step tutorial.
166
167## API
168
169The Key Management secrets engine has a full HTTP API. Please see the
170[Key Management Secrets Engine API](/api/secret/key-management) for more
171details.
172