NSG Diagnosticsを理解するための前提
NSG Diagnosticsはsource/destination条件をsimulated flowとして評価し、Allow/Denyと根拠ruleを返す。 targetとしてVM、NIC、VMSS NIC、Application Gateway v2(一部制約あり)をsupportする。
NSG ruleはpriority numberが小さい順に評価され、matching ruleがdecisionを決める。 subnet NSGとNIC NSGが併用される場合は両方のeffective effectを確認する。
NSG Diagnosticsはapplication listener/host firewall/NVA等を証明しない。 security admin rule等AVNM controlが関与する環境では対象toolがどこまで評価するかcurrent docsを確認する。
Control plane と data plane
仕組みと設計上の意味
「portが開いているはず」をrule textで判断せず、actual source/destination IP/protocol/portで診断する。
stateful existing flowとnew connectionは挙動が違う可能性があるためchange validationはnew flowで実施。
effective NSG outputとNSG Diagnostics resultが違う時はresource selection/ASG/IPを再確認。
denyがNSGでなければroute、Firewall/NVA、host、applicationへ進む。
Packet / decision path
source→destinationを1本のflowとして固定し、名前解決・routing・security・NAT/service processing・return pathを必要な範囲で順に確認する。
- target resourceとNIC/subnetを特定。
- 5-tupleを固定。
- NSG Diagnostics/IP Flow Verifyを実行。
- effective NSGとmatching ruleを確認。
- allowなら次にroute/application layerを確認。
設計判断
| 判断点 | 推奨 | 理由 |
|---|---|---|
| Quick rule reason | NSG Diagnostics | matching ruleを可視化 |
| NIC-wide review | Effective NSG | 全effective rule inventory |
| Actual connectivity | Connection troubleshoot/app test | NSG外layerも含む |
| Historical pattern | VNet flow logs | intermittent flowを分析 |
確認手順
Azure Portal
- Network Watcher → NSG diagnosticsでtarget/direction/protocol/IP/portを指定。
- 結果のsecurity rule名/priority/actionを確認。
- NIC → Effective security rulesでsubnet/NIC ruleを照合。
Evidence contract
az network watcher run-configuration-diagnostic --resource <resource-id> --resource-group <rg> --direction Outbound --protocol TCP --destination <dst-ip> --port <port>
az network nic list-effective-nsg -g <rg> -n <nic> -o jsonc
az network watcher test-ip-flow -g <rg> --vm <vm> --direction Outbound --protocol TCP --local <src:port> --remote <dst:port>
障害切り分け
| 症状 | 疑う点 | 証拠 | 次の確認 |
|---|---|---|---|
| Deny ruleが想定外 | priority/ASG/source IP誤認 | diagnostic result | rule scope修正 |
| Allowなのに接続不可 | route/host/app/NVA | next hop/connection test | 次layerへ |
| VMSS一部だけ差 | NIC/subnet association drift | instance NIC effective NSG | config統一 |
| change直後だけ旧挙動 | existing flow state | new connection test | stateful behavior考慮 |
変更・rollback
- rule変更前にmatching diagnostic resultを保存。
- Allow追加はsource/dest/serviceを最小化しexpiry/ownerを付ける。
- rollbackはrule priorityとASG membershipも元に戻す。
- 変更後はexpected allowとexpected denyの両方を再試験。