Microsoft Azure Cloud HSM 可讓您備份和還原雲端 HSM,並保留所有密鑰、版本、屬性、卷標和角色指派。
這很重要
當您建立 Azure 雲端 HSM 備份時,它會受到 HSM 內衍生的金鑰所保護。 Microsoft無法檢視或存取可保護備份的衍生密鑰。 Azure 雲端 HSM 不支援將備份還原至其來源 HSM 或任何已啟用的雲端 HSM。 若要還原,請在任何偏好的區域中使用另一個尚未啟用的雲端 HSM。 否則,還原作業會失敗,使目標 Cloud HSM 變得無法運作。
先決條件
下列必要條件支援 Azure 雲端 HSM 備份和還原作業。
- 針對 Azure 雲端 HSM 來源和目的地設定的受控服務識別。
- 具有 RBAC 的 Azure Blob 儲存體 (儲存體 Blob 資料參與者)。
- Azure Cloud HSM 目的地資源必須處於 NotActivated 狀態。
下列設定不支援使用 Azure Cloud HSM 進行備份和還原。
- 不支援儲存容器 SAS 權杖。
將 MSI 套用至雲端 HSM 並建立 HSM 備份的記憶體帳戶
建立受控服務識別
在現有的 Azure Cloud HSM 資源群組中建立新的使用者指派受控服務識別。 在此引導式範例中,我們使用 CHSM-MSI 和 CHSM-SERVER-RG,也就是 Azure Cloud HSM 上線指南範例中所參考的資源組名。
# Define parameters for the new managed service identity (MSI)
$identity = @{
Location = "<RegionName>"
ResourceName = "<MSIName>"
ResourceGroupName = "<ResourceGroupName>"
SubscriptionID = "<SubscriptionID>"
}
# Create a new user-assigned managed service identity (MSI) in the specified resource group and location
New-AzUserAssignedIdentity -Name $identity.ResourceName -ResourceGroupName $identity.ResourceGroupName -Location $identity.Location
將 MSI 套用至來源和目的地 Cloud HSM
針對 Azure 雲端 HSM 備份和還原作業,受控服務識別 (MSI) 必須同時套用至您的來源和目的地 Cloud HSM 資源。 每個雲端 HSM 叢集只能有一個 MSI。 您可以針對來源和目的地使用相同的 MSI,或針對每個來源和目的地使用不同的 MSIS。 在此引導式範例中,我們會將相同的 MSI 同時套用至來源和目的地 Cloud HSM 資源。
# Define the source Cloud HSM parameters
$sourceCloudHSM = @{
Location = "<RegionName>"
Sku = @{ "family" = "B"; "Name" = "Standard_B1" }
ResourceName = "<SourceCloudHSMName>"
ResourceType = "microsoft.hardwaresecuritymodules/cloudHsmClusters"
ResourceGroupName = "<SourceResourceGroupName>"
Force = $true
}
# Define the destination Cloud HSM parameters
$destinationCloudHSM = @{
Location = "<RegionName>"
Sku = @{ "family" = "B"; "Name" = "Standard_B1" }
ResourceName = "<DestinationCloudHSMName>"
ResourceType = "microsoft.hardwaresecuritymodules/cloudHsmClusters"
ResourceGroupName = "<DestinationResourceGroupName>"
Force = $true
}
# Define the Cloud HSM MSI patch payload
$chsmMSIPatch = '{
"Sku": {
"Family": "B",
"Name": "Standard_B1"
},
"Location": "<RegionName>",
"Identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/<SubscriptionID>/resourcegroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<MSIName>": {}
}
}
}'
# Construct the source URI
$sourceURI = "/subscriptions/$($identity.SubscriptionID)/resourceGroups/$($sourceCloudHSM.ResourceGroupName)/providers/Microsoft.HardwareSecurityModules/cloudHsmClusters/$($sourceCloudHSM.ResourceName)?api-version=2024-06-30-preview"
# Construct the destination URI
$destinationURI = "/subscriptions/$($identity.SubscriptionID)/resourceGroups/$($destinationCloudHSM.ResourceGroupName)/providers/Microsoft.HardwareSecurityModules/cloudHsmClusters/$($destinationCloudHSM.ResourceName)?api-version=2024-06-30-preview"
# Invoke REST method to update the source Cloud HSM with MSI patch
Invoke-AzRestMethod -Path $sourceURI -Method Put -Payload $chsmMSIPatch
# Invoke REST method to update the destination Cloud HSM with MSI patch
Invoke-AzRestMethod -Path $destinationURI -Method Put -Payload $chsmMSIPatch
在私人 VNET 中為雲端 HSM 備份建立記憶體帳戶
藉由定義及設定私人虛擬網路內的記憶體帳戶和相關聯的 Blob 容器,來設定 Azure Cloud HSM 備份作業的記憶體基礎結構。 首先,定義訂用帳戶標識碼並指定記憶體帳戶參數,包括位置、SKU 和類型。 此程式包括建立新的資源群組、使用網路規則建立記憶體帳戶,以限制對指定虛擬網路的存取,以及透過私人端點增強安全性。 私人端點會設定為安全存取,並將「儲存體 Blob 資料參與者」角色指派給指定的身分識別,以確保備份工作的適當權限。 在此範例中,我們會建立名為 CHSM-BACKUP-RG 的新資源群組、名為 chsmbackup00 的記憶體帳戶,以及名為 chsmbackupcontainer00 的 Blob 容器,並同時授與來源和目的地的讀取/寫入存取權。
這很重要
所需的最小 RBAC 角色是 儲存體 Blob 資料參與者。 公用記憶體帳戶可透過公用因特網存取,因此請將您的記憶體帳戶放在私人 VNET 後面,以提高安全性。
# Define the subscription ID
$subscriptionId = "<SubscriptionID>"
# Define storage account parameters
$storageAccount = @{
Location = "<RegionName>"
ResourceGroupName = "<BackupResourceGroupName>"
AccountName = "<ResourceName>" # Name for the storage account
SkuName = "<StorageAccountSKU>" # Storage account SKU (example: Standard_LRS)
Kind = "<StorageAccountType>" #Type of storage account (example: StorageV2)
}
# Define the blob container parameters
$container = @{
ResourceGroupName = $storageAccount.ResourceGroupName # Resource group name where the storage account is located
StorageAccountName = $storageAccount.AccountName # Name of the storage account
ContainerName = "<StorageContainerName>" # Name for the blob container
}
# Define the private endpoint parameters
# Storage accounts are publicly accessible, its recommended to put it behind a private VNET
$privateEndpoint = @{
Name = "<PrivateEndpointName>"
VnetName = "<ExistingVNetName>" # Name of the existing VNet
SubnetName = "<ExistingSubnetName>" # Name of the existing subnet within the VNet
ResourceGroupName = "<ResourceGroupName>" # Resource group for private VNet and subnet (example: CHSM-CLIENT-RG)
}
# Define the role assignment parameters
$roleAssignment = @{
RoleDefinitionName = "Storage Blob Data Contributor" # Minimum RBAC role required
PrincipalId = "<PrincipalId>" # The ID of the managed identity or user to assign the role to
Scope = "/subscriptions/$($subscriptionId)/resourceGroups/$($storageAccount.ResourceGroupName)/providers/Microsoft.Storage/storageAccounts/$($storageAccount.AccountName)"
}
# Create a new resource group with the specified name and location
New-AzResourceGroup -Name $storageAccount.ResourceGroupName -Location $storageAccount.Location -Force
# Create a new storage account in the specified resource group and location
# This command sets up the storage account needed for backup operations
New-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName `
-Name $storageAccount.AccountName `
-Location $storageAccount.Location `
-SkuName $storageAccount.SkuName `
-Kind $storageAccount.Kind
# Retrieve the storage account key
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.AccountName)[0].Value
# Create the storage context
$storageAccountContext = New-AzStorageContext -StorageAccountName $storageAccount.AccountName -StorageAccountKey $storageAccountKey
# Create the blob container in the storage account
New-AzStorageContainer -Name $container.ContainerName -Context $storageAccountContext
# Retrieve the virtual network and subnet object
$vnet = Get-AzVirtualNetwork -ResourceGroupName $privateEndpoint.ResourceGroupName -Name $privateEndpoint.VnetName
$subnet = $vnet.Subnets | Where-Object { $_.Name -eq $privateEndpoint.SubnetName }
# Create the private endpoint for the storage account in the existing VNet
New-AzPrivateEndpoint -ResourceGroupName $storageAccount.ResourceGroupName `
-Name $privateEndpoint.Name `
-Location $storageAccount.Location `
-PrivateLinkServiceConnection @(
@{
Name = "$($storageAccount.AccountName)-connection"
PrivateLinkServiceConnectionState = @{
Status = "Approved"
Description = "Private Endpoint Connection"
}
PrivateLinkServiceId = "/subscriptions/$subscriptionId/resourceGroups/$($storageAccount.ResourceGroupName)/providers/Microsoft.Storage/storageAccounts/$($storageAccount.AccountName)"
GroupIds = @("blob") # Add this parameter with the required group ID
}
) `
-Subnet $subnet
# Assign 'Storage Blob Data Contributor' role to the specified identity
New-AzRoleAssignment -RoleDefinitionName $roleAssignment.RoleDefinitionName `
-PrincipalId $roleAssignment.PrincipalId `
-Scope $roleAssignment.Scope
透過入口網站設定停用共用金鑰存取
停用共用金鑰存取以增強安全性。 若要這樣做,請流覽至您的 Azure 記憶體帳戶,選取 [設定 >> 組態],然後將 [允許記憶體帳戶密鑰存取權] 設定為 [已停用]。
Azure 雲端 HSM 備份
從來源 HSM 啟動雲端 HSM 備份
將具有記憶體容器 URI 的 POST 要求傳送至備份 API 端點,以啟動來源 Azure Cloud HSM 的備份。 將 GET 要求傳送至回應標頭中的 URL,以監視備份的進度。 腳本會從回應中擷取並顯示備份作業狀態和唯一備份標識碼,確認備份已啟動並追蹤其進度。
# Define backup properties, including the URI for the Azure Storage Blob container
$backupProperties = ConvertTo-Json @{
azureStorageBlobContainerUri = "https://$($container.StorageAccountName).blob.core.windows.net/$($container.ContainerName)"
}
# Construct the URI for the backup operation using the provided parameters
$backupUri = "/subscriptions/$($identity.SubscriptionID)/resourceGroups/$($sourceCloudHSM.ResourceGroupName)/providers/Microsoft.HardwareSecurityModules/cloudHsmClusters/$($sourceCloudHSM.ResourceName)/backup?api-version=2024-06-30-preview"
# Initiate the backup operation by sending a POST request with the backup properties
$response = Invoke-AzRestMethod -Path $backupUri -Method Post -Payload $backupProperties
# Check the backup job status to confirm it succeeded
$jobStatus = Invoke-AzRestMethod -Method 'GET' -Uri $response.Headers.Location
$backupStatus = (ConvertFrom-Json $jobStatus.Content).properties.status
# Extract the backup ID from the job status response
$backupID = (ConvertFrom-Json $jobStatus.Content).properties.backupId
# Output the backup status and backup ID
$backupStatus
$backupID
預期的輸出: $backupStatus 傳回「成功」,並 $backupID 顯示您所起始備份的對應備份標識碼。
Azure 雲端 HSM 還原
啟動雲端 HSM 還原至目標 HSM
提供必要的還原屬性,包括記憶體容器 URI 和備份標識碼,以啟動目的地 Azure Cloud HSM 的還原作業。 腳本會為還原 API 端點建立正確的 URI,並傳送 POST 要求來起始還原。 若要監視還原進度,請將 GET 要求傳送至響應標頭中指定的位置,並擷取還原作業狀態以確認其完成。
$restoreProperties = ConvertTo-Json @{
"azureStorageBlobContainerUri" = "https://$($container.StorageAccountName).blob.core.windows.net/$($container.ContainerName)"
"backupId" = "$($backupID)"
}
# Set the URI for the restore API endpoint using the subscription ID, resource group, and destination server details
$restoreUri = "/subscriptions/$($identity.SubscriptionID)/resourceGroups/$($destinationCloudHSM.ResourceGroupName)/providers/Microsoft.HardwareSecurityModules/cloudHsmClusters/$($destinationCloudHSM.ResourceName)/restore?api-version=2024-06-30-preview"
# Initiate the restore operation by sending a POST request to the restore API endpoint with the defined properties
$response = Invoke-AzRestMethod -Path $restoreUri -Method Post -Payload $restoreProperties
# Check the status of the restore job by sending a GET request to the location provided in the response headers
$jobStatus = Invoke-AzRestMethod -Method 'GET' -Uri $response.Headers.Location
# Extract and display the status of the restore job
(ConvertFrom-Json $jobStatus.Content).properties.status
預期的輸出:$jobStatus應該會傳回 「Succeeded」。
驗證還原至目的地雲端 HSM
經過一些處理時間,還原作業應該會指出「成功」,而目的地雲端 HSM 應該會顯示「作用中」的啟用狀態。當您連線到執行還原作業的目的地雲端 HSM 時,執行 azcloudhsm_mgmt_util 和執行 getClusterInfo 應該會將這三個節點顯示為作用中且可用。
這很重要
從系統管理 VM 連線到 Azure Cloud HSM 時,更新用戶端和管理組態檔 (azcloudhsm_resource.cfg) 以指向執行還原的正確目的地 Cloud HSM。
執行下列命令以啟動
azcloudhsm_mgmt_util:Linux
cd /usr/local/bin/AzureCloudHSM-ClientSDK-* sudo ./azcloudhsm_mgmt_util ./azcloudhsm_resource.cfgWindows
cd azcloudhsm_mgmt_util .\azcloudhsm_mgmt_util.exe .\azcloudhsm_resource.cfg在管理公用程式內,提示符號會變成
cloudmgmt。 若要列出叢集資訊,請執行:getClusterInfo預期的輸出:
getClusterInfo應該確認所有三個節點現在都可供 Azure 雲端 HSM 叢集使用。結束管理公用程式,然後啟動 Azure 雲端 HSM 公用程式 (
azcloudhsm_util)。 以 CU 身分登入並執行findKey命令。這很重要
密鑰句柄可能會變更,因為它們是動態的;不過,金鑰標識碼不會變更。
Linux
./azcloudhsm_util loginHSM -u CU -s cu1 -p user1234 findKeyWindows
azcloudhsm_util.exe loginHSM -u CU -s cu1 -p user1234 findKey