適用於:
Azure SQL Database
注意
- 資料庫層級 TDE CMK 適用於 Azure SQL 資料庫 (所有 SQL Database 版本)。 它不適用於 Azure SQL 受控執行個體、內部部署 SQL Server、Azure VM 和 Azure Synapse Analytics (專用 SQL 集區 (先前稱為 SQL DW))。
- 您可以套用相同的指南,排除同盟用戶端識別碼參數,在相同的租用戶中設定資料庫層級客戶自控金鑰。 如需資料庫層級客戶自控金鑰的詳細資訊,請參閱資料庫層級中使用客戶自控金鑰的透明資料加密 (TDE)。
在本指南中,我們在資料庫層級會逐步建立、更新和擷取具有透明資料加密 (TDE) 的 Azure SQL Database 和客戶自控 (CMK) 金鑰,利用使用者指派的受控識別來存取 Azure Key Vault。 Azure Key Vault 位於與 Azure SQL 資料庫不同的 Microsoft Entra 租用戶中。 如需詳細資訊,請參閱使用透明資料加密的跨租用戶客戶自控金鑰。
必要條件
- 本指南假設您有兩個 Microsoft Entra 租用戶。
- 第一個包含 Azure SQL Database 資源、多租使用者Microsoft Entra 應用程式,以及使用者指派的受控識別。
- 第二個租用戶會裝載 Azure Key Vault。
- 如需設定 Microsoft Entra 應用程式和 Azure Key Vault 所需的跨租用戶 CMK 和 RBAC 權限的完整指示,請參閱下列其中一個指南:
- Azure CLI 2.52.0 版或更高版本。
- Az PowerShell 模組 10.3.0 版或更高版本。
- 資料庫層級 CMK 所需的 RBAC 權限與伺服器層級 CMK 所需的權限相同。 具體而言,在伺服器層級使用 Azure 金鑰保存庫、 受控識別和 跨租用戶 CMK 進行 TDE 時適用的相同 RBAC 許可權也適用於資料庫層級。 如需金鑰管理和存取原則的詳細資訊,請參閱金鑰管理。
第一個租用戶上的必要資源
為因應本教學課程的目的,我們假設第一個租用戶屬於獨立軟體廠商 (ISV),而第二個租用戶來自其用戶端。 如需此案例的詳細資訊,請參閱使用透明資料加密的跨租用戶客戶自控金鑰。
在能夠使用跨租戶 CMK 來設定 Azure SQL Database 的 TDE 之前,我們需要具備一個已配置的多租戶 Microsoft Entra 應用程式,此應用程式透過使用者指派的受控識別,作為應用程式的同盟身分識別認證。 遵循必要條件中的其中一份指南。
在您想要建立 Azure SQL Database 的第一個租戶上,建立並設定多租戶 Microsoft Entra 應用程式。
建立使用者指派的受控識別。
將使用者指派的受控識別 設定為多租戶應用程式的同盟身份認證。
記錄應用程式名稱和應用程式識別碼。 這可在 Azure 入口網站>Microsoft Entra ID>企業應用程式中找到,並搜尋已建立的應用程式。
第二個租用戶上的必要資源
注意
自 2024 年 3 月 30 日起,Azure AD 和 MSOnline PowerShell 模組已被淘汰。 若要深入了解,請閱讀淘汰更新。 在此日期之後,對這些模組的支援僅限於對 Microsoft Graph PowerShell SDK 的移轉協助和安全性修正。 淘汰的模組將繼續運作至 2025 年 3 月 30 日。
我們建議移轉至 Microsoft Graph PowerShell 以與 Microsoft Entra ID (以前稱為 Azure AD) 互動。 如需了解常見的移轉問題,請參閱移轉常見問題。
注意:MSOnline 1.0.x 版可能會在 2024 年 6 月 30 日之後發生中斷。
在 Azure Key Vault 所在的第二個租用戶上,使用來自第一個租用戶已註冊應用程式的應用程式識別碼,建立服務主體 (應用程式)。 以下是如何註冊多租用戶應用程式的一些範例。 分別將 <TenantID> 和 <ApplicationID> 替換為來自 Microsoft Entra ID 的租戶 ID ,以及來自多租戶應用程式的應用程式 ID 。
前往 Azure 入口網站>Microsoft Entra ID>企業應用程式,並搜尋建立的應用程式。
建立 Azure Key Vault (如果您尚未建立),然後建立金鑰。
建立或設定存取原則。
- 在建立存取原則時,選取 [金鑰權限] 下的 [取得]、[包裝金鑰]、[解除包裝金鑰] 權限。
- 在建立存取原則時,於 主體 選項中選取在第一個步驟中已建立的多租用戶應用程式。
建立存取原則和金鑰之後, 請從 Azure Key Vault 擷取金鑰 ,並記錄 金鑰標識碼。
使用資料庫層級客戶自控金鑰建立新的 Azure SQL Database
以下是在具有使用者指派受控識別的 Azure SQL Database 上建立資料庫,以及如何在資料庫層級設定跨租用戶客戶自控金鑰的範例。 需要使用者指派的自控識別,於資料庫建立階段針對透明資料加密設定客戶自控金鑰。
移至 Azure SQL 中樞 at aka.ms/azuresqlhub。
在 Azure SQL 資料庫的窗格中,選取 [ 顯示選項]。
在 [Azure SQL 資料庫選項] 視窗中,選取 [建立 SQL 資料庫]。
在 [建立 SQL Database] 表單的 [基本資料] 索引標籤上,在 [專案詳細資料] 下,為資料庫選取想要的 Azure [訂用帳戶]、[資源群組] 和 [伺服器]。 然後,針對 [資料庫名稱],使用唯一的名稱。 如果您尚未為 Azure SQL 資料庫建立邏輯伺服器,請參閱建立伺服器並使用跨租用戶客戶自控金鑰 (CMK) 設定 TDE,以取得參考。
當您前往 [安全性] 索引標籤時,選取 [設定資料庫層級金鑰的透明資料加密]。
在 [透明資料加密] 功能表上,選取 [資料庫層級客戶自控金鑰 (CMK)]。
針對 [使用者指派的受控識別],選取 [設定] 以啟用資料庫身分識別,並在 [身分識別] 功能表中未列出所需的身分識別時,將使用者指派的受控識別 [新增] 至資源。 接著選取套用。
在 [透明資料加密] 功能表上,選取 [變更金鑰]。 針對要用於 TDE 的客戶自控金鑰,選取所需的訂閱、金鑰保存庫、金鑰和版本。 選取 [選取] 按鈕。 在您選取金鑰之後,您也可以使用 [透明資料加密] 功能表中的 [Azure Key vault URI (物件識別碼)],視需要新增其他資料庫金鑰。
您也可以使用 [透明資料加密] 功能表中的[自動輪替金鑰] 核取方塊,在資料庫層級啟用 [自動金鑰輪替]。
選取 [套用] 繼續建立資料庫。
選取 [下一步:其他設定]。
選取 [下一步:標記]。
請考慮使用 Azure 標籤。 例如,「Owner」或「CreatedBy」標籤可識別資源的建立者,以及 Environment 標籤可識別此資源是否處於生產、開發等狀態。如需詳細資訊,請參閱 開發 Azure 資源的命名和標記策略。
選擇 檢閱 + 創建。
檢閱 [檢閱 + 建立] 頁面之後,選取 [建立]。
注意
如果使用者指派的受控識別未在金鑰保存庫上啟用正確的權限,則資料庫建立將會失敗。 使用者指派的受控識別需要具有金鑰保存庫的 Get、wrapKey 和 unwrapKey 權限。 如需詳細資訊,請參閱利用客戶自控金鑰支援透明資料加密的受控識別。
如需如何安裝目前版本的 Azure CLI,請參閱安裝 Azure CLI 一文。
使用 az sql db create 命令建立資料庫,並設定使用者指派的受控識別和跨租用戶客戶自控的 TDE。 第二個租用戶的金鑰識別碼可用於 encryption-protector 欄位中。 多租使用者應用程式的 應用程式識別碼 可以在 [federated-client-id] 欄位中使用。
--encryption-protector-auto-rotation 參數可用來在資料庫層級上啟用自動金鑰輪替。
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像
az sql db create --resource-group $resourceGroupName --server $serverName --name mySampleDatabase --sample-name AdventureWorksLT --edition GeneralPurpose --compute-model Serverless --family Gen5 --capacity 2 --assign-identity --user-assigned-identity-id $identityid --encryption-protector $keyid --federated-client-id $federatedclientid --encryption-protector-auto-rotation True
在資料庫層級使用 PowerShell 建立資料庫,並設定使用者指派的受控識別和跨租用戶客戶自控的 TDE。
如需 Az PowerShell 模組安裝指示,請參閱安裝 Azure PowerShell。
使用 New-AzSqlDatabase Cmdlet。
取代範例中的下列值:
-
<ResourceGroupName>:Azure SQL 邏輯伺服器的資源群組名稱
-
<DatabaseName>:使用唯一 Azure SQL 資料庫名稱
-
<ServerName>:使用唯一的 Azure SQL 邏輯伺服器名稱
-
<UserAssignedIdentityId>:要指派給伺服器的使用者指派受控識別清單 (可以是一或多個)
-
<CustomerManagedKeyId>:來自第二個租使用者 Azure Key Vault 的密鑰標識碼
-
<FederatedClientId>:多租戶應用程式的應用程式識別符
-
-EncryptionProtectorAutoRotation:可用來在資料庫層級上啟用自動金鑰輪替
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像
# create a server with user-assigned managed identity and cross-tenant customer-managed TDE with automatic key rotation enabled
$params = @{
ResourceGroupName = '<ResourceGroupName>'
ServerName = '<ServerName>'
DatabaseName = '<DatabaseName>'
AssignIdentity = $true
UserAssignedIdentityId = '<UserAssignedIdentityId>'
EncryptionProtector = '<CustomerManagedKeyId>'
FederatedClientId = '<FederatedClientId>'
EncryptionProtectorAutoRotation = $true
}
New-AzSqlDatabase @params
以下是 ARM 範本的範例,其會建立 Azure SQL Database,包含資料庫層級中使用者指派的受控識別和客戶自控的 TDE。 針對跨租戶 CMK,請使用來自第二個租戶 Azure Key Vault 的 密鑰識別碼,以及來自多租戶應用程式的 應用程式識別碼。
如需詳細資訊和 ARM 範本,請參閱 適用於 Azure SQL 資料庫的 Azure Resource Manager 範本。
使用 Azure 入口網站中的自訂部署,然後在編輯器中建置您自己的範本。 接下來,將設定貼進範例之後,加以儲存。
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像 。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"server_name": {
"type": "String"
},
"database_name": {
"type": "String"
},
"user_assigned_identity": {
"type": "String"
},
"encryption_protector": {
"type": "String"
},
"federated_client_id": {
"type": "String"
},
"location": {
"type": "String"
},
"encryption_protector_auto_rotation": {
"type": "bool"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-02-01-preview",
"name": "[concat(parameters('server_name'), concat('/',parameters('database_name')))]",
"location": "[parameters('location')]",
"sku": {
"name": "Basic",
"tier": "Basic",
"capacity": 5
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('user_assigned_identity')]": {}
}
},
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": 104857600,
"catalogCollation": "SQL_Latin1_General_CP1_CI_AS",
"zoneRedundant": false,
"readScale": "Disabled",
"requestedBackupStorageRedundancy": "Geo",
"maintenanceConfigurationId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default",
"isLedgerOn": false,
"encryptionProtector": "[parameters('encryption_protector')]",
"federatedClientId": "[parameters('federated_client_id')]",
"encryptionProtectorAutoRotation": "[parameters('encryption_protector_auto_rotation')]"
}
}
]
}
使用資料庫層級客戶自控金鑰更新現有 Azure SQL Database
以下是在具有使用者指派受控識別的 Azure SQL Database 上更新現有的資料庫,以及如何在資料庫層級設定跨租用戶客戶自控金鑰的範例。 需要使用者指派的自控識別,於資料庫建立階段針對透明資料加密設定客戶自控金鑰。
在 Azure 入口網站中,瀏覽至要使用資料庫層級客戶自控金鑰更新的 SQL Database 資源。
在 [安全性] 下,選取 [身分識別]。 為此資料庫新增使用者指派的受控識別,然後選取 [儲存]
現在,前往資料庫 [安全性] 下的 [資料加密] 功能表。 選取 [資料庫層級客戶自控金鑰] (CMK)。 資料庫的資料庫身分識別應該已 [啟用],因為您在上一個步驟中已設定身分識別。
選取 [變更金鑰]。 針對要用於 TDE 的客戶自控金鑰,選取所需的訂閱、金鑰保存庫、金鑰和版本。 選取 [選取] 按鈕。 在您選取金鑰之後,您也可以使用 [資料加密] 功能表中的 [Azure Key vault URI (物件識別碼)],視需要新增其他資料庫金鑰。
如果您想要在資料庫層級上啟用 [自動金鑰輪替],請選取 [自動輪替金鑰] 核取方塊。
選取儲存。
如需如何安裝目前版本的 Azure CLI,請參閱安裝 Azure CLI 一文。
使用 az sql db create 命令更新資料庫,並設定使用者指派的受控識別和跨租用戶客戶自控的 TDE。 第二個租用戶的金鑰識別碼可用於 encryption-protector 欄位中。 多租使用者應用程式的 應用程式識別碼 可以在 [federated-client-id] 欄位中使用。
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像 。
--encryption-protector-auto-rotation 參數可用來在資料庫層級上啟用自動金鑰輪替。
az sql db update --resource-group $resourceGroupName --server $serverName --name mySampleDatabase --sample-name AdventureWorksLT --edition GeneralPurpose --compute-model Serverless --family Gen5 --capacity 2 --assign-identity --user-assigned-identity-id $identityid --encryption-protector $keyid --federated-client-id $federatedclientid --keys $keys --keys-to-remove $keysToRemove --encryption-protector-auto-rotation True
此清單 $keys 是以空格分隔的金鑰清單,這些金鑰要新增至資料庫,而 $keysToRemove 是必須從資料庫移除的金鑰空格分隔清單
$keys = '"https://yourvault.vault.azure.net/keys/yourkey1/6638b3667e384aefa31364f94d230000" "https://yourvault.vault.azure.net/keys/yourkey2/ fd021f84a0d94d43b8ef33154bca0000"'
$keysToRemove = '"https://yourvault.vault.azure.net/keys/yourkey3/6638b3667e384aefa31364f94d230000" "https://yourvault.vault.azure.net/keys/yourkey4/fd021f84a0d94d43b8ef33154bca0000"'
在資料庫層級使用 PowerShell 更新資料庫,並設定使用者指派的受控識別和跨租用戶客戶自控的 TDE。
如需 Az PowerShell 模組安裝指示,請參閱安裝 Azure PowerShell。
使用 Set-AzSqlDatabase Cmdlet。
取代範例中的下列值:
-
<ResourceGroupName>:Azure SQL 邏輯伺服器的資源群組名稱
-
<DatabaseName>:使用唯一 Azure SQL 資料庫名稱
-
<ServerName>:使用唯一的 Azure SQL 邏輯伺服器名稱
-
<UserAssignedIdentityId>:要指派給伺服器的使用者指派受控識別清單 (可以是一或多個)
-
<CustomerManagedKeyId>:來自第二個租使用者 Azure Key Vault 的密鑰標識碼
-
<FederatedClientId>:多租戶應用程式的應用程式識別符
-
<ListOfKeys>:要新增至資料庫的資料庫層級客戶自控金鑰逗號分隔清單
-
<ListOfKeysToRemove>:要從資料庫移除的資料庫層級客戶自控金鑰逗號分隔清單
-
-EncryptionProtectorAutoRotation:可用來在資料庫層級上啟用自動金鑰輪替
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像 。
$params = @{
ResourceGroupName = "<ResourceGroupName>"
ServerName = "<ServerName>"
DatabaseName = "<DatabaseName>"
AssignIdentity = $true
UserAssignedIdentityId = "<UserAssignedIdentityId>"
EncryptionProtector = "<CustomerManagedKeyId>"
FederatedClientId = "<FederatedClientId>"
KeyList = "<ListOfKeys>"
KeysToRemove = "<ListOfKeysToRemove>"
EncryptionProtectorAutoRotation = $true
}
Set-AzSqlDatabase @params
-KeyList 和 -KeysToRemove 的範例如下:
$keysToAdd = "https://yourvault.vault.azure.net/keys/yourkey1/fd021f84a0d94d43b8ef33154bca0000","https://yourvault.vault.azure.net/keys/yourkey2/fd021f84a0d94d43b8ef33154bca0000"
$keysToRemove = "https://yourvault.vault.azure.net/keys/yourkey3/fd021f84a0d94d43b8ef33154bca0000"
以下是 ARM 範本的範例,其會更新 Azure SQL Database,包含資料庫層級中使用者指派的受控識別和客戶自控的 TDE。 針對跨租戶 CMK,請使用來自第二個租戶 Azure Key Vault 的 密鑰識別碼,以及來自多租戶應用程式的 應用程式識別碼。
如需詳細資訊和 ARM 範本,請參閱 適用於 Azure SQL 資料庫的 Azure Resource Manager 範本。
使用 Azure 入口網站中的自訂部署,然後在編輯器中建置您自己的範本。 接下來,將設定貼進範例之後,加以儲存。
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像 。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"server_name": {
"type": "String"
},
"database_name": {
"type": "String"
},
"user_assigned_identity": {
"type": "String"
},
"encryption_protector": {
"type": "String"
},
"location": {
"type": "String"
},
"federated_client_id": {
"type": "String"
},
"keys_to_add": {
"type": "Object"
},
"encryption_protector_auto_rotation": {
"type": "bool"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-02-01-preview",
"name": "[concat(parameters('server_name'), concat('/',parameters('database_name')))]",
"location": "[parameters('location')]",
"sku": {
"name": "Basic",
"tier": "Basic",
"capacity": 5
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('user_assigned_identity')]": {}
}
},
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": 104857600,
"catalogCollation": "SQL_Latin1_General_CP1_CI_AS",
"zoneRedundant": false,
"readScale": "Disabled",
"requestedBackupStorageRedundancy": "Geo",
"maintenanceConfigurationId": "/subscriptions/e1775f9f-a286-474d-b6f0-29c42ac74554/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default",
"isLedgerOn": false,
"encryptionProtector": "[parameters('encryption_protector')]",
"keys": "[parameters('keys_to_add')]",
"federatedClientId": "[parameters('federated_client_id')]",
"encryptionProtectorAutoRotation": "[parameters('encryption_protector_auto_rotation')]"
}
}
]
}
encryption_protector 和 keys_to_add 參數的範例如下:
"keys_to_add": {
"value": {
"https://yourvault.vault.azure.net/keys/yourkey1/fd021f84a0d94d43b8ef33154bca0000": {},
"https://yourvault.vault.azure.net/keys/yourkey2/fd021f84a0d94d43b8ef33154bca0000": {}
}
},
"encryption_protector": {
"value": "https://yourvault.vault.azure.net/keys/yourkey2/fd021f84a0d94d43b8ef33154bca0000"
}
重要
若要從資料庫移除金鑰,必須將特定金鑰的關鍵字典值傳遞為 Null。 例如: "https://yourvault.vault.azure.net/keys/yourkey1/fd021f84a0d94d43b8ef33154bca0000": null 。
在 Azure SQL Database 上檢視資料庫層級客戶自控的金鑰設定
以下是擷取資料庫的資料庫層級客戶自控金鑰的範例。 ARM 資源 Microsoft.Sql/servers/databases 預設只會顯示資料庫上設定的 TDE 保護裝置和受控識別。 若要展開金鑰的完整清單,請使用參數 -ExpandKeyList。 此外,例如篩選準則和 -KeysFilter "current" 時間點的值 (例如 2023-01-01) 可用來擷取目前金鑰和過去在特定時間點使用的金鑰。 這些篩選準則僅支援個別資料庫查詢,而不支援伺服器層級查詢。
若要檢視 Azure 入口網站中的資料庫層級客戶自控金鑰,請前往 SQL Database 資源的 [資料加密] 功能表。
如需如何安裝目前版本的 Azure CLI,請參閱安裝 Azure CLI 一文。
# Retrieve the basic database level customer-managed key settings from a database
az sql db show --resource-group $resourceGroupName --server $serverName --name mySampleDatabase
# Retrieve the basic database level customer-managed key settings from a database and all the keys ever added
az sql db show --resource-group $resourceGroupName --server $serverName --name mySampleDatabase --expand-keys
# Retrieve the basic database level customer-managed key settings from a database and the current keys in use
az sql db show --resource-group $resourceGroupName --server $serverName --name mySampleDatabase --expand-keys --keys-filter current
# Retrieve the basic database level customer-managed key settings from a database and the keys in use at a particular point in time
az sql db show --resource-group $resourceGroupName --server $serverName --name mySampleDatabase --expand-keys --keys-filter 01-01-2015
# Retrieve all the databases in a server to check which ones are configured with database level customer-managed keys
az sql db list --resource-group $resourceGroupName --server $serverName
如需 Az PowerShell 模組安裝指示,請參閱安裝 Azure PowerShell。
使用 Get-AzSqlDatabase Cmdlet。
# Retrieve the basic database level customer-managed key settings from a database
Get-AzSqlDatabase -ResourceGroupName <ResourceGroupName> -ServerName <ServerName> -DatabaseName <DatabaseName>
# Retrieve the basic database level customer-managed key settings from a database and all the keys ever added
Get-AzSqlDatabase -ResourceGroupName <ResourceGroupName> -ServerName <ServerName> -DatabaseName <DatabaseName> -ExpandKeyList
# Retrieve the basic database level customer-managed key settings from a database and the current keys in use
Get-AzSqlDatabase -ResourceGroupName <ResourceGroupName> -ServerName <ServerName> -DatabaseName <DatabaseName> -ExpandKeyList -KeysFilter "current"
# Retrieve the basic database level customer-managed key settings from a database and the keys in use at a particular point in time
Get-AzSqlDatabase -ResourceGroupName <ResourceGroupName> -ServerName <ServerName> -DatabaseName <DatabaseName> -ExpandKeyList -KeysFilter '2023-02-03 00:00:00'
# Retrieve all the databases in a server to check which ones are configured with database level customer-managed keys
Get-AzSqlDatabase -resourceGroupName <ResourceGroupName> -ServerName <ServerName> | Select DatabaseName, EncryptionProtector
使用適用於 Azure SQL Database 的 2022-08-01-preview REST API。
從資料庫擷取基本資料庫層級客戶自控的金鑰設定。
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}?api-version=2022-08-01-preview
從資料庫和所有曾新增的金鑰擷取基本資料庫層級客戶自控的金鑰設定
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}?api-version=2022-08-01-preview&$expand=keys
從資料庫和目前正在使用的金鑰擷取基本資料庫層級客戶自控的金鑰設定
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}?api-version=2022-08-01-preview&$expand=keys($filter=pointInTime('current'))
從資料庫和在特定時間點使用的金鑰擷取基本資料庫層級客戶自控的金鑰設定
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}?api-version=2022-08-01-preview&$expand=keys($filter=pointInTime('2023-02-04T01:57:42.49Z'))
列出邏輯伺服器中的所有金鑰
若要擷取所有金鑰的清單 (而不只是伺服器下每個資料庫所使用的主要保護裝置),還必須使用金鑰篩選個別查詢。 以下是 PowerShell 查詢的範例,可列出邏輯伺服器下的每個金鑰。
使用 Get-AzSqlDatabase Cmdlet。
$dbs = Get-AzSqlDatabase -resourceGroupName <ResourceGroupName> -ServerName <ServerName>
foreach ($db in $dbs)
{
Get-AzSqlDatabase -DatabaseName $db.DatabaseName -ServerName $db.ServerName -ResourceGroupName $db.ResourceGroupName -ExpandKeyList
}
在 Azure SQL Database 上重新驗證資料庫層級客戶自控的金鑰
如果 TDE 保護裝置無法存取,如使用 客戶管理金鑰的 Azure SQL 透明資料加密中所述,一旦金鑰存取已更正,就可以使用重新驗證金鑰作業來讓資料庫可存取。 如需範例,請參閱下列指令或命令。
使用 [Azure 入口網站],尋找您的 SQL Database 資源。 選取 SQL Database 資源之後,請前往 [安全性設定] 下 [資料加密] 功能表的 [透明資料加密] 索引標籤。 如果資料庫無法存取 Azure Key Vault,則會出現 [重新驗證金鑰] 按鈕,而且您可以選擇選取 [重試現有金鑰]來重新驗證現有的金鑰,或選取 [選取備份金鑰] 來重新驗證另一個金鑰。
如需如何安裝目前版本的 Azure CLI,請參閱安裝 Azure CLI 一文。
az sql db tde key revalidate --resource-group $resourceGroupName --server $serverName --database mySampleDatabase
使用適用於 Azure SQL Database 的 2022-08-01-preview REST API。
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/encryptionProtector/current/revalidate?api-version=2022-08-01-preview
在 Azure SQL Database 上還原資料庫層級客戶自控的金鑰
如果伺服器是使用下列命令設定服務管理的金鑰,則使用資料庫層級 CMK 設定的資料庫可以還原為伺服器層級加密。
若要將資料庫層級客戶自控金鑰設定還原為 Azure 入口網站中的伺服器層級加密金鑰,請前往 SSQL Database 資源的 [資料加密] 功能表的 [透明資料加密] 索引標籤。 選取 [伺服器層級加密金鑰],然後選取 [儲存] 以儲存設定。
注意
若要使用個別資料庫的伺服器層級加密金鑰設定,Azure SQL 資料庫的邏輯伺服器必須設定為使用適用於 TDE 的服務管理金鑰。
如需如何安裝目前版本的 Azure CLI,請參閱安裝 Azure CLI 一文。
az sql db tde key revert --resource-group $resourceGroupName --server $serverName --name mySampleDatabase
使用適用於 Azure SQL Database 的 2022-08-01-preview REST API。
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/encryptionProtector/current/revert?api-version=2022-08-01-preview
相關內容