Skip to content

feat(azure-policy): add alias normalization and denormalization#635

Merged
anakrish merged 2 commits intomicrosoft:mainfrom
anakrish:normalizer
Mar 30, 2026
Merged

feat(azure-policy): add alias normalization and denormalization#635
anakrish merged 2 commits intomicrosoft:mainfrom
anakrish:normalizer

Conversation

@anakrish
Copy link
Copy Markdown
Collaborator

@anakrish anakrish commented Mar 27, 2026

Azure Policy Alias Normalization

Summary

Adds a normalizer and denormalizer for ARM resource JSON, bridging the
gap between Azure's ARM resource representation and the flat structure
that Azure Policy rules evaluate against.

After normalization, every known alias short name is a direct path into
the resource object — the compiler and VM never need to know about
aliases.

What it does

Normalizer (ARM JSON → flat input.resource)

  • Flattens root-level properties into the resource root
  • Recursively flattens sub-resource array element properties (e.g.,
    NSG securityRules[*].properties.protocolsecurityRules[*].protocol)
  • Lowercases all object keys for case-insensitive matching
  • Resolves per-alias versioned ARM paths (API-version-aware)
  • Remaps element-level fields when versioned paths rename array leaves
  • Renames array bases when alias and ARM names differ
  • Handles collision-safe keys (_p_type) when alias names shadow root
    ARM fields
  • Supports both control-plane and data-plane (.Data/) resource types

Denormalizer (flat input.resource → ARM JSON)

  • Reverses all normalizer transformations
  • Restores key casing from alias catalog metadata
  • Re-wraps sub-resource arrays with properties envelopes
  • Supports versioned path selection for correct ARM structure

AliasRegistry

  • Loads production alias catalogs (Get-AzPolicyAlias format)
  • Loads data-plane manifests (DataPolicyManifest format)
  • Derives sub-resource arrays from alias path patterns
  • Provides normalize_and_wrap / denormalize convenience API

Files

Area Files
Core library src/languages/azure_policy/aliases/ (normalizer, denormalizer, types, obj_map, registry)
FFI bindings bindings/ffi/src/alias_registry.rs
C# bindings bindings/csharp/Regorus/AliasRegistry.cs, tests
Test suite 13 YAML test files under tests/azure_policy/normalization/cases/
Benchmarks benches/normalization_benchmark.rs
Test data tests/azure_policy/aliases/ (alias catalogs)

Testing

  • 466 lib tests, 162 integration tests (all pass)
  • YAML-driven test cases cover: basic normalize/denormalize, round-trip,
    reverse round-trip, sub-resources, data-plane, edge cases, malformed
    input, versioned aliases, registry API, and envelope pipeline
  • Clippy clean (-Dwarnings)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Azure Policy “alias” support to Regorus by introducing an alias registry plus normalization/denormalization logic (control-plane and data-plane), along with extensive YAML-driven test coverage, documentation, benchmarks, and FFI/C# bindings to expose the registry to consumers.

Changes:

  • Introduce languages::azure_policy::aliases (types, registry, normalizer, denormalizer) and expose it behind the azure_policy feature.
  • Add YAML-driven normalization/denormalization/round-trip tests and supporting alias catalogs/manifests.
  • Add FFI + C# wrapper API for AliasRegistry, plus a Criterion benchmark and dependency updates (incl. lockfiles).

Reviewed changes

Copilot reviewed 44 out of 50 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/mod.rs Conditionally enables Azure Policy test module under azure_policy feature.
tests/azure_policy/mod.rs Azure Policy test root module.
tests/azure_policy/normalization/mod.rs YAML-driven normalization/denormalization/envelope test runner.
tests/azure_policy/normalization/cases/round_trip.yaml Round-trip normalization/denormalization scenarios (incl. versioned remap regression).
tests/azure_policy/normalization/cases/registry_api.yaml Exercises public AliasRegistry APIs (normalize/denormalize/normalize_and_wrap).
tests/azure_policy/normalization/cases/normalize_sub_resources.yaml Sub-resource array flattening test cases.
tests/azure_policy/normalization/cases/normalize_envelope.yaml Envelope construction expectations.
tests/azure_policy/normalization/cases/normalize_basic.yaml Basic normalization behaviors (flatten properties, root precedence, etc.).
tests/azure_policy/normalization/cases/malformed_input.yaml Pins behavior for malformed/unexpected inputs.
tests/azure_policy/normalization/cases/envelope_pipeline.yaml End-to-end normalize+wrap pipeline case.
tests/azure_policy/normalization/cases/edge_cases.yaml Edge-case behavior pinning for ambiguous/malformed inputs.
tests/azure_policy/normalization/cases/denormalize_basic.yaml Basic denormalization behaviors.
tests/azure_policy/normalization/cases/denormalize_aliases.yaml Denormalization with alias-based casing restoration + arrays.
tests/azure_policy/normalization/cases/data_plane_manifest.yaml Data-plane manifest loading + normalization coverage.
tests/azure_policy/normalization/cases/data_plane_breadth.yaml Broader data-plane shape coverage across namespaces.
tests/azure_policy/normalization/cases/data_plane_advanced.yaml Advanced data-plane shapes (top-level aliases, schemaVersions, arrays).
tests/azure_policy/aliases/versioned_aliases.json Versioned alias catalog fixture for tests.
src/lib.rs Exposes languages::azure_policy behind feature flag.
src/languages/mod.rs Adds azure_policy to languages module file (currently unused by crate wiring).
src/languages/azure_policy/mod.rs Defines Azure Policy language module + clippy allowances; exports aliases.
src/languages/azure_policy/aliases/types.rs Alias/manifest schema types + resolved/precomputed structures.
src/languages/azure_policy/aliases/obj_map.rs Internal hash map utilities + nested set helpers + ROOT_FIELDS.
src/languages/azure_policy/aliases/normalizer/mod.rs Normalizer entry points + envelope builder.
src/languages/azure_policy/aliases/normalizer/flatten.rs Recursive normalization helpers + sub-resource flattening.
src/languages/azure_policy/aliases/normalizer/element_remap.rs Array element-level remap logic used for versioned wildcard aliases.
src/languages/azure_policy/aliases/normalizer/alias_resolution.rs Applies alias resolution + precomputed aggregates to normalized output.
src/languages/azure_policy/aliases/denormalizer/mod.rs Denormalization pipeline back to ARM JSON + aggregates application.
src/languages/azure_policy/aliases/denormalizer/helpers.rs CI key lookup + element field removal utilities.
src/languages/azure_policy/aliases/denormalizer/sub_resource.rs Rewraps sub-resource array elements back under properties.
src/languages/azure_policy/aliases/denormalizer/casing.rs Restores key casing using alias metadata-derived map.
src/languages/azure_policy/aliases/denormalizer/tests.rs Inline unit tests for denormalizer helpers/casing.
docs/azure-policy/aliases.md Design discussion and rationale for alias approach.
docs/azure-policy/alias-normalization.md Detailed normalization spec and end-to-end flow documentation.
check_aliases.py Helper script to validate presence of needed aliases in fixtures.
benches/normalization_benchmark.rs Criterion benchmark suite for normalization/denormalization performance.
Cargo.toml Adds hashbrown dependency and new normalization_benchmark bench target.
Cargo.lock Lockfile updates from new dependency graph.
bindings/ffi/src/lib.rs Wires in new FFI module.
bindings/ffi/src/common.rs Derives Debug/PartialEq for RegorusStatus (used in tests/interop).
bindings/ffi/src/alias_registry.rs Adds FFI surface for AliasRegistry load/query/normalize/denormalize.
bindings/ffi/Cargo.lock Lockfile updates from new dependency graph.
bindings/csharp/Regorus/SafeHandles.cs Adds SafeHandle for alias registry native handle.
bindings/csharp/Regorus/NativeMethods.cs Adds P/Invoke declarations for alias registry functions + struct.
bindings/csharp/Regorus/AliasRegistry.cs Adds managed AliasRegistry wrapper API.
bindings/csharp/Regorus.Tests/AliasRegistryTests.cs Adds managed tests covering alias registry API behavior.
bindings/java/Cargo.lock Lockfile updates (hashbrown/foldhash).
bindings/python/Cargo.lock Lockfile updates (hashbrown/foldhash).
bindings/wasm/Cargo.lock Lockfile updates (hashbrown/foldhash).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 44 out of 50 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anakrish anakrish force-pushed the normalizer branch 2 times, most recently from 788f861 to 2efd79d Compare March 27, 2026 16:33
@anakrish anakrish requested a review from Copilot March 27, 2026 16:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 45 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 45 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 44 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anakrish anakrish requested a review from Copilot March 30, 2026 15:15
@anakrish anakrish changed the title Normalizer feat(azure-policy): add alias normalization and denormalization Mar 30, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add normalizer and denormalizer for ARM JSON resources, enabling Azure
Policy alias short names to become direct paths into a flat structure.

- Normalizer: flattens properties wrappers, lowercases keys, resolves
  per-alias versioned ARM paths, handles sub-resource array flattening,
  element-level field remaps, and array base renames
- Denormalizer: reverses all transformations with casing restoration
- AliasRegistry: loads production alias catalogs and data policy manifests
- Types: serde deserialization for ARM provider alias formats
- YAML test suite: 13 test files covering normalize, denormalize, round-trip,
  data-plane, edge cases, malformed input, sub-resources, and registry API
- Benchmark suite for normalization performance
- FFI: alias_registry.rs with C-compatible API for loading catalogs,
  normalizing resources, and denormalizing back to ARM JSON
- C#: AliasRegistry wrapper class with NativeMethods P/Invoke bindings
  and integration tests
- Updated Cargo.lock files for new serde_json dependency
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 46 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anakrish anakrish marked this pull request as ready for review March 30, 2026 16:52
@anakrish anakrish merged commit d36f952 into microsoft:main Mar 30, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants