使用 Azure CLI,利用安全性群組檢視分析虛擬機器的安全性
注意
安全性群組檢視 API 已不再維護,且即將被取代。 請使用提供相同功能的有效安全性規則功能。
安全性群組檢視會傳回套用至虛擬機器之已設定且有效的網路安全性規則。 這項功能可用來稽核及診斷 VM 所設定的網路安全性群組和規則,以確保會正確允許或拒絕流量。 在本文中,我們會說明如何使用 Azure CLI 來擷取虛擬機器所設定且有效的安全性規則
若要執行本文的步驟,您需要安裝適用於 Windows、Linux 或 macOS 的 Azure CLI。
開始之前
此案例假設您已依照建立網路監看員中的步驟建立網路監看員。
案例
本文涵蓋的案例會擷取指定虛擬機器之已設定且有效的安全性規則。
取得 VM
必須有虛擬機器才能執行 vm list
Cmdlet。 下列命令會列出資源群組中的虛擬機器:
az vm list -resource-group resourceGroupName
一旦您知道虛擬機,您可以使用 vm show
Cmdlet 來取得其資源識別碼:
az vm show -resource-group resourceGroupName -name virtualMachineName
擷取安全性群組檢視
下一步是擷取安全性群組檢視的結果。
az network watcher show-security-group-view --resource-group resourceGroupName --vm vmName
檢視結果
下列範例是所傳回結果的縮短回應。 結果顯示虛擬機器上所有有效且套用的安全性規則,並細分為 NetworkInterfaceSecurityRules、DefaultSecurityRules和 EffectiveSecurityRules 群組。
{
"networkInterfaces": [
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{nicName}",
"resourceGroup": "{resourceGroupName}",
"securityRuleAssociations": {
"defaultSecurityRules": [
{
"access": "Allow",
"description": "Allow inbound traffic from all VMs in VNET",
"destinationAddressPrefix": "VirtualNetwork",
"destinationPortRange": "*",
"direction": "Inbound",
"etag": null,
"id": "/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups//providers/Microsoft.Network/networkSecurityGroups/{nsgName}/defaultSecurityRules/AllowVnetInBound",
"name": "AllowVnetInBound",
"priority": 65000,
"protocol": "*",
"provisioningState": "Succeeded",
"resourceGroup": "",
"sourceAddressPrefix": "VirtualNetwork",
"sourcePortRange": "*"
}...
],
"effectiveSecurityRules": [
{
"access": "Deny",
"destinationAddressPrefix": "*",
"destinationPortRange": "0-65535",
"direction": "Outbound",
"expandedDestinationAddressPrefix": null,
"expandedSourceAddressPrefix": null,
"name": "DefaultOutboundDenyAll",
"priority": 65500,
"protocol": "All",
"sourceAddressPrefix": "*",
"sourcePortRange": "0-65535"
},
{
"access": "Allow",
"destinationAddressPrefix": "VirtualNetwork",
"destinationPortRange": "0-65535",
"direction": "Outbound",
"expandedDestinationAddressPrefix": [
"10.1.0.0/24",
"168.63.129.16/32"
],
"expandedSourceAddressPrefix": [
"10.1.0.0/24",
"168.63.129.16/32"
],
"name": "DefaultRule_AllowVnetOutBound",
"priority": 65000,
"protocol": "All",
"sourceAddressPrefix": "VirtualNetwork",
"sourcePortRange": "0-65535"
},...
],
"networkInterfaceAssociation": {
"id": "/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{nicName}",
"resourceGroup": "{resourceGroupName}",
"securityRules": [
{
"access": "Allow",
"description": null,
"destinationAddressPrefix": "*",
"destinationPortRange": "3389",
"direction": "Inbound",
"etag": "W/\"efb606c1-2d54-475a-ab20-da3f80393577\"",
"id": "/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{nsgName}/securityRules/default-allow-rdp",
"name": "default-allow-rdp",
"priority": 1000,
"protocol": "TCP",
"provisioningState": "Succeeded",
"resourceGroup": "{resourceGroupName}",
"sourceAddressPrefix": "*",
"sourcePortRange": "*"
}
]
},
"subnetAssociation": null
}
}
]
}
下一步
請瀏覽使用網路監看員稽核網路安全性群組 (NSG) 以了解如何自動驗證網路安全性群組。
請瀏覽安全性群組檢視概觀以深入了解套用到網路資源的安全性規則