Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Azure Dedicated HSM is being retired. Microsoft will fully support existing Dedicated HSM customers until July 31, 2028. No new customer onboardings are accepted. For full details and required actions, see the official Azure update.
If you're an Azure Dedicated HSM user, see Migrate from Azure Dedicated HSM to Managed HSM or Azure Cloud HSM. Azure Cloud HSM is now generally available and the successor to Azure Dedicated HSM.
New customers should evaluate and onboard to Azure Cloud HSM, Managed HSM, or Azure Key Vault based on their workload requirements. For guidance, see How to choose the right Azure key management solution.
This article describes how to create and manage an Azure Dedicated HSM by using the hardware-security-modules Azure CLI extension.
Prerequisites
An Azure subscription. You can create a free account if you don't have one.
If you have more than one Azure subscription, set the subscription to use for billing with the Azure CLI az account set command.
az account set --subscription 00000000-0000-0000-0000-000000000000
Use the Bash environment in Azure Cloud Shell. For more information, see Get started with Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Authenticate to Azure using Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use and manage extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
The hardware-security-modules Azure CLI extension. Install it with the az extension add command:
az extension add --name hardware-security-modulesThe required resource providers and feature flags registered for your subscription. Register the
AzureDedicatedHsmandDedicatedHsmEnabledfeatures, and then register theMicrosoft.HardwareSecurityModulesprovider. If theDedicatedHsmEnabledfeature isn't registered, dedicated HSM commands return anInvalidResourceTypeerror.az feature register --namespace Microsoft.HardwareSecurityModules --name AzureDedicatedHsm az feature register --namespace Microsoft.HardwareSecurityModules --name DedicatedHsmEnabled az provider register -n Microsoft.HardwareSecurityModulesFeature registration can take a few minutes. Confirm that both features show a state of
Registeredbefore you continue:az feature show --namespace Microsoft.HardwareSecurityModules --name AzureDedicatedHsm --query properties.state az feature show --namespace Microsoft.HardwareSecurityModules --name DedicatedHsmEnabled --query properties.state
Create a resource group
An Azure resource group is a logical container for deploying and managing Azure resources as a group. If you don't already have a resource group for the dedicated HSM, create one by using the az group create command. The following example creates a resource group named myRG in the westus Azure region:
az group create --name myRG --location westus
Create the network resources
A dedicated HSM is injected into a subnet in your virtual network, and the virtual network must have an ExpressRoute gateway. Without a gateway, the create operation fails with an error in connecting the device to the virtual network.
Create a virtual network with a subnet for compute resources by using the az network vnet create command:
az network vnet create \ --name myHSM-vnet \ --resource-group myRG \ --address-prefix 10.2.0.0/16 \ --subnet-name compute \ --subnet-prefix 10.2.0.0/24Add a subnet for the HSM by using the az network vnet subnet create command. Delegate the subnet to
Microsoft.HardwareSecurityModules/dedicatedHSMs, and use a name that's different from the virtual network name.az network vnet subnet create \ --resource-group myRG \ --vnet-name myHSM-vnet \ --name hsmsubnet \ --address-prefixes 10.2.1.0/24 \ --delegations Microsoft.HardwareSecurityModules/dedicatedHSMsAdd the
GatewaySubnetthat the ExpressRoute gateway requires:az network vnet subnet create \ --resource-group myRG \ --vnet-name myHSM-vnet \ --name GatewaySubnet \ --address-prefixes 10.2.255.0/26Create the ExpressRoute gateway by using the az network vnet-gateway create command. Use the
ErGwScaleSKU. Azure automatically assigns and manages the gateway's public IP address, so don't create a public IP resource or pass the--public-ip-addressesparameter.az network vnet-gateway create \ --resource-group myRG \ --name myergw \ --vnet myHSM-vnet \ --gateway-type ExpressRoute \ --sku ErGwScale \ --min-scale-unit 1 \ --max-scale-unit 1The gateway takes approximately 17 minutes to deploy.
Note
In West US, the
ErGwScaleSKU worked for this scenario. TheErGw1AZSKU was rejected withInvalidGatewaySkuSpecifiedForGatewayDeploymentType, and theStandardSKU failed withGatewayError.
Create a dedicated HSM
To create a dedicated HSM, use the az dedicated-hsm create command. The following example provisions a dedicated HSM named hsm1 in the westus region and myRG resource group. Pass the resource ID of the delegated HSM subnet, and assign a private IP address from inside that subnet's address range. The required parameters are name, location, and resource group.
az dedicated-hsm create \
--resource-group myRG \
--name "hsm1" \
--location "westus" \
--stamp-id "stamp1" \
--sku "SafeNet Luna Network HSM A790" \
--subnet id="/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myRG/providers/Microsoft.Network/virtualNetworks/myHSM-vnet/subnets/hsmsubnet" \
--network-interfaces private-ip-address="10.2.1.4" \
--tags resourceType="hsm" Environment="test"
The HSM create operation takes approximately 7 minutes to complete.
Get a dedicated HSM
To get a current dedicated HSM, run the az dedicated-hsm show command. The following example gets the hsm1 dedicated HSM in the myRG resource group.
az dedicated-hsm show --resource-group myRG --name hsm1
Note
The Azure portal doesn't list dedicated HSMs in their resource group. Use az dedicated-hsm show or az dedicated-hsm list to confirm that an HSM exists.
Update a dedicated HSM
Use the az dedicated-hsm update command to update a dedicated HSM. The following example updates the hsm1 dedicated HSM in the myRG resource group, and its tags:
az dedicated-hsm update --resource-group myRG --name hsm1 --tags resourceType="hsm" Environment="prod" Slice="A"
List dedicated HSMs
Run the az dedicated-hsm list command to get information about current dedicated HSMs. The following example lists the dedicated HSMs in the myRG resource group:
az dedicated-hsm list --resource-group myRG
Clean up resources
Caution
Zeroize and delete the dedicated HSM before you delete its resource group. Deleting the resource group directly doesn't delete the HSM. It places the HSM into an orphaned state that continues to incur charges. For more information, see How to delete an HSM resource.
Remove a dedicated HSM
After you zeroize the HSM, use the az dedicated-hsm delete command to remove it. The following example deletes the hsm1 dedicated HSM from the myRG resource group:
az dedicated-hsm delete --resource-group myRG --name hsm1
Tip
If a create operation fails, the delete operation can stay in a Deleting state for several hours. If it does, run the az dedicated-hsm delete command again to complete the deletion immediately.
Delete the resource group
After the HSM is deleted, you can delete the resource group if you no longer need it by running the az group delete command. This command deletes the group and all resources in it, including any that are unrelated to dedicated HSM. The following example deletes the myRG resource group and everything in it:
az group delete --name myRG
Next steps
To learn more about Azure Dedicated HSM, see Azure Dedicated HSM.