Repository navigation
Description
What happens
In auto-detection mode (no EmergencyAccessAccounts configured), when no Conditional Access policy is left after the authentication context, service principal and agent identity filters, MT.1005 returns False and its result reads:
These Conditional Access policies don't have the emergency access group excluded:
%TestResult%
- The sentence announces a list of policies, and there is none.
groupis the default value of$EmergencyAccessUUIDType(L68), not a detected type.- The placeholder stays raw:
Add-MtTestResultDetailonly replaces it when-GraphObjectsis not empty (L120, L191-L194), and the list of policies without the exclusion is empty (L92-L93).
@earbona23 measured it while reviewing #2811 (comment), with the same output on main and on that branch, so #2811 does not cause it.
Where it shows
- A tenant with no Conditional Access policy at all, for example a tenant with an Entra ID P1 license that still uses security defaults (creating Conditional Access policies prevents enabling security defaults). MT.1005 requires
AAD_PREMIUM, so it runs there. - A tenant whose only policies target service principals or agent identities.
The False verdict looks intended: the two unit tests under "Agent Identity and Service Principal policies" expect it (L462-L484, "When all policies are filtered out, there are no policies to check, so no emergency access is detected"). For comparison, the same tenant passes when an account is configured in EmergencyAccessAccounts ("All Conditional Access policies exclude the configured emergency access accounts or groups:"). This issue is only about the message.
Suggested change
In the auto-detection branch, when $PolicyCount is 0, return False with a message of its own and no placeholder, for example "No user-targeted Conditional Access policy was found, so no emergency access account or group could be detected." Whether this case should be skipped instead is the maintainers' call.
Reproduction
Code level, no tenant change. On main (2d659e8) and on the head of #2811 (f0d1dce), PowerShell 7 and Pester 5.7.1: 4 passed on both. The tests pin the current behaviour.
Pester
# $env:MAESTER_WT = '<path to a Maester clone>'; Invoke-Pester -Path ./Test.MT.1005.NoPolicy.Repro.Tests.ps1 -Output Detailed
Describe 'MT.1005 with no user-targeted Conditional Access policy' {
BeforeAll {
Import-Module (Join-Path $env:MAESTER_WT 'powershell/Maester.psd1') -Force
. (Join-Path $env:MAESTER_WT 'powershell/tests/helpers/Use-MtModuleFunction.ps1')
Use-MtModuleFunction -Name Test-MtCaEmergencyAccessExists
Mock -ModuleName Maester Get-MtLicenseInformation { 'P1' }
Mock -ModuleName Maester Add-MtTestResultDetail { $global:MtRepro = @{ Result = $Result; Objects = @($GraphObjects | Where-Object { $_ }) } }
$script:userId = '11111111-1111-1111-1111-111111111111'
}
BeforeEach { $global:MtRepro = $null }
It 'Control: auto-detection, one policy that excludes a user, passes' {
Mock -ModuleName Maester Get-MtConditionalAccessPolicy {
[pscustomobject]@{ id = 'p1'; displayName = 'Policy 1'; state = 'enabled'; conditions = [pscustomobject]@{ applications = [pscustomobject]@{ includeApplications = @('All') }; users = [pscustomobject]@{ includeUsers = @('All'); excludeUsers = @('11111111-1111-1111-1111-111111111111'); excludeGroups = @() } } }
}
Mock -ModuleName Maester Invoke-MtGraphRequest { [pscustomobject]@{ id = '11111111-1111-1111-1111-111111111111'; displayName = 'Break glass 1' } }
Test-MtCaEmergencyAccessExists | Should -BeTrue
}
It 'Auto-detection, no Conditional Access policy at all: fails with a sentence about policies and a raw placeholder' {
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { @() }
Test-MtCaEmergencyAccessExists | Should -BeFalse
$global:MtRepro.Result | Should -BeExactly "These Conditional Access policies don't have the emergency access group excluded:`n`n%TestResult%"
$global:MtRepro.Objects.Count | Should -Be 0
}
It 'Auto-detection, only an agent identity policy (filtered out): same output' {
Mock -ModuleName Maester Get-MtConditionalAccessPolicy {
[pscustomobject]@{ id = 'p2'; displayName = 'Agents'; state = 'enabled'; conditions = [pscustomobject]@{ applications = [pscustomobject]@{ includeApplications = @('All') }; clientApplications = [pscustomobject]@{ includeAgentIdServicePrincipals = @('All') }; users = [pscustomobject]@{ includeUsers = @(); excludeUsers = @(); excludeGroups = @() } } }
}
Test-MtCaEmergencyAccessExists | Should -BeFalse
$global:MtRepro.Result | Should -BeExactly "These Conditional Access policies don't have the emergency access group excluded:`n`n%TestResult%"
$global:MtRepro.Objects.Count | Should -Be 0
}
It 'Configured account, same tenant with no policy: passes' {
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { @() }
Mock -ModuleName Maester Invoke-MtGraphRequest { [pscustomobject]@{ id = '11111111-1111-1111-1111-111111111111'; displayName = 'Break glass 1' } }
Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts @(@{ Id = $script:userId; Type = 'user' }) | Should -BeTrue
$global:MtRepro.Result | Should -BeLike 'All Conditional Access policies exclude the configured emergency access accounts or groups:*'
}
}
Activity
fix(entra): give MT.1005 a message of its own when auto-detection fin…