Resolve and validate aliases offline against a bundled snapshot¶
Context and Problem Statement¶
Authors write short field names such as publicNetworkAccess. Azure Policy needs full aliases such as Microsoft.Storage/storageAccounts/publicNetworkAccess. A misspelled alias is not rejected when the policy is created. It just never matches, so the policy is silently ineffective. How does Bylaw resolve and validate alias names without depending on Azure while compiling?
Decision Drivers¶
- Compiling must work offline and in CI without credentials (ADR-0007).
- Unknown or misspelled aliases must fail the build.
- The full alias set is large, so loading it must not make every build slow.
- The installed module folder may be read-only, and it is replaced on every module update.
Considered Options¶
- A bundled snapshot plus an optional refreshed cache, with lookup-based resolution
- A live lookup through Az at compile time
- No validation: concatenate
<type>/<name>
Decision Outcome¶
Chosen option: "A bundled snapshot plus an optional refreshed cache, with lookup-based resolution".
Snapshot format¶
{
"schemaVersion": 1,
"generatedAt": "2026-11-25T00:00:00Z",
"types": {
"Microsoft.Storage/storageAccounts": {
"aliases": {
"Microsoft.Storage/storageAccounts/publicNetworkAccess": { "modifiable": true, "type": "String" },
"Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]": { "type": "Array" },
"Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value": { "type": "String" }
}
}
}
}
- Whether an alias is an array is derived from
[*]in its name. Only facts that can't be derived are stored, and both are optional: modifiable, whichModifyneeds (ADR-0024).type, the property's data type as Azure reports it (DefaultMetadata.Type). It is omitted when Azure saysNotSpecified. Comparing mismatched types is a runtimeErrorin Azure (ADR-0004), so a later validation rule can use this to catch, for example, a numeric comparison against aStringproperty at compile time.- The snapshot is written with the canonical writer (ADR-0009), with types and aliases sorted by ordinal comparison, so refreshing it gives minimal diffs.
- It is read with
System.Text.Json, notConvertFrom-Json, which would turngeneratedAtinto aDateTime. - The loader parses the file once per runspace, and indexes only the resource types the build references.
- The bundled
src/Data/aliases.jsoncurrently holds only the types the tests and examples use (storage accounts, virtual machines and their extensions, network security groups, key vaults, and diagnostic settings). The maintainers will generate the full snapshot.
Where the snapshot is loaded from (first match wins)¶
Build-Bylaw -AliasCachePathaliasCacheinbylaw.json(ADR-0012), relative to that file- The user cache, at
$HOME/.bylaw/aliases.json - The bundled
src/Data/aliases.json, which is read-only and ships with the module
Update-BylawAliasCache calls Get-AzPolicyAlias, which needs a signed-in Az context. It writes to the user cache by default, or to -OutputPath. It never writes into the module folder. The full bundled snapshot is generated by the maintainers using the same command. Until 2026-11-29 the bundled file held only the 6 types the tests and examples needed; since then it holds every type (1,531 then, 9.2 MB), so real policies build without a refresh or -AllowUnknownAlias. It has no tenant data. Loading it adds about 2.5 seconds to a 21-file build. Converting the Azure Landing Zones Library with it, policies needing Condition fell from 21 to 11 (ADR-0042).
Resolution rules, in order¶
- Reserved fields pass through unchanged and are not aliases:
name,fullName,kind,type,location,id,identity.type,identity.userAssignedIdentities,extendedLocation,extendedLocation.name,extendedLocation.type,tags,tags['<name>']andtags.<name>. - Full alias (the name contains
/): checked against the snapshot, ignoring case. - Short name under
Resource '<type>': an exact match on<type>/<name>, ignoring case. Otherwise, a unique match among that type's aliases whose name ends in/<name>. Not every alias is prefixed with its full type path, for exampleMicrosoft.Compute/imagePublisherunderMicrosoft.Compute/virtualMachines, so this is a lookup, not string concatenation. More than one match is an error that lists the candidates. - Inside
Each <array>[*]:Field xresolves to<array alias>[*].x, andElementrefers to the element itself (<array alias>[*]), for arrays of plain values. Resource *: there is no type context, so only reserved fields and full aliases are allowed.[*]outsideEachis a compile error. Azure evaluates a[*]field condition as "every element satisfies it", and as true for an empty array, so negating it by swapping the operator would be wrong. See ADR-0002.
Casing¶
Azure ignores case in resource types and aliases, but its alias data doesn't spell them consistently. For example, the type microsoft.insights/diagnosticSettings has Microsoft.Insights/diagnosticSettings/logs[*].enabled next to microsoft.insights/diagnosticSettings/logs[*].categoryGroup. Copying the snapshot would mix spellings within one policy, so:
- A resource type (
Resource, or the-TypeofAuditIfNotExistsandDeployIfNotExists) is emitted as written. - The type segments of a resolved alias are spelled as the author wrote the type: the type in
Resourceor-Typefor a short name, the array's alias insideEach, or the alias itself when it is written in full. This applies for as long as the segments match, soMicrosoft.Compute/imagePublishertakes only the namespace fromMicrosoft.Compute/virtualMachines. - The property path after the type segments is emitted as the snapshot spells it.
Unknown aliases¶
- An unknown alias is a compile error. The message includes the closest matches from the snapshot.
Field x -AllowUnknownAliasallows it for one field. A short name is then built as<type>/<name>.Build-Bylaw -AllowUnknownAliasallows it for the whole build. Each use is still reported as a warning.
Consequences¶
- Good, because compiling is offline and deterministic, and typos fail the build.
- Good, because a refreshed cache never needs write access to the module folder.
- Bad, because the bundled snapshot goes stale between releases. Users who need new aliases run
Update-BylawAliasCache.
Confirmation¶
Unit tests cover each resolution rule, each error, the order in which snapshot locations are tried, and stable output from a refresh (with Az mocked).