Skip to content

Commit 7b2f433

Browse files
authored
Merge pull request #205478 from CocoWang-wql/patch-6
KMS GA doc.
2 parents eb94d15 + 2f229e7 commit 7b2f433

File tree

1 file changed

+203
-50
lines changed

1 file changed

+203
-50
lines changed
Lines changed: 203 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,50 @@
11
---
2-
title: Use KMS etcd encryption in Azure Kubernetes Service (AKS) (Preview)
2+
title: Use KMS etcd encryption in Azure Kubernetes Service (AKS)
33
description: Learn how to use kms etcd encryption with Azure Kubernetes Service (AKS)
44
services: container-service
55
ms.topic: article
6-
ms.date: 06/06/2022
6+
ms.date: 07/26/2022
77

88
---
99

10-
# Add KMS etcd encryption to an Azure Kubernetes Service (AKS) cluster (Preview)
10+
# Add KMS etcd encryption to an Azure Kubernetes Service (AKS) cluster
1111

1212
This article shows you how to enable encryption at rest for your Kubernetes data in etcd using Azure Key Vault with Key Management Service (KMS) plugin. The KMS plugin allows you to:
1313

1414
* Use a key in Key Vault for etcd encryption
1515
* Bring your own keys
1616
* Provide encryption at rest for secrets stored in etcd
17+
* Rotate the keys in Key Vault
1718

1819
For more information on using the KMS plugin, see [Encrypting Secret Data at Rest](https://kubernetes.io/docs/tasks/administer-cluster/kms-provider/).
1920

20-
[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)]
21-
2221
## Before you begin
2322

2423
* An Azure subscription. If you don't have an Azure subscription, you can create a [free account](https://azure.microsoft.com/free).
25-
* [Azure CLI installed](/cli/azure/install-azure-cli).
26-
27-
### Install the `aks-preview` Azure CLI
28-
29-
You also need the *aks-preview* Azure CLI extension version 0.5.58 or later. Install the *aks-preview* Azure CLI extension by using the [az extension add][az-extension-add] command. Or install any available updates by using the [az extension update][az-extension-update] command.
30-
31-
```azurecli-interactive
32-
# Install the aks-preview extension
33-
az extension add --name aks-preview
34-
# Update the extension to make sure you have the latest version installed
35-
az extension update --name aks-preview
36-
```
37-
38-
### Register the `AzureKeyVaultKmsPreview` preview feature
39-
40-
To use the feature, you must also enable the `AzureKeyVaultKmsPreview` feature flag on your subscription.
41-
42-
Register the `AzureKeyVaultKmsPreview` feature flag by using the [az feature register][az-feature-register] command, as shown in the following example:
24+
* Azure CLI version 2.39.0 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
4325

44-
```azurecli-interactive
45-
az feature register --namespace "Microsoft.ContainerService" --name "AzureKeyVaultKmsPreview"
46-
```
47-
48-
It takes a few minutes for the status to show *Registered*. Verify the registration status by using the [az feature list][az-feature-list] command:
49-
50-
```azurecli-interactive
51-
az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/AzureKeyVaultKmsPreview')].{Name:name,State:properties.state}"
52-
```
53-
54-
When ready, refresh the registration of the *Microsoft.ContainerService* resource provider by using the [az provider register][az-provider-register] command:
55-
56-
```azurecli-interactive
57-
az provider register --namespace Microsoft.ContainerService
58-
```
26+
> [!WARNING]
27+
> KMS only supports Konnectivity. You could use `kubectl get po -n kube-system` to check whether there is 'konnectivity-agent-xxx' pod running.
5928
6029
## Limitations
6130

6231
The following limitations apply when you integrate KMS etcd encryption with AKS:
6332

64-
* Disabling of the KMS etcd encryption feature.
65-
* Changing of key ID, including key name and key version.
6633
* Deletion of the key, Key Vault, or the associated identity.
6734
* KMS etcd encryption doesn't work with System-Assigned Managed Identity. The keyvault access-policy is required to be set before the feature is enabled. In addition, System-Assigned Managed Identity isn't available until cluster creation, thus there's a cycle dependency.
6835
* Using more than 2000 secrets in a cluster.
6936
* Bring your own (BYO) Azure Key Vault from another tenant.
37+
* Change associated Azure Key Vault model (public, private) if KMS is enabled. For [changing associated key vault mode][changing-associated-key-vault-mode], you need to disable and enable KMS again.
38+
* Stop/satrt cluster which is enabled KMS with private key vault.
39+
40+
KMS supports [public key vault][Enable-KMS-with-public-key-vault] and [private key vault][Enable-KMS-with-private-key-vault] now.
7041

71-
## Create a KeyVault and key
42+
## Enable KMS with public key vault
43+
44+
### Create a key vault and key
7245

7346
> [!WARNING]
74-
> Deleting the key or the Azure Key Vault is not supported and will cause your cluster to become unstable.
47+
> Deleting the key or the Azure Key Vault is not supported and will cause the secrets to be unrecoverable in the cluster.
7548
>
7649
> If you need to recover your Key Vault or key, see the [Azure Key Vault recovery management with soft delete and purge protection](../key-vault/general/key-vault-recovery.md?tabs=azure-cli) documentation.
7750
@@ -96,7 +69,7 @@ echo $KEY_ID
9669

9770
The above example stores the Key ID in *KEY_ID*.
9871

99-
## Create a user-assigned managed identity
72+
### Create a user-assigned managed identity
10073

10174
Use `az identity create` to create a User-assigned managed identity.
10275

@@ -122,28 +95,28 @@ echo $IDENTITY_RESOURCE_ID
12295

12396
The above example stores the value of the Identity Resource ID in *IDENTITY_RESOURCE_ID*.
12497

125-
## Assign permissions (decrypt and encrypt) to access key vault
98+
### Assign permissions (decrypt and encrypt) to access key vault
12699

127100
Use `az keyvault set-policy` to create an Azure KeyVault policy.
128101

129102
```azurecli-interactive
130103
az keyvault set-policy -n MyKeyVault --key-permissions decrypt encrypt --object-id $IDENTITY_OBJECT_ID
131104
```
132105

133-
## Create an AKS cluster with KMS etcd encryption enabled
106+
### Create an AKS cluster with KMS etcd encryption enabled
134107

135-
Create an AKS cluster using the [az aks create][az-aks-create] command with the `--enable-azure-keyvault-kms` and `--azure-keyvault-kms-key-id` parameters to enable KMS etcd encryption.
108+
Create an AKS cluster using the [az aks create][az-aks-create] command with the `--enable-azure-keyvault-kms`, `--azure-keyvault-kms-key-vault-network-access` and `--azure-keyvault-kms-key-id` parameters to enable KMS etcd encryption.
136109

137110
```azurecli-interactive
138-
az aks create --name myAKSCluster --resource-group MyResourceGroup --assign-identity $IDENTITY_RESOURCE_ID --enable-azure-keyvault-kms --azure-keyvault-kms-key-id $KEY_ID
111+
az aks create --name myAKSCluster --resource-group MyResourceGroup --assign-identity $IDENTITY_RESOURCE_ID --enable-azure-keyvault-kms --azure-keyvault-kms-key-vault-network-access "Public" --azure-keyvault-kms-key-id $KEY_ID
139112
```
140113

141-
## Update an exiting AKS cluster to enable KMS etcd encryption
114+
### Update an exiting AKS cluster to enable KMS etcd encryption
142115

143-
Use [az aks update][az-aks-update] with the `--enable-azure-keyvault-kms` and `--azure-keyvault-kms-key-id` parameters to enable KMS etcd encryption on an existing cluster.
116+
Use [az aks update][az-aks-update] with the `--enable-azure-keyvault-kms`, `--azure-keyvault-kms-key-vault-network-access` and `--azure-keyvault-kms-key-id` parameters to enable KMS etcd encryption on an existing cluster.
144117

145118
```azurecli-interactive
146-
az aks update --name myAKSCluster --resource-group MyResourceGroup --enable-azure-keyvault-kms --azure-keyvault-kms-key-id $KEY_ID
119+
az aks update --name myAKSCluster --resource-group MyResourceGroup --enable-azure-keyvault-kms --azure-keyvault-kms-key-vault-network-access "Public" --azure-keyvault-kms-key-id $KEY_ID
147120
```
148121

149122
Use below command to update all secrets. Otherwise, the old secrets aren't encrypted.
@@ -152,6 +125,182 @@ Use below command to update all secrets. Otherwise, the old secrets aren't encry
152125
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
153126
```
154127

128+
> [!NOTE]
129+
> For larger clusters, you may wish to subdivide the secrets by namespace or script an update.
130+
131+
### Rotate the existing keys
132+
After changing the key ID (including key name and key version), you could use [az aks update][az-aks-update] with the `--enable-azure-keyvault-kms`, `--azure-keyvault-kms-key-vault-network-access` and `--azure-keyvault-kms-key-id` parameters to rotate the exitsing keys of KMS.
133+
134+
> [!WARNING]
135+
> Remember to update all secrets after key rotation. Otheriwse, the secrets will be unaccessable if the old keys are not existing or working.
136+
137+
```azurecli-interactive
138+
az aks update --name myAKSCluster --resource-group MyResourceGroup --enable-azure-keyvault-kms --azure-keyvault-kms-key-vault-network-access "Public" --azure-keyvault-kms-key-id $NEW_KEY_ID
139+
```
140+
141+
Use below command to update all secrets. Otherwise, the old secrets are still encrypted with the previous key.
142+
143+
```azurecli-interactive
144+
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
145+
```
146+
147+
> [!NOTE]
148+
> For larger clusters, you may wish to subdivide the secrets by namespace or script an update.
149+
150+
## Enable KMS with private key vault
151+
152+
If you enable KMS with private key vault, AKS will create a private endpoint and private link in the node resource group automatically. The key vault will be added a private endpoint connection with the AKS cluster.
153+
154+
### Create a private key vault and key
155+
156+
> [!WARNING]
157+
> Deleting the key or the Azure Key Vault is not supported and will cause the secrets to be unrecoverable in the cluster.
158+
>
159+
> If you need to recover your Key Vault or key, see the [Azure Key Vault recovery management with soft delete and purge protection](../key-vault/general/key-vault-recovery.md?tabs=azure-cli) documentation.
160+
161+
162+
Use `az keyvault create` to create a priate KeyVault.
163+
164+
```azurecli
165+
az keyvault create --name MyKeyVault --resource-group MyResourceGroup --public-network-access Disabled
166+
```
167+
168+
Without private endpoint, it's not supported to create or update keys in private key vault. To manage private key vault, you could refer to [Integrate Key Vault with Azure Private Link](../key-vault/general/private-link-service.md).
169+
170+
### Create a user-assigned managed identity
171+
172+
Use `az identity create` to create a User-assigned managed identity.
173+
174+
```azurecli
175+
az identity create --name MyIdentity --resource-group MyResourceGroup
176+
```
177+
178+
Use `az identity show` to get Identity Object ID.
179+
180+
```azurecli
181+
IDENTITY_OBJECT_ID=$(az identity show --name MyIdentity --resource-group MyResourceGroup --query 'principalId' -o tsv)
182+
echo $IDENTITY_OBJECT_ID
183+
```
184+
185+
The above example stores the value of the Identity Object ID in *IDENTITY_OBJECT_ID*.
186+
187+
Use `az identity show` to get Identity Resource ID.
188+
189+
```azurecli
190+
IDENTITY_RESOURCE_ID=$(az identity show --name MyIdentity --resource-group MyResourceGroup --query 'id' -o tsv)
191+
echo $IDENTITY_RESOURCE_ID
192+
```
193+
194+
The above example stores the value of the Identity Resource ID in *IDENTITY_RESOURCE_ID*.
195+
196+
### Assign permissions (decrypt and encrypt) to access key vault
197+
198+
Use `az keyvault set-policy` to create an Azure KeyVault policy.
199+
200+
```azurecli-interactive
201+
az keyvault set-policy -n MyKeyVault --key-permissions decrypt encrypt --object-id $IDENTITY_OBJECT_ID
202+
```
203+
204+
For private key vault, the AKS needs *Key Vault Contributor* role to create private link between private key vault and cluster.
205+
206+
```azurecli-interactive
207+
az role assignment create --role "Key Vault Contributor" --assignee-object-id $IDENTITY_OBJECT_ID --assignee-principal-type "ServicePrincipal" --scope $KEYVAULT_RESOURCE_ID
208+
```
209+
210+
### Create an AKS cluster with private key vault and enable KMS etcd encryption
211+
212+
Create an AKS cluster using the [az aks create][az-aks-create] command with the `--enable-azure-keyvault-kms`, `--azure-keyvault-kms-key-id`, `--azure-keyvault-kms-key-vault-network-access` and `--azure-keyvault-kms-key-vault-resource-id` parameters to enable KMS etcd encryption with private key vault.
213+
214+
```azurecli-interactive
215+
az aks create --name myAKSCluster --resource-group MyResourceGroup --assign-identity $IDENTITY_RESOURCE_ID --enable-azure-keyvault-kms --azure-keyvault-kms-key-id $KEY_ID --azure-keyvault-kms-key-vault-network-access "Private" --azure-keyvault-kms-key-vault-resource-id $KEYVAULT_RESOURCE_ID
216+
```
217+
218+
### Update an exiting AKS cluster to enable KMS etcd encryption with private key vault
219+
220+
Use [az aks update][az-aks-update] with the `--enable-azure-keyvault-kms`, `--azure-keyvault-kms-key-id`, `--azure-keyvault-kms-key-vault-network-access` and `--azure-keyvault-kms-key-vault-resource-id` parameters to enable KMS etcd encryption on an existing cluster with private key vault.
221+
222+
```azurecli-interactive
223+
az aks update --name myAKSCluster --resource-group MyResourceGroup --enable-azure-keyvault-kms --azure-keyvault-kms-key-id $KEY_ID --azure-keyvault-kms-key-vault-network-access "Private" --azure-keyvault-kms-key-vault-resource-id $KEYVAULT_RESOURCE_ID
224+
```
225+
226+
Use below command to update all secrets. Otherwise, the old secrets aren't encrypted.
227+
228+
```azurecli-interactive
229+
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
230+
```
231+
232+
> [!NOTE]
233+
> For larger clusters, you may wish to subdivide the secrets by namespace or script an update.
234+
235+
### Rotate the existing keys
236+
After changing the key ID (including key name and key version), you could use [az aks update][az-aks-update] with the `--enable-azure-keyvault-kms`, `--azure-keyvault-kms-key-id`, `--azure-keyvault-kms-key-vault-network-access` and `--azure-keyvault-kms-key-vault-resource-id` parameters to rotate the existing keys of KMS.
237+
238+
> [!WARNING]
239+
> Remember to update all secrets after key rotation. Otherwise, the secrets will be unaccessable if the old keys are not existing or working.
240+
241+
```azurecli-interactive
242+
az aks update --name myAKSCluster --resource-group MyResourceGroup --enable-azure-keyvault-kms --azure-keyvault-kms-key-id $NewKEY_ID --azure-keyvault-kms-key-vault-network-access "Private" --azure-keyvault-kms-key-vault-resource-id $KEYVAULT_RESOURCE_ID
243+
```
244+
245+
Use below command to update all secrets. Otherwise, the old secrets are still encrypted with the previous key.
246+
247+
```azurecli-interactive
248+
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
249+
```
250+
251+
> [!NOTE]
252+
> For larger clusters, you may wish to subdivide the secrets by namespace or script an update.
253+
254+
## Update key vault mode
255+
256+
> [!NOTE]
257+
> To change a different key vault with different mode (public, private), you could run `az aks update` directly. To change the mode of attached key vault, you need to diable KMS and re-enable it with new key vault ids.
258+
259+
Below are the steps about how to migrate the attached public key vault to private mode.
260+
261+
### Disable KMS on the cluster
262+
263+
Use below command to disable the KMS on existing cluster and release the key vault.
264+
265+
```azurecli-interactive
266+
az aks update --name myAKSCluster --resource-group MyResourceGroup --disable-azure-keyvault-kms
267+
```
268+
269+
### Change key vault mode
270+
271+
Update the key vault from public to private.
272+
273+
```azurecli-interactive
274+
az keyvault update --name MyKeyVault --resource-group MyResourceGroup --public-network-access Disabled
275+
```
276+
277+
### Enable KMS on the cluster with updated key vault
278+
279+
Use below command to re-enable the KMS with updated private key vault.
280+
281+
```azurecli-interactive
282+
az aks update --name myAKSCluster --resource-group MyResourceGroup --enable-azure-keyvault-kms --azure-keyvault-kms-key-id $NewKEY_ID --azure-keyvault-kms-key-vault-network-access "Private" --azure-keyvault-kms-key-vault-resource-id $KEYVAULT_RESOURCE_ID
283+
```
284+
285+
After configuring KMS, you could enable [diagnostic-settings for key vault to check the encryption logs](../key-vault/general/howto-logging.md).
286+
287+
## Disable KMS
288+
289+
Use below command to disable KMS on existing cluster.
290+
291+
```azurecli-interactive
292+
az aks update --name myAKSCluster --resource-group MyResourceGroup --disable-azure-keyvault-kms
293+
```
294+
295+
Use below command to update all secrets. Otherwise, the old secrets are still encrypted with the previous key.
296+
297+
```azurecli-interactive
298+
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
299+
```
300+
301+
> [!NOTE]
302+
> For larger clusters, you may wish to subdivide the secrets by namespace or script an update.
303+
155304
<!-- LINKS - Internal -->
156305
[aks-support-policies]: support-policies.md
157306
[aks-faq]: faq.md
@@ -167,3 +316,7 @@ kubectl get secrets --all-namespaces -o json | kubectl replace -f -
167316
[az-feature-list]: /cli/azure/feature#az_feature_list
168317
[az-provider-register]: /cli/azure/provider#az_provider_register
169318
[az-aks-update]: /cli/azure/aks#az_aks_update
319+
[Enable-KMS-with-public-key-vault]: use-kms-etcd-encryption.md#enable-kms-with-public-key-vault
320+
[Enable-KMS-with-private-key-vault]: use-kms-etcd-encryption.md#enable-kms-with-private-key-vault
321+
[changing-associated-key-vault-mode]: use-kms-etcd-encryption.md#update-key-vault-mode
322+
[install-azure-cli]: /cli/azure/install-azure-cli

0 commit comments

Comments
 (0)