訓練
認證
Microsoft Certified: Information Protection and Compliance Administrator Associate - Certifications
示範資料安全性、生命週期管理、資訊安全性和合規性的基本知識,以保護 Microsoft 365 部署。
了解 Azure 中合規性的第一個步驟是識別您資源的狀態。 在本快速入門中,您將使用 Azure CLI 來建立一個原則指派,以識別不符合規範的資源。 此原則會指派給資源群組,而它會稽核不使用受控磁碟的虛擬機器。 建立原則指派之後,您將識別不符合規範的虛擬機器。
Azure CLI 可用來從命令列或在指令碼中建立和管理 Azure 資源。 本指南使用 Azure CLI 來建立原則指派,以及識別 Azure 環境中不符合規範的資源。
指派內建原則或計畫定義時,您可以選擇參考版本。 除非另有指定,否則內建定義的原則指派會預設為最新版本,並自動繼承次要版本變更。
Microsoft.PolicyInsights
必須在您的 Azure 訂用帳戶中進行註冊。 若要註冊資源提供者,您必須有權註冊資源提供者。 該權限包括在參與者和擁有者角色中。從 Visual Studio Code 終端機工作階段中連線到 Azure。 如果您有多個訂用帳戶,請執行命令來設定您訂用帳戶的內容。 使用您的 Azure 訂用帳戶識別碼來取代 <subscriptionID>
。
az login
# Run these commands if you have multiple subscriptions
az account list --output table
az account set --subscription <subscriptionID>
註冊資源提供者後,即可在您的 Azure 訂用帳戶中使用它。
若要驗證 Microsoft.PolicyInsights
是否已註冊,請執行 Get-AzResourceProvider
。 資源提供者包含數個資源類型。 如果結果是 NotRegistered
,請執行 Register-AzResourceProvider
:
az provider show \
--namespace Microsoft.PolicyInsights \
--query "{Provider:namespace,State:registrationState}" \
--output table
az provider register --namespace Microsoft.PolicyInsights
Azure CLI 命令使用反斜線 (\
) 來進行續行以提高可讀性。 如需詳細資訊,請移至 az provider。
使用下列命令來為您的資源群組建立新的原則指派。 此範例使用一個包含不含受控磁碟的虛擬機器的現有資源群組。 資源群組是原則指派的範圍。 此範例使用內建原則定義:稽核不是使用受控磁碟的 VM。
執行下列命令,並將 <resourceGroupName>
取代為您的資源群組名稱:
rgid=$(az group show --resource-group <resourceGroupName> --query id --output tsv)
definition=$(az policy definition list \
--query "[?displayName=='Audit VMs that do not use managed disks']".name \
--output tsv)
rgid
變數會儲存資源群組識別碼。 definition
變數會儲存原則定義的名稱,也就是 GUID。
執行下列命令以建立原則指派:
az policy assignment create \
--name 'audit-vm-managed-disks' \
--display-name 'Audit VM managed disks' \
--scope $rgid \
--policy $definition \
--description 'Azure CLI policy assignment to resource group'
name
會建立指派的 ResourceId
中所使用的原則指派名稱。display-name
是原則指派的名稱,且會顯示在 Azure 入口網站中。scope
會使用 $rgid
變數來將原則指派給資源群組。policy
會指派儲存在 $definition
變數中的原則定義。description
可用來新增原則指派的相關內容。原則指派的結果類似下列範例:
"description": "Azure CLI policy assignment to resource group",
"displayName": "Audit VM managed disks",
"enforcementMode": "Default",
"id": "/subscriptions/{subscriptionID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments/audit-vm-managed-disks",
"identity": null,
"location": null,
"metadata": {
"createdBy": "11111111-1111-1111-1111-111111111111",
"createdOn": "2024-02-23T18:42:27.4780803Z",
"updatedBy": null,
"updatedOn": null
},
"name": "audit-vm-managed-disks",
如果您想要重新顯示原則指派資訊,請執行下列命令:
az policy assignment show --name "audit-vm-managed-disks" --scope $rgid
如需詳細資訊,請移至 az policy assignment。
新原則指派的合規性狀態需要幾分鐘的時間才會生效,而且其會提供原則狀態的相關結果。
使用下列命令來識別不符合您所建立之原則指派規範的資源:
policyid=$(az policy assignment show \
--name "audit-vm-managed-disks" \
--scope $rgid \
--query id \
--output tsv)
az policy state list --resource $policyid --filter "(isCompliant eq false)"
policyid
變數會使用運算式來取得原則指派的識別碼。 filter
參數會將輸出限制為不符合規範的資源。
az policy state list
輸出是詳細資訊,但在本文中,complianceState
會顯示 NonCompliant
:
"complianceState": "NonCompliant",
"components": null,
"effectiveParameters": "",
"isCompliant": false,
如需詳細資訊,請移至 az policy state。
若要移除原則指派,請執行下列命令:
az policy assignment delete --name "audit-vm-managed-disks" --scope $rgid
若要登出您的 Azure CLI 工作階段:
az logout
在這個快速入門中,您指派原則定義以識別 Azure 環境中的不相容資源。
若要深入了解如何指派驗證資源合規性的原則,請繼續進行教學課程。
訓練
認證
Microsoft Certified: Information Protection and Compliance Administrator Associate - Certifications
示範資料安全性、生命週期管理、資訊安全性和合規性的基本知識,以保護 Microsoft 365 部署。