Fix MT.1005 to exclude Agent Identity CA policies and add tests for Agent ID and Service Principals#1386
Fix MT.1005 to exclude Agent Identity CA policies and add tests for Agent ID and Service Principals#1386bubbletroubles wants to merge 2 commits intomaester365:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug in test MT.1005 (Test-MtCaEmergencyAccessExists) where Agent Identity Conditional Access policies were incorrectly flagged as failing because they don't exclude emergency/break-glass accounts. Agent Identity policies target non-user identities (managed identities, service principals, agents) and cannot have user or group exclusions, so they should be filtered out before checking for emergency access exclusions.
Changes:
- Added filtering logic to exclude Agent Identity CA policies (with
includeAgentIdServicePrincipals) from emergency access checks - Added comprehensive unit tests to verify both Agent Identity and Service Principal policies are properly filtered
- Updated comments to reflect that both types of non-user-targeted policies are now excluded
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
powershell/public/maester/entra/Test-MtCaEmergencyAccessExists.ps1 |
Added filter to exclude policies with includeAgentIdServicePrincipals alongside existing includeServicePrincipals filter |
powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 |
Added helper functions and 3 test cases to verify Agent Identity and Service Principal policies are properly filtered |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1
Outdated
Show resolved
Hide resolved
powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1
Outdated
Show resolved
Hide resolved
…s.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hi @SamErde I've updated the wording as per the copilot recomendations. Ready for re-review. |
Description
Fix MT.1005 to exclude Agent Identity CA policies and add tests for Agent ID and Service Principals
Fixes #1385
Problem
Test MT.1005 (
Test-MtCaEmergencyAccessExists) was incorrectly flagging Agent Identity Conditional Access policies as failing because they don't exclude emergency/break-glass accounts.Agent Identity policies target non-user identities (managed identities, agents) and cannot have user or group exclusions. The test was already filtering out Service Principal policies using
includeServicePrincipals, but was missing the newerincludeAgentIdServicePrincipalsproperty, causing false positives for Agent Identity CA policies.Changes Made
1. Updated
Test-MtCaEmergencyAccessExists.ps1(lines 35-39)includeAgentIdServicePrincipals(the bug fix)includeServicePrincipals) was already working correctlyBefore:
After:
2. Added comprehensive unit tests (
Test-MtCaEmergencyAccessExists.Tests.ps1)Get-PolicyAgentIdentity()helper function to create test Agent Identity policiesGet-PolicyServicePrincipal()helper function to create test Service Principal policiesTesting
✅ All tests passing:
./powershell/tests/pester.ps1Test-MtCaEmergencyAccessExistspass (including 3 new tests)Impact
Related Documentation
Contribution Checklist
Before submitting this PR, please confirm you have completed the following:
/powershell/tests/pester.ps1on your local system.Join us at the Maester repository discussions 💬 or Entra Discord 🧑💻 for more help and conversations!