From ce9ab46dca2276192cae47ef2a4a0b8fd986a485 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 20 Nov 2026 14:43:22 +0100 Subject: [PATCH 1/4] fix(entra): MT.1007 no longer counts custom controls as MFA Custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them: no new or edited custom controls since September 2026, full retirement in early 2027. A policy that grants access with a custom control alone no longer counts, and the result lists these policies with a link to the migration guide. Adds the first unit tests for MT.1007. --- .../Test-MtCaMfaForAllUsers.Tests.ps1 | 105 ++++++++++++++++++ tests/maester/entra/Test.MT.1007.md | 4 +- tests/maester/entra/Test.MT.1007.ps1 | 29 ++++- 3 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 diff --git a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 new file mode 100644 index 0000000000..14724d8f82 --- /dev/null +++ b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 @@ -0,0 +1,105 @@ +Describe 'Test-MtCaMfaForAllUsers' { + BeforeAll { + Import-Module "$PSScriptRoot\..\..\Maester.psd1" -Force + . "$PSScriptRoot\..\helpers\Use-MtModuleFunction.ps1" + # Check functions that became native tests are not exported. + Use-MtModuleFunction -Name Test-MtCaMfaForAllUsers + + # An enabled policy that targets all users and all resources. + function New-TestCaPolicy { + param( + [string] $DisplayName, + [string[]] $BuiltInControls = @(), + [string[]] $CustomAuthenticationFactors = @(), + [string] $StrengthRequirementsSatisfied, + [switch] $NoGrantControls + ) + $grantControls = $null + if (-not $NoGrantControls) { + $authenticationStrength = $null + if ($StrengthRequirementsSatisfied) { + $authenticationStrength = [pscustomobject]@{ requirementsSatisfied = $StrengthRequirementsSatisfied } + } + $grantControls = [pscustomobject]@{ + operator = 'OR' + builtInControls = $BuiltInControls + customAuthenticationFactors = $CustomAuthenticationFactors + authenticationStrength = $authenticationStrength + } + } + [pscustomobject]@{ + displayName = $DisplayName + state = 'enabled' + conditions = [pscustomobject]@{ + users = [pscustomobject]@{ includeUsers = @('All') } + applications = [pscustomobject]@{ includeApplications = @('All') } + } + grantControls = $grantControls + } + } + } + + BeforeEach { + Mock Add-MtTestResultDetail -ModuleName Maester { } + } + + It 'Passes for a policy that requires built-in MFA' { + $policies = @(New-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa') + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeTrue + } + + It 'Passes for a policy that requires an authentication strength that satisfies MFA' { + $policies = @(New-TestCaPolicy -DisplayName 'Require phishing-resistant MFA' -StrengthRequirementsSatisfied 'mfa') + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeTrue + } + + It 'Fails for a policy that relies on a custom control, and lists the policy' { + $policies = @(New-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA') + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like 'No Conditional Access policy requires*' -and + $Result -like '*custom control*' -and + $Result -like '*- Legacy MFA provider*' + } + } + + It 'Passes for a policy that requires built-in MFA next to a custom control' { + $policies = @(New-TestCaPolicy -DisplayName 'MFA or legacy provider' -BuiltInControls 'mfa' -CustomAuthenticationFactors 'ContosoMFA') + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeTrue + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -notlike '*custom control*' + } + } + + It 'Passes for a policy that requires MFA, and still lists a separate custom control policy' { + $policies = @( + New-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa' + New-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' + ) + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeTrue + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like 'The following Conditional Access policies require*' -and + $Result -like '*- Legacy MFA provider*' + } + } + + It 'Fails for a policy with session controls only' { + $policies = @(New-TestCaPolicy -DisplayName 'Sign-in frequency' -NoGrantControls) + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -notlike '*custom control*' + } + } +} diff --git a/tests/maester/entra/Test.MT.1007.md b/tests/maester/entra/Test.MT.1007.md index cb3c2fb301..dd8e8ba6f1 100644 --- a/tests/maester/entra/Test.MT.1007.md +++ b/tests/maester/entra/Test.MT.1007.md @@ -1,5 +1,7 @@ This test checks if the tenant has at least one Conditional Access policy requiring MFA for all users. -See [Require MFA for all users - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/howto-conditional-access-policy-all-users-mfa) +A policy that grants access with a custom control doesn't count: custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. The test result lists these policies. + +See [Require MFA for all users - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/howto-conditional-access-policy-all-users-mfa) and [Migrate from custom controls to external multifactor authentication - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa) %TestResult% \ No newline at end of file diff --git a/tests/maester/entra/Test.MT.1007.ps1 b/tests/maester/entra/Test.MT.1007.ps1 index 7af400df45..3c3f28c106 100644 --- a/tests/maester/entra/Test.MT.1007.ps1 +++ b/tests/maester/entra/Test.MT.1007.ps1 @@ -6,8 +6,12 @@ .Description MFA for all users Conditional Access policy can be used to require MFA for all users in the tenant. + A policy that grants access with a custom control doesn't count: custom controls don't satisfy the + multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. + Learn more: https://learn.microsoft.com/entra/identity/conditional-access/howto-conditional-access-policy-all-users-mfa + https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa .Example Test-MtCaMfaForAllUsers @@ -31,7 +35,7 @@ Service = 'Graph', License = 'AAD_PREMIUM', Author = 'f-bader', - Contributor = ('brianreidc7', 'SamErde') + Contributor = ('brianreidc7', 'SamErde', 'julien-ly') )] [CmdletBinding()] [OutputType([bool])] @@ -49,6 +53,9 @@ -not $_.conditions.signInRiskLevels } $policiesResult = New-Object System.Collections.ArrayList + # Policies that target all users and all resources with a custom control. Custom controls don't + # satisfy the multifactor authentication requirement, so these policies don't count. + $customControlPolicies = New-Object System.Collections.ArrayList $result = $false foreach ($policy in $policies) { @@ -60,20 +67,24 @@ ).Count -gt 0 } + $targetsAllUsersAndResources = $policy.conditions.users.includeUsers -eq 'All' -and + $policy.conditions.applications.includeApplications -eq 'All' + if ( ( $policy.grantControls.builtInControls -contains 'mfa' -or - $policy.grantControls.authenticationStrength.requirementsSatisfied -contains 'mfa' -or - $hasCustomAuthenticationFactor + $policy.grantControls.authenticationStrength.requirementsSatisfied -contains 'mfa' ) -and - $policy.conditions.users.includeUsers -eq 'All' -and - $policy.conditions.applications.includeApplications -eq 'All' + $targetsAllUsersAndResources ) { $result = $true $CurrentResult = $true $policiesResult.Add($policy) | Out-Null } else { $CurrentResult = $false + if ($hasCustomAuthenticationFactor -and $targetsAllUsersAndResources) { + $customControlPolicies.Add($policy) | Out-Null + } } Write-Verbose "$($policy.displayName) - $CurrentResult" } @@ -84,6 +95,14 @@ $testResult = 'No Conditional Access policy requires multi-factor authentication for all users.' } + if ($customControlPolicies.Count -gt 0) { + $customControlList = ($customControlPolicies | ForEach-Object { "- $(Get-MtSafeMarkdown $_.displayName)" }) -join "`n" + $migrationLink = 'https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa' + $testResult += "`n`nThe following policies target all users with a custom control, which doesn't satisfy the " + + "multifactor authentication requirement, so they don't count. Custom controls are deprecated: " + + "[migrate them to external MFA]($migrationLink).`n`n$customControlList" + } + Add-MtTestResultDetail -Result $testResult -GraphObjects $policiesResult -GraphObjectType ConditionalAccess return $result From 435ff326c59fb216a23d8fb6ec02e8a71ca65129 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 20 Nov 2026 14:49:27 +0100 Subject: [PATCH 2/4] test: rename the policy helper in the MT.1007 unit tests PSScriptAnalyzer flags a New-* function without ShouldProcess. The helper only builds test objects, so it now uses the Get verb. --- .../functions/Test-MtCaMfaForAllUsers.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 index 14724d8f82..1891d71dc1 100644 --- a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 @@ -6,7 +6,7 @@ Use-MtModuleFunction -Name Test-MtCaMfaForAllUsers # An enabled policy that targets all users and all resources. - function New-TestCaPolicy { + function Get-TestCaPolicy { param( [string] $DisplayName, [string[]] $BuiltInControls = @(), @@ -44,21 +44,21 @@ } It 'Passes for a policy that requires built-in MFA' { - $policies = @(New-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa') + $policies = @(Get-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa') Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } Test-MtCaMfaForAllUsers | Should -BeTrue } It 'Passes for a policy that requires an authentication strength that satisfies MFA' { - $policies = @(New-TestCaPolicy -DisplayName 'Require phishing-resistant MFA' -StrengthRequirementsSatisfied 'mfa') + $policies = @(Get-TestCaPolicy -DisplayName 'Require phishing-resistant MFA' -StrengthRequirementsSatisfied 'mfa') Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } Test-MtCaMfaForAllUsers | Should -BeTrue } It 'Fails for a policy that relies on a custom control, and lists the policy' { - $policies = @(New-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA') + $policies = @(Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA') Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } Test-MtCaMfaForAllUsers | Should -BeFalse @@ -70,7 +70,7 @@ } It 'Passes for a policy that requires built-in MFA next to a custom control' { - $policies = @(New-TestCaPolicy -DisplayName 'MFA or legacy provider' -BuiltInControls 'mfa' -CustomAuthenticationFactors 'ContosoMFA') + $policies = @(Get-TestCaPolicy -DisplayName 'MFA or legacy provider' -BuiltInControls 'mfa' -CustomAuthenticationFactors 'ContosoMFA') Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } Test-MtCaMfaForAllUsers | Should -BeTrue @@ -81,8 +81,8 @@ It 'Passes for a policy that requires MFA, and still lists a separate custom control policy' { $policies = @( - New-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa' - New-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' + Get-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa' + Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' ) Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } @@ -94,7 +94,7 @@ } It 'Fails for a policy with session controls only' { - $policies = @(New-TestCaPolicy -DisplayName 'Sign-in frequency' -NoGrantControls) + $policies = @(Get-TestCaPolicy -DisplayName 'Sign-in frequency' -NoGrantControls) Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } Test-MtCaMfaForAllUsers | Should -BeFalse From 857b29949e238abf4ca76f0a434eac1b8a3e18e9 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 20 Nov 2026 14:53:21 +0100 Subject: [PATCH 3/4] fix(entra): MT.1007 skips a policy that a custom control alone satisfies Under the OR operator, a user meets a policy that requires MFA or a custom control with the custom control alone, so the policy doesn't require MFA. A policy that requires both (AND) still counts. --- .../Test-MtCaMfaForAllUsers.Tests.ps1 | 16 ++++++++++++++-- tests/maester/entra/Test.MT.1007.md | 2 +- tests/maester/entra/Test.MT.1007.ps1 | 18 +++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 index 1891d71dc1..f7c1dbc61d 100644 --- a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 @@ -12,6 +12,8 @@ [string[]] $BuiltInControls = @(), [string[]] $CustomAuthenticationFactors = @(), [string] $StrengthRequirementsSatisfied, + [ValidateSet('OR', 'AND')] + [string] $Operator = 'OR', [switch] $NoGrantControls ) $grantControls = $null @@ -21,7 +23,7 @@ $authenticationStrength = [pscustomobject]@{ requirementsSatisfied = $StrengthRequirementsSatisfied } } $grantControls = [pscustomobject]@{ - operator = 'OR' + operator = $Operator builtInControls = $BuiltInControls customAuthenticationFactors = $CustomAuthenticationFactors authenticationStrength = $authenticationStrength @@ -69,10 +71,20 @@ } } - It 'Passes for a policy that requires built-in MFA next to a custom control' { + It 'Fails for a policy that a custom control satisfies instead of built-in MFA (OR), and lists the policy' { $policies = @(Get-TestCaPolicy -DisplayName 'MFA or legacy provider' -BuiltInControls 'mfa' -CustomAuthenticationFactors 'ContosoMFA') Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + Test-MtCaMfaForAllUsers | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like '*- MFA or legacy provider*' + } + } + + It 'Passes for a policy that requires built-in MFA and a custom control (AND)' { + $policies = @(Get-TestCaPolicy -DisplayName 'MFA and legacy provider' -BuiltInControls 'mfa' -CustomAuthenticationFactors 'ContosoMFA' -Operator 'AND') + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + Test-MtCaMfaForAllUsers | Should -BeTrue Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { $Result -notlike '*custom control*' diff --git a/tests/maester/entra/Test.MT.1007.md b/tests/maester/entra/Test.MT.1007.md index dd8e8ba6f1..439150a5b7 100644 --- a/tests/maester/entra/Test.MT.1007.md +++ b/tests/maester/entra/Test.MT.1007.md @@ -1,6 +1,6 @@ This test checks if the tenant has at least one Conditional Access policy requiring MFA for all users. -A policy that grants access with a custom control doesn't count: custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. The test result lists these policies. +A policy that a custom control alone satisfies doesn't count: custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. The test result lists these policies. A policy that requires MFA and a custom control (AND) still counts. See [Require MFA for all users - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/howto-conditional-access-policy-all-users-mfa) and [Migrate from custom controls to external multifactor authentication - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa) diff --git a/tests/maester/entra/Test.MT.1007.ps1 b/tests/maester/entra/Test.MT.1007.ps1 index 3c3f28c106..be7227e0fd 100644 --- a/tests/maester/entra/Test.MT.1007.ps1 +++ b/tests/maester/entra/Test.MT.1007.ps1 @@ -6,8 +6,9 @@ .Description MFA for all users Conditional Access policy can be used to require MFA for all users in the tenant. - A policy that grants access with a custom control doesn't count: custom controls don't satisfy the - multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. + A policy that a custom control alone satisfies doesn't count: custom controls don't satisfy the + multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. A policy + that requires MFA and a custom control (AND) still counts. Learn more: https://learn.microsoft.com/entra/identity/conditional-access/howto-conditional-access-policy-all-users-mfa @@ -53,8 +54,8 @@ -not $_.conditions.signInRiskLevels } $policiesResult = New-Object System.Collections.ArrayList - # Policies that target all users and all resources with a custom control. Custom controls don't - # satisfy the multifactor authentication requirement, so these policies don't count. + # Policies that target all users and all resources and that a custom control alone satisfies. Custom + # controls don't satisfy the multifactor authentication requirement, so these policies don't count. $customControlPolicies = New-Object System.Collections.ArrayList $result = $false @@ -69,12 +70,15 @@ $targetsAllUsersAndResources = $policy.conditions.users.includeUsers -eq 'All' -and $policy.conditions.applications.includeApplications -eq 'All' + # Unless the grant requires every control (AND), a custom control alone satisfies the policy. + $customControlSatisfiesPolicy = $hasCustomAuthenticationFactor -and $policy.grantControls.operator -ne 'AND' if ( ( $policy.grantControls.builtInControls -contains 'mfa' -or $policy.grantControls.authenticationStrength.requirementsSatisfied -contains 'mfa' ) -and + -not $customControlSatisfiesPolicy -and $targetsAllUsersAndResources ) { $result = $true @@ -82,7 +86,7 @@ $policiesResult.Add($policy) | Out-Null } else { $CurrentResult = $false - if ($hasCustomAuthenticationFactor -and $targetsAllUsersAndResources) { + if ($customControlSatisfiesPolicy -and $targetsAllUsersAndResources) { $customControlPolicies.Add($policy) | Out-Null } } @@ -98,8 +102,8 @@ if ($customControlPolicies.Count -gt 0) { $customControlList = ($customControlPolicies | ForEach-Object { "- $(Get-MtSafeMarkdown $_.displayName)" }) -join "`n" $migrationLink = 'https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa' - $testResult += "`n`nThe following policies target all users with a custom control, which doesn't satisfy the " + - "multifactor authentication requirement, so they don't count. Custom controls are deprecated: " + + $testResult += "`n`nThe following policies target all users, and a custom control alone satisfies them. A custom control " + + "doesn't satisfy the multifactor authentication requirement, so they don't count. Custom controls are deprecated: " + "[migrate them to external MFA]($migrationLink).`n`n$customControlList" } From f955518d260e7766121e1746788db6b4d545c033 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 20 Nov 2026 21:04:52 +0100 Subject: [PATCH 4/4] fix(entra): MT.1007 lists custom control policies that require all controls A grant with a custom control and no MFA accepts the custom control instead of MFA, whatever the operator. Such a policy still doesn't count, and the result now lists it with the migration link. Three regression cases, which fail on the previous commit. --- .../Test-MtCaMfaForAllUsers.Tests.ps1 | 24 ++++++++++++++--- tests/maester/entra/Test.MT.1007.md | 2 +- tests/maester/entra/Test.MT.1007.ps1 | 26 ++++++++----------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 index f7c1dbc61d..6cadf3a3b6 100644 --- a/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1 @@ -59,8 +59,11 @@ Test-MtCaMfaForAllUsers | Should -BeTrue } - It 'Fails for a policy that relies on a custom control, and lists the policy' { - $policies = @(Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA') + It 'Fails for a policy that relies on a custom control (), and lists the policy' -ForEach @( + @{ Operator = 'OR' } + @{ Operator = 'AND' } + ) { + $policies = @(Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' -Operator $Operator) Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } Test-MtCaMfaForAllUsers | Should -BeFalse @@ -91,10 +94,23 @@ } } - It 'Passes for a policy that requires MFA, and still lists a separate custom control policy' { + It 'Fails for a policy that requires a compliant device and a custom control (AND), and lists the policy' { + $policies = @(Get-TestCaPolicy -DisplayName 'Compliant device and legacy provider' -BuiltInControls 'compliantDevice' -CustomAuthenticationFactors 'ContosoMFA' -Operator 'AND') + Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } + + Test-MtCaMfaForAllUsers | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like '*- Compliant device and legacy provider*' + } + } + + It 'Passes for a policy that requires MFA, and still lists a separate custom control policy ()' -ForEach @( + @{ Operator = 'OR' } + @{ Operator = 'AND' } + ) { $policies = @( Get-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa' - Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' + Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' -Operator $Operator ) Mock Get-MtConditionalAccessPolicy -ModuleName Maester { $policies } diff --git a/tests/maester/entra/Test.MT.1007.md b/tests/maester/entra/Test.MT.1007.md index 439150a5b7..8c953f8c65 100644 --- a/tests/maester/entra/Test.MT.1007.md +++ b/tests/maester/entra/Test.MT.1007.md @@ -1,6 +1,6 @@ This test checks if the tenant has at least one Conditional Access policy requiring MFA for all users. -A policy that a custom control alone satisfies doesn't count: custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. The test result lists these policies. A policy that requires MFA and a custom control (AND) still counts. +A policy that accepts a custom control instead of MFA doesn't count: custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. The test result lists these policies. A policy that requires MFA and a custom control (AND) still counts. See [Require MFA for all users - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/howto-conditional-access-policy-all-users-mfa) and [Migrate from custom controls to external multifactor authentication - Microsoft Learn](https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa) diff --git a/tests/maester/entra/Test.MT.1007.ps1 b/tests/maester/entra/Test.MT.1007.ps1 index be7227e0fd..8d4b998469 100644 --- a/tests/maester/entra/Test.MT.1007.ps1 +++ b/tests/maester/entra/Test.MT.1007.ps1 @@ -6,7 +6,7 @@ .Description MFA for all users Conditional Access policy can be used to require MFA for all users in the tenant. - A policy that a custom control alone satisfies doesn't count: custom controls don't satisfy the + A policy that accepts a custom control instead of MFA doesn't count: custom controls don't satisfy the multifactor authentication requirement, and Microsoft deprecated them in favor of external MFA. A policy that requires MFA and a custom control (AND) still counts. @@ -54,7 +54,7 @@ -not $_.conditions.signInRiskLevels } $policiesResult = New-Object System.Collections.ArrayList - # Policies that target all users and all resources and that a custom control alone satisfies. Custom + # Policies that target all users and all resources and accept a custom control instead of MFA. Custom # controls don't satisfy the multifactor authentication requirement, so these policies don't count. $customControlPolicies = New-Object System.Collections.ArrayList @@ -70,23 +70,19 @@ $targetsAllUsersAndResources = $policy.conditions.users.includeUsers -eq 'All' -and $policy.conditions.applications.includeApplications -eq 'All' - # Unless the grant requires every control (AND), a custom control alone satisfies the policy. - $customControlSatisfiesPolicy = $hasCustomAuthenticationFactor -and $policy.grantControls.operator -ne 'AND' + $requiresMfa = $policy.grantControls.builtInControls -contains 'mfa' -or + $policy.grantControls.authenticationStrength.requirementsSatisfied -contains 'mfa' + # A custom control takes the place of MFA, unless the grant requires MFA as well (AND). + $customControlReplacesMfa = $hasCustomAuthenticationFactor -and + (-not $requiresMfa -or $policy.grantControls.operator -ne 'AND') - if ( - ( - $policy.grantControls.builtInControls -contains 'mfa' -or - $policy.grantControls.authenticationStrength.requirementsSatisfied -contains 'mfa' - ) -and - -not $customControlSatisfiesPolicy -and - $targetsAllUsersAndResources - ) { + if ($requiresMfa -and -not $customControlReplacesMfa -and $targetsAllUsersAndResources) { $result = $true $CurrentResult = $true $policiesResult.Add($policy) | Out-Null } else { $CurrentResult = $false - if ($customControlSatisfiesPolicy -and $targetsAllUsersAndResources) { + if ($customControlReplacesMfa -and $targetsAllUsersAndResources) { $customControlPolicies.Add($policy) | Out-Null } } @@ -102,8 +98,8 @@ if ($customControlPolicies.Count -gt 0) { $customControlList = ($customControlPolicies | ForEach-Object { "- $(Get-MtSafeMarkdown $_.displayName)" }) -join "`n" $migrationLink = 'https://learn.microsoft.com/entra/identity/conditional-access/how-to-migrate-custom-controls-external-mfa' - $testResult += "`n`nThe following policies target all users, and a custom control alone satisfies them. A custom control " + - "doesn't satisfy the multifactor authentication requirement, so they don't count. Custom controls are deprecated: " + + $testResult += "`n`nThe following policies target all users and accept a custom control instead of multifactor authentication. " + + "A custom control doesn't satisfy the multifactor authentication requirement, so they don't count. Custom controls are deprecated: " + "[migrate them to external MFA]($migrationLink).`n`n$customControlList" }