Azure Resource Graph: Network Inventoryを理解するための前提
Azure Resource GraphはAzure Resource Manager resource type/propertyを横断queryするためのinventory planeで、network topology/incident scope確認に有効。 Microsoft LearnにはNICのipConfigurationsからVNet/Subnetを抽出するnetworking sample queryが公開されている。
subscription横断でtype/countを可視化すると、manual spreadsheetよりdrift・orphan・resource sprawlを検出しやすい。 Resource Graphのinventory結果はpacket forwardingそのものを証明しない。effective routes/NSG、Network Watcher、logsと組み合わせる。
query結果をevidenceとして保存する場合はquery text・subscription scope・実行時刻もセットで記録する。
Control plane と Data plane
仕組みと設計上の意味
Resource Graphは「Azureに何があるか」を高速に尋ねるcontrol-plane inventoryです。個々のresource bladeを巡回する代わりに、resource type・location・tags・propertiesをKQLで横断できます。ネットワークでは、NICからsubnet/VNetへの関連、孤立NSG、Public IPの割り当て、VNet/peering数などを定型query化しておくと、incident初動と定期監査の両方に使えます。
ただし、Resource Graphの線やpropertiesだけでdata plane successを断定してはいけません。UDRがassociationされていることと、そのflowで選ばれたeffective routeは別です。NSG resourceが存在することと、その5-tupleがallowされることも別です。
Operational / decision path
対象scopeと時刻を固定し、read-only evidence → 判断 → change → same testで再検証の順を崩さない。
- incidentまたはreview対象のsubscription setを固定する。
- まずMicrosoft.Network resource typeのcountを取り、estate sizeと想定外typeを把握する。
- 対象flowに関係するNIC/VNet/Subnet/NSG/route table/private endpoint等をqueryで絞る。
- resource IDをキーとしてPortal/CLIのeffective stateへdrill downする。
- queryと結果をsnapshot保存し、change後に同じqueryでdiffを取る。
設計判断
| 判断点 | 推奨 | 理由 |
|---|---|---|
| Query library | 目的別にsmall queryをversion control | 巨大な万能queryより検証・再利用しやすい |
| Scope | subscription listを明示 | 見えていないsubscriptionを「resourceなし」と誤認しない |
| Join key | nameではなくresource IDを優先 | 同名resource/別RG/別subscriptionを混同しない |
| Runtime proof | ARGの後にeffective state/testへ進む | inventoryとpacket behaviorを分離 |
確認手順
Azure Portal
- Azure portal → Resource Graph Explorerでqueryを実行し、scopeを確認。
- 結果のresource IDから対象resource bladeへdrill down。
- Chartsはoverview用途、incident evidenceはtable/CSVとquery textを保存。
Evidence contract
Read-only first: 以下のCLI/PowerShellは原則として参照系から開始します。コメントでMUTATINGと示した操作は、必要性・scope・rollbackを確認した後にのみ実行します。
# network resource count by type
az graph query -q "Resources | where type startswith 'microsoft.network/' | summarize count() by type | order by count_ desc" -o table
# NIC -> VNet/Subnet (Microsoft Learn sample pattern)
az graph query -q "Resources | where type =~ 'microsoft.network/networkinterfaces' | project id, ipConfigurations = properties.ipConfigurations | mvexpand ipConfigurations | project id, subnetId = tostring(ipConfigurations.properties.subnet.id) | parse kind=regex subnetId with '/virtualNetworks/' virtualNetwork '/subnets/' subnet | project id, virtualNetwork, subnet" -o table
# orphan NSG candidates
az graph query -q "Resources | where type =~ 'microsoft.network/networksecuritygroups' and isnull(properties.networkInterfaces) and isnull(properties.subnets) | project name, resourceGroup, subscriptionId, id | sort by name asc" -o tableSearch-AzGraph -Query "Resources | where type startswith 'microsoft.network/' | summarize count() by type | order by count_ desc"
Search-AzGraph -Query "Resources | where type =~ 'microsoft.network/networksecuritygroups' and isnull(properties.networkInterfaces) and isnull(properties.subnets) | project name, resourceGroup, subscriptionId, id | sort by name asc"
障害切り分け
| 症状 | 疑う点 | 証拠 | 次の確認 |
|---|---|---|---|
| query結果が0件 | scope/permission/type文字列 | subscription context + query | Reader以上のread scopeとtype caseを確認 |
| PortalにはあるがARGに見えない | index反映/tenant-subscription scope | resource ID direct GET | ARGだけで削除済みと断定しない |
| associationは見えるが通信不可 | inventoryをruntime proofと誤認 | effective route/NSG/connection test | data plane evidenceへ降りる |
| queryが壊れた | property shape/API evolution | sample query + raw properties | tostring/isnull等でdefensive queryにする |
変更・rollback
- Resource Graph query自体はread-onlyだが、結果を基にbulk delete/updateへ直結させない。candidate→review→changeの段階を分ける。
- before/after queryは同じscope・query textで実行し、drift比較を可能にする。
- orphan判定はassociation propertyだけでなく、IaC・Policy・future deployment dependencyを確認してから削除する。
- rollbackに必要なresource definitionをIaC/exportで確保してからcleanupを実施する。