Repository navigation
feat(policy): add Azure.Policy.AssignmentMessage rule - #3992
Open
Ming (MaxonT) wants to merge 2 commits into
Open
Ming (MaxonT) wants to merge 2 commits into
Ming (MaxonT) wants to merge 2 commits into
Conversation
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) forMicrosoft.Authorization/policyAssignments. It passes whenproperties.nonComplianceMessageshas at least one entry with a non-blankmessageand nopolicyDefinitionReferenceId, 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 inAzure.Policy.Tests.ps1. For the fixture I gaveassignment-001inResources.Policy.jsona single message that has apolicyDefinitionReferenceId, so it fails the rule;assignment-002already had a default message and passes.Two choices I would like you to check: the
ruleSetis2026_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 siblingAzure.Policy.AssignmentDescriptors.How I checked: ran
Invoke-Build TestModule -TestGroup Policyon 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 newAzure.Policy.AssignmentMessagetest 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, theRulestask and the docs build, and nothing on Windows. I could not build locally (no .NET 8 SDK).