Share via


適用於 Apache Cassandra 的 Azure 受控執行個體 中客戶管理的金鑰

在適用於 Apache Cassandra 的 Azure 受控執行個體 中,您可以使用自己的金鑰來加密磁碟上的數據。 本文說明如何使用 Azure 金鑰保存庫 來實作客戶管理的密鑰。

必要條件

  • 使用 Azure 金鑰保存庫 設定秘密。 如需詳細資訊,請參閱關於 Azure 金鑰保存庫 秘密

  • 在您的資源群組中部署虛擬網路。

  • 以 Azure Cosmos DB 服務主體作為成員套用網路參與者角色。 使用下列命令:

        az role assignment create \
        --assignee a232010e-820c-4083-83bb-3ace5fc29d0b \
        --role 4d97b98b-1d4f-4787-a291-c67834d212e7 \
        --scope /subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/virtualNetworks/<vnetName>
    

    將適當的角色套用至虛擬網路可協助您避免在部署適用於Apache Cassandra叢集的 Azure 受控執行個體 時發生失敗。 如需詳細資訊,請參閱使用 Azure CLI 建立適用於 Apache Cassandra 叢集的 Azure 受控執行個體。

本文需要 Azure CLI 2.30.0 版或更新版本。 若您使用的是 Azure Cloud Shell,即已安裝最新版本。

建立具有系統指派身分識別的叢集

  1. 使用下列命令建立叢集。 將、 <resourceGroupName><vnetName><subnetName> 取代<subscriptionID>為適當的值。

    subnet="/subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/virtualNetworks/<vnetName>/subnets/<subnetName>"
    cluster="thvankra-cmk-test-wcus"
    group="thvankra-nova-cmk-test"
    region="westcentralus"
    password="PlaceholderPassword"
    
    az managed-cassandra cluster create \
        --identity-type SystemAssigned \
        --resource-group $group \
        --location $region \
        --cluster-name $cluster \
        --delegated-management-subnet-id $subnet \
        --initial-cassandra-admin-password $password
    
  2. 取得所建立叢集的身分識別資訊:

    az managed-cassandra cluster show -c $cluster -g $group
    

    輸出包含身分識別區段,例如下列範例。 principalId複製值以供稍後使用。

      "identity": {
        "principalId": "1aa51c7f-196a-4013-a656-1ccabfdc54e0",
        "tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
        "type": "SystemAssigned"
      }
    
  3. 在 Azure 入口網站 中,移至您的密鑰保存庫,然後選取 [存取原則]。 然後選取 [ 新增存取原則 ],為您的密鑰建立存取原則。

    Screenshot that shows the pane for access policies in the Azure portal.

  4. 針對 [密鑰許可權],選取 [取得]、[包裝] 和 [解除包裝]。 選取 [ 選取主體 ] 方塊以開啟 [ 主體 ] 窗格。 輸入您稍早擷取的 principalId 叢集值,然後選取 [ 選取 ] 按鈕。 (在入口網站中,您也可以依叢集的名稱查閱叢集的主體標識符。

    Screenshot that shows an example of adding a principal for an access policy.

    警告

    請確定金鑰保存庫已開啟清除保護。 若未啟用,則會導致資料中心部署失敗。

  5. 選取 [新增 ] 以新增存取原則,然後選取 [ 儲存]。

    Screenshot that shows the button for saving an access policy.

  6. 若要取得金鑰標識碼,請選取 [金鑰],然後選取您的密鑰。

    Screenshot that shows the pane for selecting a key.

  7. 選取目前的版本。

    Screenshot that shows the box for selecting the current version of a key.

  8. 儲存金鑰標識碼以供稍後使用。

    Screenshot that shows copying a key identifier to the clipboard.

  9. 將 取代 <key identifier> 為您在上一個步驟中複製的相同金鑰(您在上一個步驟中複製的 URI)來建立資料中心,以進行受控磁碟 (managed-disk-customer-key-uri) 和備份記憶體 (backup-storage-customer-key-uri) 加密。 針對您稍早使用的相同值 subnet

    managedDiskKeyUri = "<key identifier>"
    backupStorageKeyUri = "<key identifier>"
    group="thvankra-nova-cmk-test"
    region="westcentralus"
    cluster="thvankra-cmk-test-2"
    dc="dc1"
    nodecount=3
    subnet="/subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/virtualNetworks/<vnetName>/subnets/<subnetName>"
    
    az managed-cassandra datacenter create \
        --resource-group $group \
        --cluster-name $cluster \
        --data-center-name $dc \
        --managed-disk-customer-key-uri $managedDiskKeyUri \
        --backup-storage-customer-key-uri $backupStorageKeyUri \
        --node-count $nodecount \
        --delegated-subnet-id $subnet \
        --data-center-location $region \
        --sku Standard_DS14_v2
    

您也可以將身分識別指派給沒有身分識別資訊的現有叢集:

az managed-cassandra cluster update --identity-type SystemAssigned -g $group -c $cluster

輪替金鑰

若要更新金鑰,請使用此指令:

managedDiskKeyUri = "<key identifier>"
backupStorageKeyUri = "<key identifier>"
    
az managed-cassandra datacenter update \
    --resource-group $group \
    --cluster-name $cluster \ 
    --data-center-name $dc \
    --managed-disk-customer-key-uri $managedDiskKeyUri \
    --backup-storage-customer-key-uri $backupStorageKeyUri