Skip to content

Commit 6d102b5

Browse files
Added Managed HSM support with CMK for SB
1 parent ea12f03 commit 6d102b5

File tree

1 file changed

+108
-54
lines changed

1 file changed

+108
-54
lines changed

articles/service-bus-messaging/configure-customer-managed-key.md

Lines changed: 108 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Configure your own key for encrypting Azure Service Bus data at rest
33
description: This article provides information on how to configure your own key for encrypting Azure Service Bus data rest.
44
ms.topic: conceptual
5-
ms.date: 06/26/2023
5+
ms.date: 05/13/2024
66
---
77

88
# Configure customer-managed keys for encrypting Azure Service Bus data at rest
@@ -12,7 +12,7 @@ There are some caveats to the customer managed key for service side encryption.
1212
- This feature is supported by [Azure Service Bus Premium](service-bus-premium-messaging.md) tier. It can't be enabled for standard tier Service Bus namespaces.
1313
- The encryption can only be enabled for new or empty namespaces. If the namespace contains any queues or topics, then the encryption operation fails.
1414

15-
You can use Azure Key Vault to manage your keys and audit your key usage. You can either create your own keys and store them in a key vault, or you can use the Azure Key Vault APIs to generate keys. For more information about Azure Key Vault, see [What is Azure Key Vault?](../key-vault/general/overview.md)
15+
You can use Azure Key Vault (including Azure Key Vault Managed HSM) to manage your keys and audit your key usage. You can either create your own keys and store them in a key vault, or you can use the Azure Key Vault APIs to generate keys. For more information about Azure Key Vault, see [What is Azure Key Vault?](../key-vault/general/overview.md)
1616

1717
## Enable customer-managed keys (Azure portal)
1818
To enable customer-managed keys in the Azure portal, follow these steps:
@@ -23,6 +23,8 @@ To enable customer-managed keys in the Azure portal, follow these steps:
2323

2424
![Enable customer managed key](./media/configure-customer-managed-key/enable-customer-managed-key.png)
2525

26+
> [!NOTE]
27+
> Currently you can't configure Azure Key Vault Managed HSM through the portal.
2628
2729
## Set up a key vault with keys
2830

@@ -32,6 +34,9 @@ After you enable customer-managed keys, you need to associate the customer manag
3234

3335
> [!IMPORTANT]
3436
> Using customer-managed keys with Azure Service Bus requires that the key vault have two required properties configured. They are: **Soft Delete** and **Do Not Purge**. The Soft Delete property is enabled by default when you create a new key vault in the Azure portal whereas the Purge Protection is optional so make sure to select it when creating the Key Vault. Also, if you need to enable these properties on an existing key vault, you must use either PowerShell or Azure CLI.
37+
38+
# [Key Vault](#tab/Key-Vault)
39+
3540
1. To turn on both soft delete and purge protection when creating a vault, use the [az keyvault create](/cli/azure/keyvault#az-keyvault-create) command.
3641

3742
```azurecli-interactive
@@ -42,6 +47,22 @@ After you enable customer-managed keys, you need to associate the customer manag
4247
```azurecli-interactive
4348
az keyvault update --name contoso-SB-BYOK-keyvault --resource-group ContosoRG --enable-purge-protection true
4449
```
50+
51+
# [Key Vault Managed HSM](#tab/Key-Vault-Managed-HSM)
52+
53+
1. To turn on both soft delete and purge protection when creating a vault, use the [az keyvault create](/cli/azure/keyvault#az-keyvault-create) command.
54+
55+
```azurecli-interactive
56+
az keyvault create --hsm-name contoso-SB-BYOK-keyvault --resource-group ContosoRG --location westus --enable-soft-delete true --enable-purge-protection true
57+
```
58+
1. To add purge protection to an existing vault (that already has soft delete enabled), use the [az keyvault update](/cli/azure/keyvault#az-keyvault-update) command.
59+
60+
```azurecli-interactive
61+
az keyvault update --hsm-name contoso-SB-BYOK-keyvault --resource-group ContosoRG --enable-purge-protection true
62+
```
63+
64+
---
65+
4566
1. Create keys by following these steps:
4667
1. To create a new key, select **Generate/Import** from the **Keys** menu under **Settings**.
4768
@@ -61,23 +82,23 @@ After you enable customer-managed keys, you need to associate the customer manag
6182
6283
6384
> [!IMPORTANT]
64-
> If you are looking to use Customer managed key along with Geo disaster recovery, please review this section.
85+
> If you are looking to use Customer managed key along with [Geo-Disaster Recovery](service-bus-geo-dr.md), please review this section.
6586
>
6687
> To enable encryption of Microsoft-managed key with a customer managed key, an [access policy](../key-vault/general/security-features.md) is set up for the Service Bus' managed identity on the specified Azure KeyVault. This ensures controlled access to the Azure KeyVault from the Azure Service Bus namespace.
6788
>
6889
> Due to this:
6990
>
70-
> * If [Geo disaster recovery](service-bus-geo-dr.md) is already enabled for the Service Bus namespace and you are looking to enable customer managed key, then
91+
> * If [Geo-Disaster Recovery](service-bus-geo-dr.md) is already enabled for the Service Bus namespace and you are looking to enable customer managed key, then
7192
> * Break the pairing
7293
> * [Set up the access policy](../key-vault/general/assign-access-policy-portal.md) for the managed identity for both the primary and secondary namespaces to the key vault.
7394
> * Set up encryption on the primary namespace.
7495
> * Re-pair the primary and secondary namespaces.
7596
>
76-
> * If you are looking to enable Geo-DR on a Service Bus namespace where customer managed key is already set up, then -
97+
> * If you are looking to enable Geo-Disaster Recovery on a Service Bus namespace where customer managed key is already set up, then -
7798
> * [Set up the access policy](../key-vault/general/assign-access-policy-portal.md) for the managed identity for the secondary namespace to the key vault.
7899
> * Pair the primary and secondary namespaces.
79100
>
80-
> * Once paired, the secondary namespace will use the key vault configured for the primary namespace. If the key vault for both namespaces is different before Geo-DR pairing, the user must delegate an access policy or RBAC role for the managed identity of the secondary namespace in the key vault associated with primary namespace.
101+
> * Once paired, the secondary namespace will use the key vault configured for the primary namespace. If the key vault for both namespaces is different before Geo-Disaster Recovery pairing, the user must delegate an access policy or RBAC role for the managed identity of the secondary namespace in the key vault associated with primary namespace.
81102
82103
## Managed identities
83104
There are two types of managed identities that you can assign to a Service Bus namespace.
@@ -92,7 +113,7 @@ This section shows how to do the following tasks:
92113
93114
1. Create a **premium** Service Bus namespace with a **managed service identity**.
94115
2. Create a **key vault** and grant the service identity access to the key vault.
95-
3. Update the Service Bus namespace with the key vault information (key/value).
116+
3. Update the Service Bus namespace with the key vault information (key/value).
96117
97118
### Create a premium Service Bus namespace with managed service identity
98119
This section shows you how to create an Azure Service Bus namespace with managed service identity by using an Azure Resource Manager template and PowerShell.
@@ -145,7 +166,7 @@ This section shows you how to create an Azure Service Bus namespace with managed
145166
}
146167
}
147168
```
148-
2. Create a template parameter file named: **CreateServiceBusPremiumNamespaceParams.json**.
169+
1. Create a template parameter file named: **CreateServiceBusPremiumNamespaceParams.json**.
149170
150171
> [!NOTE]
151172
> Replace the following values:
@@ -166,7 +187,7 @@ This section shows you how to create an Azure Service Bus namespace with managed
166187
}
167188
}
168189
```
169-
3. Run the following PowerShell command to deploy the template to create a premium Service Bus namespace. Then, retrieve the ID of the Service Bus namespace to use it later. Replace `{MyRG}` with the name of the resource group before running the command.
190+
1. Run the following PowerShell command to deploy the template to create a premium Service Bus namespace. Then, retrieve the ID of the Service Bus namespace to use it later. Replace `{MyRG}` with the name of the resource group before running the command.
170191
171192
```powershell
172193
$outputs = New-AzResourceGroupDeployment -Name CreateServiceBusPremiumNamespace -ResourceGroupName {MyRG} -TemplateFile ./CreateServiceBusPremiumNamespace.json -TemplateParameterFile ./CreateServiceBusPremiumNamespaceParams.json
@@ -176,20 +197,7 @@ This section shows you how to create an Azure Service Bus namespace with managed
176197
177198
### Grant Service Bus namespace identity access to key vault
178199
179-
1. Run the following command to create a key vault with **purge protection** and **soft-delete** enabled.
180-
181-
```powershell
182-
New-AzureRmKeyVault -Name "{keyVaultName}" -ResourceGroupName {RGName} -Location "{location}" -EnableSoftDelete -EnablePurgeProtection
183-
```
184-
185-
(OR)
186-
187-
Run the following command to update an **existing key vault**. Specify values for resource group and key vault names before running the command.
188-
189-
```powershell
190-
($updatedKeyVault = Get-AzureRmResource -ResourceId (Get-AzureRmKeyVault -ResourceGroupName {RGName} -VaultName {keyVaultName}).ResourceId).Properties| Add-Member -MemberType "NoteProperty" -Name "enableSoftDelete" -Value "true"-Force | Add-Member -MemberType "NoteProperty" -Name "enablePurgeProtection" -Value "true" -Force
191-
```
192-
2. Set the key vault access policy so that the managed identity of the Service Bus namespace can access key value in the key vault. Use the ID of the Service Bus namespace from the previous section.
200+
1. Set the key vault access policy so that the managed identity of the Service Bus namespace can access key value in the key vault. Use the ID of the Service Bus namespace from the previous section.
193201
194202
```powershell
195203
$identity = (Get-AzureRmResource -ResourceId $ServiceBusNamespaceId -ExpandProperties).Identity
@@ -201,7 +209,7 @@ This section shows you how to create an Azure Service Bus namespace with managed
201209
You have done the following steps so far:
202210
203211
1. Created a premium namespace with a managed identity.
204-
2. Create a key vault and granted the managed identity access to the key vault.
212+
1. Create a key vault and granted the managed identity access to the key vault.
205213
206214
In this step, you update the Service Bus namespace with key vault information.
207215
@@ -268,14 +276,16 @@ In this step, you update the Service Bus namespace with key vault information.
268276
}
269277
```
270278
271-
2. Create a template parameter file: **UpdateServiceBusNamespaceWithEncryptionParams.json**.
279+
1. Create a template parameter file: **UpdateServiceBusNamespaceWithEncryptionParams.json**.
272280
273281
> [!NOTE]
274282
> Replace the following values:
275283
> - `<ServiceBusNamespaceName>` - Name of your Service Bus namespace
276284
> - `<Location>` - Location of your Service Bus namespace
277285
> - `<KeyVaultName>` - Name of your key vault
278-
> - `<KeyName>` - Name of the key in the key vault
286+
> - `<KeyName>` - Name of the key in the key vault
287+
288+
# [Key Vault](#tab/Key-Vault)
279289
280290
```json
281291
{
@@ -296,8 +306,34 @@ In this step, you update the Service Bus namespace with key vault information.
296306
}
297307
}
298308
}
299-
```
300-
3. Run the following PowerShell command to deploy the Resource Manager template. Replace `{MyRG}` with the name of your resource group before running the command.
309+
```
310+
311+
# [Key Vault Managed HSM](#tab/Key-Vault-Managed-HSM)
312+
313+
```json
314+
{
315+
"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
316+
"contentVersion":"1.0.0.0",
317+
"parameters":{
318+
"namespaceName":{
319+
"value":"<ServiceBusNamespaceName>"
320+
},
321+
"location":{
322+
"value":"<Location>"
323+
},
324+
"keyName":{
325+
"value":"<KeyName>"
326+
},
327+
"keyVaultUri":{
328+
"value":"https://<KeyVaultName>.managedhsm.azure.net"
329+
}
330+
}
331+
}
332+
```
333+
334+
---
335+
336+
1. Run the following PowerShell command to deploy the Resource Manager template. Replace `{MyRG}` with the name of your resource group before running the command.
301337
302338
```powershell
303339
New-AzResourceGroupDeployment -Name UpdateServiceBusNamespaceWithEncryption -ResourceGroupName {MyRG} -TemplateFile ./UpdateServiceBusNamespaceWithEncryption.json -TemplateParameterFile ./UpdateServiceBusNamespaceWithEncryptionParams.json
@@ -315,27 +351,14 @@ Follow instructions from the [Create a user-assigned managed identity](../active
315351
> [!NOTE]
316352
> You can assign up to **4** user identities to a namespace. These associations are deleted when the namespace is deleted or when you pass the `identity -> type` in the template to `None`.
317353
318-
### Create a key vault and grant access to user-assigned identity
319-
320-
1. Run the following command to create a key vault with purge protection and soft-delete enabled.
321-
322-
```azurepowershell-interactive
323-
New-AzureRmKeyVault -Name "{keyVaultName}" -ResourceGroupName {RGName} -Location "{location}" -EnableSoftDelete -EnablePurgeProtection
324-
```
325-
326-
(OR)
354+
### Grant access to user-assigned identity
327355
328-
Run the following command to update an existing key vault. Specify values for resource group and key vault names before running the command.
329-
330-
```azurepowershell-interactive
331-
($updatedKeyVault = Get-AzureRmResource -ResourceId (Get-AzureRmKeyVault -ResourceGroupName {RGName} -VaultName {keyVaultName}).ResourceId).Properties| Add-Member -MemberType "NoteProperty" -Name "enableSoftDelete" -Value "true"-Force | Add-Member -MemberType "NoteProperty" -Name "enablePurgeProtection" -Value "true" -Force
332-
```
333-
2. Get the **Service principal ID** for the user identity using the following PowerShell command. In the example, `ud1` is the user-assigned identity to be used for encryption.
356+
1. Get the **Service principal ID** for the user identity using the following PowerShell command. In the example, `ud1` is the user-assigned identity to be used for encryption.
334357
335358
```azurepowershell-interactive
336359
$servicePrincipal=Get-AzADServicePrincipal -SearchString "ud1"
337360
```
338-
3. Grant the user-assigned identity access to the key vault by assigning an access policy.
361+
1. Grant the user-assigned identity access to the key vault by assigning an access policy.
339362
340363
```azurepowershell-interactive
341364
Set-AzureRmKeyVaultAccessPolicy -VaultName {keyVaultName} -ResourceGroupName {RGName} -ObjectId $servicePrincipal.Id -PermissionsToKeys get,wrapKey,unwrapKey,list
@@ -374,7 +397,6 @@ This section gives you an example that shows you how to do the following tasks u
374397
}
375398
```
376399
377-
378400
1. Create a JSON file named **CreateServiceBusNamespaceWithUserIdentityAndEncryption.json** with the following content:
379401
380402
```json
@@ -405,8 +427,7 @@ This section gives you an example that shows you how to do the following tasks u
405427
"type":"string",
406428
"metadata":{
407429
"description":"KeyName."
408-
}
409-
},
430+
},
410431
"identity": {
411432
"type": "Object",
412433
"defaultValue": {
@@ -452,8 +473,11 @@ This section gives you an example that shows you how to do the following tasks u
452473
]
453474
}
454475
```
476+
455477
1. Create a template parameter file: **CreateServiceBusNamespaceWithUserIdentityAndEncryptionParams.json**.
456478
479+
# [Key Vault](#tab/Key-Vault)
480+
457481
```json
458482
{
459483
"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
@@ -480,6 +504,36 @@ This section gives you an example that shows you how to do the following tasks u
480504
}
481505
```
482506
507+
# [Key Vault Managed HSM](#tab/Key-Vault-Managed-HSM)
508+
509+
```json
510+
{
511+
"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
512+
"contentVersion":"1.0.0.0",
513+
"parameters":{
514+
"namespaceName":{
515+
"value":"<ServiceBusNamespaceName>"
516+
},
517+
"location":{
518+
"value":"<Location>"
519+
},
520+
"keyVaultUri":{
521+
"value":"https://<KeyVaultName>.managedhsm.azure.net"
522+
},
523+
"keyName":{
524+
"value":"<KeyName>"
525+
},
526+
"identity": {
527+
"value": {
528+
"userAssignedIdentity": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<USER MANAGED IDENTITY NAME>"
529+
}
530+
}
531+
}
532+
}
533+
```
534+
535+
---
536+
483537
In the parameter file, replace placeholders with appropriate values.
484538
485539
| Placeholder | value |
@@ -592,29 +646,29 @@ Here are more details:
592646
- If a key has been revoked, the key is removed from the record.
593647
- If all keys have been revoked, the namespace’s encryption status is set to **Revoked**. The data can't be accessed from the Service Bus namespace.
594648

595-
## Considerations when using geo-disaster recovery
649+
## Considerations when using Geo-Disaster Recovery
596650

597-
### Geo-disaster recovery - encryption with system-assigned identities
651+
### Geo-Disaster Recovery - encryption with system-assigned identities
598652
To enable encryption of Microsoft-managed key with a customer managed key, an [access policy](../key-vault/general/secure-your-key-vault.md) is set up for a system-assigned managed identity on the specified Azure KeyVault. This step ensures controlled access to the Azure KeyVault from the Azure Service Bus namespace. Therefore, you need to follow these steps:
599653

600654

601-
- If [Geo disaster recovery](service-bus-geo-dr.md) is already enabled for the Service Bus namespace and you're looking to enable customer managed key, then
655+
- If [Geo-Disaster Recovery](service-bus-geo-dr.md) is already enabled for the Service Bus namespace and you're looking to enable customer managed key, then
602656
- Break the pairing.
603657
- [Set up the access policy](../key-vault/general/assign-access-policy-portal.md) for the system-assigned managed identity for both the primary and secondary namespaces to the key vault.
604658
- Set up encryption on the primary namespace.
605659
- Re-pair the primary and secondary namespaces.
606-
- If you're looking to enable Geo-DR on a Service Bus namespace where customer-managed key is already set up, then follow these steps:
660+
- If you're looking to enable Geo-Disaster Recovery on a Service Bus namespace where customer-managed key is already set up, then follow these steps:
607661
- [Set up the access policy](../key-vault/general/assign-access-policy-portal.md) for the managed identity for the secondary namespace to the key vault.
608662
- Pair the primary and secondary namespaces.
609663

610-
### Geo-disaster recovery - encryption with user-assigned identities
664+
### Geo-Disaster Recovery - encryption with user-assigned identities
611665
Here are a few recommendations:
612666

613667
1. Create managed identity and assign Key Vault permissions to your managed identity.
614668
2. Add the identity as a user assigned identity, and enable encryption with the identity on both namespaces.
615669
3. Pair namespaces together
616670

617-
Conditions for enabling Geo-DR and Encryption with User-Assigned Identities:
671+
Conditions for enabling Geo-Disaster Recovery and Encryption with User-Assigned Identities:
618672

619673
1. Secondary namespace must already have Encryption enabled with a User-Assigned identity if it's to be paired with a primary namespace that has Encryption enabled.
620674
2. It isn't possible to enable Encryption on an already paired primary, even if the secondary has a User-Assigned identity associated with the namespace.
@@ -633,4 +687,4 @@ Use the [`resource__versionless_id` or `versionless_id`](https://registry.terraf
633687
## Next steps
634688
See the following articles:
635689
- [Service Bus overview](service-bus-messaging-overview.md)
636-
- [Key Vault overview](../key-vault/general/overview.md)
690+
- [Key Vault overview](../key-vault/general/overview.md)

0 commit comments

Comments
 (0)