Skip to content

feat(policy): add Azure.Policy.AssignmentMessage rule - #3992

Open
Ming (MaxonT) wants to merge 2 commits into
Azure:mainfrom
MaxonT:contrib/727-auto
Open

Ming (MaxonT) wants to merge 2 commits into
Azure:mainfrom
MaxonT:contrib/727-auto

Conversation

@MaxonT

Copy link
Copy Markdown

Hello, policy assignments in Azure can carry a non-compliance message, so this PR adds a rule that flags assignments missing one, as #727 describes.

Fixes #727

Thanks for writing up the rule request; the description of what the message is for was enough to scope it.

This adds Azure.Policy.AssignmentMessage (AZR-000546, Operational Excellence) for Microsoft.Authorization/policyAssignments. It passes when properties.nonComplianceMessages has at least one entry with a non-blank message and no policyDefinitionReferenceId, which is the default message the issue asks for. A message that only targets one policy inside an initiative does not count, since it does not cover the assignment as a whole.

Changes: the rule in Azure.Policy.Rule.ps1, rule docs, a changelog line, and a Pester test in Azure.Policy.Tests.ps1. For the fixture I gave assignment-001 in Resources.Policy.json a single message that has a policyDefinitionReferenceId, so it fails the rule; assignment-002 already had a default message and passes.

Two choices I would like you to check: the ruleSet is 2026_09, copied from the newest merged rules (Azure.Fleet.SecureBoot), and the ref is AZR-000546, the next one after AZR-000545 on main; I did not see an open PR that takes it. The rule docs have a template example only, like the sibling Azure.Policy.AssignmentDescriptors.

How I checked: ran Invoke-Build TestModule -TestGroup Policy on my fork's Actions (not the upstream CI, which is not run for this branch): with the rule, 10 passed, 0 failed; with the rule removed, the new Azure.Policy.AssignmentMessage test fails (9 passed, 1 failed). Run: https://github.com/MaxonT/PSRule.Rules.Azure/actions/runs/46244531458 (its overall status shows failed because the 'before' job is the rule-removed run and is meant to fail; the 'after' job is the one with the rule, and it passed). Not run: the rest of the Pester suite, the .NET tests, the Rules task and the docs build, and nothing on Windows. I could not build locally (no .NET 8 SDK).

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
@MaxonT
Ming (MaxonT) requested a review from a team as a code owner November 29, 2026 09:09
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Add rule for setting assignment non-compliance message

1 participant