Repository navigation
fix(entra): MT.1007 no longer counts custom controls as MFA #2841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
julien-ly
wants to merge
4
commits into
maester365:main
Choose a base branch
from
julien-ly:fix/mt1007-custom-controls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ce9ab46
fix(entra): MT.1007 no longer counts custom controls as MFA
julien-ly 435ff32
test: rename the policy helper in the MT.1007 unit tests
julien-ly 857b299
fix(entra): MT.1007 skips a policy that a custom control alone satisfies
julien-ly f955518
fix(entra): MT.1007 lists custom control policies that require all co…
julien-ly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
powershell/tests/functions/Test-MtCaMfaForAllUsers.Tests.ps1
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| 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 Get-TestCaPolicy { | ||
| param( | ||
| [string] $DisplayName, | ||
| [string[]] $BuiltInControls = @(), | ||
| [string[]] $CustomAuthenticationFactors = @(), | ||
| [string] $StrengthRequirementsSatisfied, | ||
| [ValidateSet('OR', 'AND')] | ||
| [string] $Operator = 'OR', | ||
| [switch] $NoGrantControls | ||
| ) | ||
| $grantControls = $null | ||
| if (-not $NoGrantControls) { | ||
| $authenticationStrength = $null | ||
| if ($StrengthRequirementsSatisfied) { | ||
| $authenticationStrength = [pscustomobject]@{ requirementsSatisfied = $StrengthRequirementsSatisfied } | ||
| } | ||
| $grantControls = [pscustomobject]@{ | ||
| operator = $Operator | ||
| 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 = @(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 = @(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 (<Operator>), 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 | ||
| 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 '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*' | ||
| } | ||
| } | ||
|
|
||
| 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 (<Operator>)' -ForEach @( | ||
| @{ Operator = 'OR' } | ||
| @{ Operator = 'AND' } | ||
| ) { | ||
| $policies = @( | ||
| Get-TestCaPolicy -DisplayName 'Require MFA' -BuiltInControls 'mfa' | ||
| Get-TestCaPolicy -DisplayName 'Legacy MFA provider' -CustomAuthenticationFactors 'ContosoMFA' -Operator $Operator | ||
| ) | ||
| 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 = @(Get-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*' | ||
| } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 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) | ||
| <!--- Results ---> | ||
| %TestResult% |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.