[BUG] cidrHost/cidrSubnet fail during Bicep expansion when address prefixes are assigned outside the template
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #3908 @oWretch による — マージ済み
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- azure, powershell
- 領域
- tooling
調査の方向性
GetBicepParamResources から開始し、参照されたリソースを解決できない場合に使用される汎用 mock レイヤーを追跡します。2 つの cidrHost/cidrSubnet の失敗を再現し、その後、型付きプレースホルダーによって一覧にあるアドレスプロパティの展開が維持されることを確認します。一方で、無関係な未指定プロパティと厳密な CIDR 検証は現在の動作を維持します。
索引モデルが issue の本文から書いたものです。
説明
Existing rule
N/A — this affects Bicep expansion rather than a specific rule.
Description of the issue
When a virtual network, subnet, or IPAM pool gets its address prefixes assigned outside the template being analyzed, the properties.addressPrefixes value cannot be resolved during expansion. PSRule for Azure creates a generic mock for the unresolved reference, and unknown string properties on that mock resolve to an empty string.
The cidr*() functions validate their input strictly, so any expression that consumes such a value fails expansion of the whole deployment:
The specified CIDR '' is not valid.
This is increasingly common with Azure Virtual Network Manager IPAM. The prefixes are allocated by IPAM at deploy time via ipamPoolPrefixAllocations, so they are genuinely not knowable from the source. Anything derived from them with cidrHost() or cidrSubnet() — a static private frontend IP for an Application Gateway is the typical case — cannot be analyzed at all today.
The generic mock already knows the resource type of the reference. That is enough to supply a well-formed placeholder for a small set of well-known address properties, so expansion can continue instead of failing outright.
Two related gaps make this worse than it first appears:
- Existing (
existing = {}) resources are registered as deployment symbols but are not added to the resource ID lookup, soreference('vnet::subnet')can fall back to a mock built from the bare symbolic name and lose the resource type entirely. - When a resource declares a partial
propertiesobject (for example a subnet that setsipamPoolPrefixAllocationsbut notaddressPrefixes), the properties are wrapped in a plain mock object. Resource type context is lost, so missing sibling properties cannot be inferred even when the type is known.
Importantly, a fix here should not relax the cidr*() functions themselves. Keeping them strict is what still catches genuine authoring mistakes such as passing id instead of an address prefix, or passing addressPrefixes without indexing it.
Error messages
Failed to expand bicep source 'deploy.bicepparam'. Exception calling "GetBicepParamResources" with "2" argument(s):
"Unable to expand resources because the source file 'deploy.bicepparam' was not valid.
The deployment 'root/example' with symbolic name 'example' failed.
An error occurred evaluating expression '[cidrHost(reference('vnet::subnet').addressPrefixes[0], 3)]'
at path 'properties.frontendIPConfigurations[1].properties.privateIPAddress'.
The function 'cidrHost' failed. The specified CIDR '' is not valid."
An error occurred evaluating expression '[cidrSubnet(reference('networkManager::platformPool').addressPrefixes[0], 23, 0)]'.
The function 'cidrSubnet' failed. The specified CIDR '' is not valid."
Reproduction
Both cases below fail expansion.
Case 1 — subnet address prefix allocated by IPAM
targetScope = 'resourceGroup'
resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' existing = {
name: 'vnet-example'
resource subnet 'subnets' = {
name: 'ApplicationGatewaySubnet'
properties: {
ipamPoolPrefixAllocations: [
{
numberOfIpAddresses: '256'
pool: { id: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-example/providers/Microsoft.Network/networkManagers/vnm-example/ipamPools/pool-example' }
}
]
defaultOutboundAccess: true
}
}
}
// Fails: The specified CIDR '' is not valid.
output privateFrontendIP string = cidrHost(vnet::subnet.properties.addressPrefixes[0], 3)
Case 2 — IPAM pool address prefix
targetScope = 'resourceGroup'
resource networkManager 'Microsoft.Network/networkManagers@2024-05-01' existing = {
name: 'vnm-example'
resource platformPool 'ipamPools' existing = {
name: 'pool-example'
}
}
// Fails: The specified CIDR '' is not valid.
output reservation string = cidrSubnet(networkManager::platformPool.properties.addressPrefixes[0], 23, 0)
The same failure occurs for a virtual network whose properties.addressSpace.addressPrefixes is IPAM-allocated.
Version of PSRule
2.9.0
Version of PSRule for Azure
1.48.0-B0231
Additional context
A targeted fix would be to give the existing mock layer source awareness: a small table mapping resource type plus normalized property path to a typed placeholder, so only well-known address properties return a valid placeholder CIDR and everything else keeps today's behaviour.
Using the reserved documentation range from RFC 5737 (192.0.2.0/24) makes placeholders obvious in output and avoids colliding with plausible customer address space.
The minimal set that unblocks the IPAM scenarios:
Microsoft.Network/virtualNetworks→properties.addressSpace.addressPrefixes[]Microsoft.Network/virtualNetworks/subnets→properties.addressPrefixMicrosoft.Network/virtualNetworks/subnets→properties.addressPrefixes[]Microsoft.Network/networkManagers/ipamPools→properties.addressPrefixes[]
A table-driven approach keeps this easy to extend later to other resources that expose address-like outputs (network interfaces, public IPs, firewalls, DNS resolver inbound endpoints) without reworking the mock layer, and without requiring full ARM property schemas.
I have a working implementation of this and will follow up with a PR.
- 主要言語
- PowerShell
- スター
- 449
- フォーク
- 108
- 平均マージ
- 1日 6時間
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Azure/PSRule.Rules.Azure のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Azure/PSRule.Rules.Azure#3959 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Azure/PSRule.Rules.Azure#3958 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] Azure.AppService.PlanInstanceCount incorrectly applies to Flex Consumption (FC1) plans対応中かも @bwateratmsft が 30 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Azure/PSRule.Rules.Azure#3929 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Export-AzRuleData fails with HTTP 400 for DefenderForStorageSettings due to deprecated API version対応中かも @saryn17 が 37 日前に担当しました。 オープンbug feature: in-flight-export
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
Azure/PSRule.Rules.Azure#3865 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[FEATURE] Behaviour documentation for PR #3908対応中かも @ElinoraWhite が 13 日前に担当しました。 オープンdocumentation
Azure/PSRule.Rules.Azure#3944 · リアクション 1 件 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
Azure/PSRule.Rules.Azure の issue をすべて見る
似ている issue
-
untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
dotnet/install-scripts#746 · リアクション 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
fullsend-ai/agents#1786 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
plugin install: the confirmation hint names 'agmsg' even for an install with another --cmd nameオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
curriculum documentation quality
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
githubnext/gh-aw-workshop#5001 ·
メンテナーはふだん 1 日以内に返信