From 34b17a4b362f41eefd1b663594e34d9327f66000 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 13 Nov 2026 22:00:16 +0100 Subject: [PATCH 1/6] fix(entra): resolve MT.1058 app roles against the API each assignment points to --- ...Test-MtSpExchangeAppAccessPolicy.Tests.ps1 | 55 ++++++++++++-- tests/maester/entra/Test.MT.1058.ps1 | 71 ++++++++++++++----- 2 files changed, 104 insertions(+), 22 deletions(-) diff --git a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 index c1d241b2ec..74decd11d0 100644 --- a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 +++ b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 @@ -26,11 +26,15 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { Mock -ModuleName Maester Get-ApplicationAccessPolicy { @() } Mock -ModuleName Maester Invoke-MtGraphRequest { throw "Unexpected Graph request: $RelativeUri" } Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { - $RelativeUri -eq 'servicePrincipals' -and $Filter + $RelativeUri -eq 'servicePrincipals' -and $Filter -eq "appId eq '00000003-0000-0000-c000-000000000000'" } { [pscustomobject]@{ Id = 'graph-sp' - AppRoles = @([pscustomobject]@{ Id = 'mail-read-role'; Value = 'Mail.Read' }) + DisplayName = 'Microsoft Graph' + AppRoles = @( + [pscustomobject]@{ Id = 'mail-read-role'; Value = 'Mail.Read' } + [pscustomobject]@{ Id = 'user-read-all-role'; Value = 'User.Read.All' } + ) } } Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { @@ -41,7 +45,7 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' } { - [pscustomobject]@{ AppRoleId = 'mail-read-role' } + [pscustomobject]@{ AppRoleId = 'mail-read-role'; ResourceId = 'graph-sp' } } } @@ -142,18 +146,57 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { { Test-MtSpExchangeAppAccessPolicy } | Should -Throw '*Graph unavailable*' } + + It 'Resolves an app role against the API the assignment points to' { + # Microsoft Graph's Mail.Read role ID, but assigned on another API: it is not Mail.Read there. + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'mail-read-role'; ResourceId = 'other-api-sp' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeTrue + $script:Result | Should -BeExactly 'Well done. No applications with Exchange permissions were found.' + } + + It 'Lists an assignment whose role the API does not define instead of dropping it' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'mail-read-role'; ResourceId = 'graph-sp' } + [pscustomobject]@{ AppRoleId = 'unknown-role'; ResourceId = 'graph-sp' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeFalse + $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | mail-app | Mail.Read |')) + $script:Result | Should -Match '### App Role Assignments Not Evaluated' + $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | Microsoft Graph | unknown-role |')) + } + + It 'Does not list the default access role as not evaluated' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = '00000000-0000-0000-0000-000000000000'; ResourceId = 'graph-sp' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeTrue + $script:Result | Should -Not -Match 'Not Evaluated' + } } Describe 'MT.1058 native engine results' { BeforeEach { Mock -ModuleName Maester Get-MgContext { $null } Mock -ModuleName Maester Invoke-MtGraphRequest { - if ($RelativeUri -eq 'servicePrincipals' -and $Filter) { - [pscustomobject]@{ AppRoles = @([pscustomobject]@{ Id = 'mail-read-role'; Value = 'Mail.Read' }) } + if ($RelativeUri -eq 'servicePrincipals' -and $Filter -eq "appId eq '00000003-0000-0000-c000-000000000000'") { + [pscustomobject]@{ Id = 'graph-sp'; DisplayName = 'Microsoft Graph'; AppRoles = @([pscustomobject]@{ Id = 'mail-read-role'; Value = 'Mail.Read' }) } + } elseif ($RelativeUri -eq 'servicePrincipals' -and $Filter) { + @() } elseif ($RelativeUri -eq 'servicePrincipals') { [pscustomobject]@{ Id = 'app-sp'; AppId = 'mail-app'; DisplayName = 'Contoso Mail App' } } elseif ($RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments') { - [pscustomobject]@{ AppRoleId = 'mail-read-role' } + [pscustomobject]@{ AppRoleId = 'mail-read-role'; ResourceId = 'graph-sp' } } else { throw "Unexpected Graph request: $RelativeUri" } diff --git a/tests/maester/entra/Test.MT.1058.ps1 b/tests/maester/entra/Test.MT.1058.ps1 index 339f30b557..3266db1374 100644 --- a/tests/maester/entra/Test.MT.1058.ps1 +++ b/tests/maester/entra/Test.MT.1058.ps1 @@ -30,7 +30,7 @@ Service = ('Graph', 'ExchangeOnline'), LongRunning, Author = 'l-gosling', - Contributor = ('merill', 'SamErde', 'thomas-s-schmidt') + Contributor = ('merill', 'SamErde', 'thomas-s-schmidt', 'julien-ly') )] [CmdletBinding()] [OutputType([bool])] @@ -38,29 +38,57 @@ Write-Verbose 'Running Test-MtSpExchangeAppAccessPolicy' -# Note: If you make any changes to this list, please keep it in sync - # with the markdown file Test-MtSpExchangeAppAccessPolicy.md - $exchangePermissions = @( - 'Mail.Read', 'Mail.ReadBasic', 'Mail.ReadBasic.All', 'Mail.ReadWrite', 'Mail.Send', - 'MailboxSettings.Read', 'MailboxSettings.ReadWrite', - 'Calendars.Read', 'Calendars.ReadWrite', - 'Contacts.Read', 'Contacts.ReadWrite' - ) + # Note: If you make any changes to these lists, please keep them in sync + # with the markdown file Test.MT.1058.md + # Permissions that application access policies restrict, by the appId of the API that defines them. + $mailboxApiPermissions = [ordered]@{ + # Microsoft Graph + '00000003-0000-0000-c000-000000000000' = @( + 'Mail.Read', 'Mail.ReadBasic', 'Mail.ReadBasic.All', 'Mail.ReadWrite', 'Mail.Send', + 'MailboxSettings.Read', 'MailboxSettings.ReadWrite', + 'Calendars.Read', 'Calendars.ReadWrite', + 'Contacts.Read', 'Contacts.ReadWrite' + ) + } + $exchangePermissions = @($mailboxApiPermissions.Values | ForEach-Object { $_ }) + + # An app role ID is defined by the API the assignment points to (its resourceId), so it is resolved there. + $mailboxApis = @{} + foreach ($apiAppId in $mailboxApiPermissions.Keys) { + foreach ($api in @(Invoke-MtGraphRequest -RelativeUri 'servicePrincipals' -Filter "appId eq '$apiAppId'")) { + $roleValues = @{} + foreach ($appRole in @($api.AppRoles)) { + $roleValues[[string]$appRole.Id] = $appRole.Value + } + $mailboxApis[[string]$api.Id] = [PSCustomObject]@{ + DisplayName = $api.DisplayName + RoleValues = $roleValues + Permissions = $mailboxApiPermissions[$apiAppId] + } + } + } # Get service principals with Exchange permissions - $msGraph = Invoke-MtGraphRequest -RelativeUri 'servicePrincipals' -Filter "appId eq '00000003-0000-0000-c000-000000000000'" - $availablePermissions = $msGraph.AppRoles | Select-Object Id, Value - + $unresolvedAssignments = [System.Collections.Generic.List[object]]::new() $servicePrincipals = Invoke-MtGraphRequest -RelativeUri 'servicePrincipals' $principalsWithExchangePerms = $servicePrincipals | ForEach-Object { $sp = $_ $appRoles = Invoke-MtGraphRequest -RelativeUri "servicePrincipals/$($sp.Id)/appRoleAssignments" - $permissions = $appRoles.AppRoleId | ForEach-Object { - $roleId = $_ - ($availablePermissions | Where-Object { $_.Id -eq $roleId }).Value + $permissions = foreach ($assignment in @($appRoles)) { + $api = $mailboxApis[[string]$assignment.ResourceId] + # Other APIs, and the default access role (empty GUID), grant no mailbox permission. + if (-not $api -or $assignment.AppRoleId -eq [guid]::Empty) { + continue + } + $roleId = [string]$assignment.AppRoleId + if (-not $api.RoleValues.ContainsKey($roleId)) { + $unresolvedAssignments.Add([PSCustomObject]@{ ServicePrincipal = $sp; Api = $api.DisplayName; AppRoleId = $roleId }) + } elseif ($api.RoleValues[$roleId] -in $api.Permissions) { + $api.RoleValues[$roleId] + } } - if ($permissions | Where-Object { $_ -in $exchangePermissions }) { + if ($permissions) { [PSCustomObject]@{ Id = $sp.Id DisplayName = $sp.DisplayName @@ -133,6 +161,17 @@ $testResultMarkdown += "`n`n**Applications with matching RestrictAccess policies configured:** $($appsWithPolicies.Count)" } + if ($unresolvedAssignments.Count -gt 0) { + $testResultMarkdown += "`n`n### App Role Assignments Not Evaluated`n`n" + $testResultMarkdown += "These assignments name an app role that the API does not define, so this check cannot tell what they grant.`n`n" + $testResultMarkdown += "| Application | API | App Role ID |`n" + $testResultMarkdown += "| --- | --- | --- |`n" + foreach ($unresolved in $unresolvedAssignments) { + $portalLink = Get-MtLinkServicePrincipal -ServicePrincipal $unresolved.ServicePrincipal -Blade Permissions + $testResultMarkdown += "| $portalLink | $(Get-MtSafeMarkdown $unresolved.Api) | $(Get-MtSafeMarkdown $unresolved.AppRoleId) |`n" + } + } + Add-MtTestResultDetail -Result $testResultMarkdown return $result } From 9304fabee9b0ff6c2edc4b33acb1fe74d754506a Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 13 Nov 2026 22:00:16 +0100 Subject: [PATCH 2/6] fix(entra): count full_access_as_app in MT.1058 --- ...Test-MtSpExchangeAppAccessPolicy.Tests.ps1 | 70 +++++++++++++++++++ tests/maester/entra/Test.MT.1058.md | 9 ++- tests/maester/entra/Test.MT.1058.ps1 | 2 + 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 index 74decd11d0..b5f0e3ccc8 100644 --- a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 +++ b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 @@ -37,6 +37,18 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { ) } } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals' -and $Filter -eq "appId eq '00000002-0000-0ff1-ce00-000000000000'" + } { + [pscustomobject]@{ + Id = 'exchange-sp' + DisplayName = 'Office 365 Exchange Online' + AppRoles = @( + [pscustomobject]@{ Id = 'ews-role'; Value = 'full_access_as_app' } + [pscustomobject]@{ Id = 'exchange-manage-role'; Value = 'Exchange.ManageAsApp' } + ) + } + } Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { $RelativeUri -eq 'servicePrincipals' -and -not $Filter } { @@ -183,6 +195,64 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { Test-MtSpExchangeAppAccessPolicy | Should -BeTrue $script:Result | Should -Not -Match 'Not Evaluated' } + + It 'Counts an app whose only mailbox permission is full_access_as_app' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'ews-role'; ResourceId = 'exchange-sp' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeFalse + $script:Result | Should -Match ([regex]::Escape('Found **1** applications with Exchange permissions.')) + $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | mail-app | full_access_as_app |')) + } + + It 'Passes for full_access_as_app when a RestrictAccess policy includes the app' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'ews-role'; ResourceId = 'exchange-sp' } + } + Mock -ModuleName Maester Get-ApplicationAccessPolicy { + [pscustomobject]@{ AppId = @('mail-app'); AccessRight = 'RestrictAccess' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeTrue + } + + It 'Lists the Microsoft Graph and EWS permissions of one app together' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'mail-read-role'; ResourceId = 'graph-sp' } + [pscustomobject]@{ AppRoleId = 'ews-role'; ResourceId = 'exchange-sp' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeFalse + $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | mail-app | Mail.Read, full_access_as_app |')) + } + + It 'Does not count an Exchange Online app role other than full_access_as_app' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'exchange-manage-role'; ResourceId = 'exchange-sp' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeTrue + } + + It 'Still evaluates Microsoft Graph permissions when the tenant has no Office 365 Exchange Online service principal' { + # Without that service principal, no app role assignment can point at it. + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals' -and $Filter -eq "appId eq '00000002-0000-0ff1-ce00-000000000000'" + } { @() } + + Test-MtSpExchangeAppAccessPolicy | Should -BeFalse + $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | mail-app | Mail.Read |')) + $script:Result | Should -Not -Match 'Not Evaluated' + } } Describe 'MT.1058 native engine results' { diff --git a/tests/maester/entra/Test.MT.1058.md b/tests/maester/entra/Test.MT.1058.md index b734e053f4..d9d42b2aa2 100644 --- a/tests/maester/entra/Test.MT.1058.md +++ b/tests/maester/entra/Test.MT.1058.md @@ -1,4 +1,4 @@ -This check evaluates legacy application access policies in Exchange Online for applications with Microsoft Graph mail permissions. +This check evaluates legacy application access policies in Exchange Online for applications with Microsoft Graph mail permissions or the Exchange Web Services (EWS) permission `full_access_as_app`. These permissions grant access to every mailbox unless an application access policy restricts them. @@ -15,6 +15,9 @@ Microsoft Exchange related permissions that should be secured by application acc - Calendars.ReadWrite - Contacts.Read - Contacts.ReadWrite +- full_access_as_app (Office 365 Exchange Online) + +Each permission is matched on the API that defines it. `full_access_as_app` gives access to every mailbox through EWS, which Microsoft is retiring in Exchange Online; it matters wherever EWS is still enabled. This check requires a `RestrictAccess` policy for each application. A `DenyAccess` policy only denies access to mailboxes in its scope; it does not restrict access to mailboxes outside that scope and does not satisfy this check. @@ -24,7 +27,7 @@ Microsoft has replaced application access policies with [RBAC for Applications]( 1. For an app still using legacy policies, review its existing policies and confirm a matching `RestrictAccess` policy limits it to the intended mailboxes. A deny-only policy does not provide that limit. 2. For new configurations or migration, follow Microsoft's RBAC for Applications guide to assign the required Exchange application role with a mailbox scope. -3. Remove equivalent or broader Microsoft Graph application permissions from the app's Entra grants after migration. Entra and Exchange grants are additive; retaining an unscoped Entra grant defeats the Exchange scope. See [MT.1252](https://maester.dev/docs/tests/MT.1252) for overlapping grants. +3. Remove equivalent or broader application permissions (Microsoft Graph, or `full_access_as_app` for EWS) from the app's Entra grants after migration. Entra and Exchange grants are additive; retaining an unscoped Entra grant defeats the Exchange scope. See [MT.1252](https://maester.dev/docs/tests/MT.1252) for overlapping grants. 4. Verify the app against both an intended mailbox and a mailbox outside its scope. `Test-ServicePrincipalAuthorization` evaluates the Exchange RBAC assignment; it does not include separate Entra grants. MT.1058 does not evaluate RBAC assignments. An app whose mail permissions are granted only through Exchange RBAC is outside this check's scope. @@ -40,7 +43,9 @@ Test-ApplicationAccessPolicy -Identity user@contoso.com -AppId '' #### Related links - [Application access policy replacement notice - Microsoft Learn](https://learn.microsoft.com/powershell/module/exchangepowershell/new-applicationaccesspolicy) +- [Application access policies: supported permissions - Microsoft Learn](https://learn.microsoft.com/exchange/permissions-exo/application-access-policies#supported-permissions-and-other-resources) - [RBAC for Applications in Exchange Online - Microsoft Learn](https://learn.microsoft.com/exchange/permissions-exo/application-rbac) +- [Exchange Online EWS retirement - Exchange Team Blog](https://techcommunity.microsoft.com/blog/exchange/exchange-online-ews-your-time-is-almost-up/4492361) %TestResult% diff --git a/tests/maester/entra/Test.MT.1058.ps1 b/tests/maester/entra/Test.MT.1058.ps1 index 3266db1374..e63ea356dc 100644 --- a/tests/maester/entra/Test.MT.1058.ps1 +++ b/tests/maester/entra/Test.MT.1058.ps1 @@ -49,6 +49,8 @@ 'Calendars.Read', 'Calendars.ReadWrite', 'Contacts.Read', 'Contacts.ReadWrite' ) + # Office 365 Exchange Online: Exchange Web Services (EWS) + '00000002-0000-0ff1-ce00-000000000000' = @('full_access_as_app') } $exchangePermissions = @($mailboxApiPermissions.Values | ForEach-Object { $_ }) From b4925b9b2e83722f5a278c0ba3e49c4a6f2e49cc Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 13 Nov 2026 22:27:04 +0100 Subject: [PATCH 3/6] fix(entra): ask for investigation when MT.1058 cannot resolve an assignment --- ...Test-MtSpExchangeAppAccessPolicy.Tests.ps1 | 31 ++++++++++++++++++- tests/maester/entra/Test.MT.1058.md | 2 ++ tests/maester/entra/Test.MT.1058.ps1 | 15 ++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 index b5f0e3ccc8..93ce24882a 100644 --- a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 +++ b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 @@ -18,9 +18,11 @@ AfterAll { Describe 'Test-MtSpExchangeAppAccessPolicy' { BeforeEach { $script:Result = $null + $script:Investigate = $false Mock -ModuleName Maester Add-MtTestResultDetail { - param($Result) + param($Result, [switch] $Investigate) $script:Result = $Result + $script:Investigate = $Investigate.IsPresent } Mock -ModuleName Maester Get-MtLinkServicePrincipal { 'Contoso Mail App' } Mock -ModuleName Maester Get-ApplicationAccessPolicy { @() } @@ -180,11 +182,25 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { } Test-MtSpExchangeAppAccessPolicy | Should -BeFalse + $script:Investigate | Should -BeFalse -Because 'a definite failure stays a failure' $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | mail-app | Mail.Read |')) $script:Result | Should -Match '### App Role Assignments Not Evaluated' $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | Microsoft Graph | unknown-role |')) } + It 'Asks for investigation instead of passing when the only finding is an assignment the API does not define' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'unknown-role'; ResourceId = 'graph-sp' } + } + + $null = Test-MtSpExchangeAppAccessPolicy + $script:Investigate | Should -BeTrue + $script:Result | Should -Not -Match 'Well done' + $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | Microsoft Graph | unknown-role |')) + } + It 'Does not list the default access role as not evaluated' { Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' @@ -293,4 +309,17 @@ Describe 'MT.1058 native engine results' { $rows[0].Result | Should -Be $Expected $rows[0].ResultDetail.TestResult | Should -Not -BeNullOrEmpty } + + It 'Records an assignment the API does not define as Investigate through Invoke-MtTest' { + Mock -ModuleName Maester Get-ApplicationAccessPolicy { @() } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'servicePrincipals/app-sp/appRoleAssignments' + } { + [pscustomobject]@{ AppRoleId = 'unknown-role'; ResourceId = 'graph-sp' } + } + + $rows = @(Invoke-MtTest -Id 'MT.1058' -Config $script:config) + $rows | Should -HaveCount 1 + $rows[0].Result | Should -Be 'Investigate' + } } diff --git a/tests/maester/entra/Test.MT.1058.md b/tests/maester/entra/Test.MT.1058.md index d9d42b2aa2..ba82f42e9d 100644 --- a/tests/maester/entra/Test.MT.1058.md +++ b/tests/maester/entra/Test.MT.1058.md @@ -19,6 +19,8 @@ Microsoft Exchange related permissions that should be secured by application acc Each permission is matched on the API that defines it. `full_access_as_app` gives access to every mailbox through EWS, which Microsoft is retiring in Exchange Online; it matters wherever EWS is still enabled. +An app role assignment to one of these two APIs that names a role the API does not define is listed under **App Role Assignments Not Evaluated**. When nothing else fails, the result is marked for investigation instead of passing. + This check requires a `RestrictAccess` policy for each application. A `DenyAccess` policy only denies access to mailboxes in its scope; it does not restrict access to mailboxes outside that scope and does not satisfy this check. ### Remediation action diff --git a/tests/maester/entra/Test.MT.1058.ps1 b/tests/maester/entra/Test.MT.1058.ps1 index e63ea356dc..eb7acd6319 100644 --- a/tests/maester/entra/Test.MT.1058.ps1 +++ b/tests/maester/entra/Test.MT.1058.ps1 @@ -139,11 +139,14 @@ $appsWithExchangePermissionsCount = ($principalsWithExchangePerms | Measure-Object).Count $invalidCount = ($missingPolicies | Measure-Object).Count $result = $invalidCount -eq 0 + # An assignment that could not be resolved is not evidence of compliance: no failure, but not a pass either. + $needsReview = $result -and $unresolvedAssignments.Count -gt 0 + $praise = if ($needsReview) { '' } else { 'Well done. ' } if ($appsWithExchangePermissionsCount -eq 0) { - $testResultMarkdown = 'Well done. No applications with Exchange permissions were found.' + $testResultMarkdown = "${praise}No applications with Exchange permissions were found." } elseif ($result) { - $testResultMarkdown = "Well done. All **$appsWithExchangePermissionsCount** applications with Exchange permissions have matching RestrictAccess policies configured." + $testResultMarkdown = "${praise}All **$appsWithExchangePermissionsCount** applications with Exchange permissions have matching RestrictAccess policies configured." } else { $testResultMarkdown = "Found **$appsWithExchangePermissionsCount** applications with Exchange permissions. **$invalidCount** application(s) do not have a matching RestrictAccess policy configured." @@ -165,7 +168,7 @@ if ($unresolvedAssignments.Count -gt 0) { $testResultMarkdown += "`n`n### App Role Assignments Not Evaluated`n`n" - $testResultMarkdown += "These assignments name an app role that the API does not define, so this check cannot tell what they grant.`n`n" + $testResultMarkdown += "These assignments name an app role that the API does not define, so this check cannot tell what they grant. Review them before reading this result as a pass.`n`n" $testResultMarkdown += "| Application | API | App Role ID |`n" $testResultMarkdown += "| --- | --- | --- |`n" foreach ($unresolved in $unresolvedAssignments) { @@ -174,6 +177,10 @@ } } - Add-MtTestResultDetail -Result $testResultMarkdown + if ($needsReview) { + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate + } else { + Add-MtTestResultDetail -Result $testResultMarkdown + } return $result } From 5fabb14d6d508916680b0bc3d77ee38dbfd5d85f Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 13 Nov 2026 23:06:55 +0100 Subject: [PATCH 4/6] docs(entra): say what MT.1058 returns when it asks for investigation --- tests/maester/entra/Test.MT.1058.md | 2 +- tests/maester/entra/Test.MT.1058.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/maester/entra/Test.MT.1058.md b/tests/maester/entra/Test.MT.1058.md index ba82f42e9d..2cf308256c 100644 --- a/tests/maester/entra/Test.MT.1058.md +++ b/tests/maester/entra/Test.MT.1058.md @@ -19,7 +19,7 @@ Microsoft Exchange related permissions that should be secured by application acc Each permission is matched on the API that defines it. `full_access_as_app` gives access to every mailbox through EWS, which Microsoft is retiring in Exchange Online; it matters wherever EWS is still enabled. -An app role assignment to one of these two APIs that names a role the API does not define is listed under **App Role Assignments Not Evaluated**. When nothing else fails, the result is marked for investigation instead of passing. +An app role assignment to one of these two APIs that names a role the API does not define is listed under **App Role Assignments Not Evaluated**. When nothing else fails, the result is marked for investigation instead of passing. `Test-MtSpExchangeAppAccessPolicy` still returns `$true` in that case, so a script that reads only its return value sees a pass. This check requires a `RestrictAccess` policy for each application. A `DenyAccess` policy only denies access to mailboxes in its scope; it does not restrict access to mailboxes outside that scope and does not satisfy this check. diff --git a/tests/maester/entra/Test.MT.1058.ps1 b/tests/maester/entra/Test.MT.1058.ps1 index eb7acd6319..273035a3d7 100644 --- a/tests/maester/entra/Test.MT.1058.ps1 +++ b/tests/maester/entra/Test.MT.1058.ps1 @@ -9,7 +9,8 @@ .EXAMPLE Test-MtSpExchangeAppAccessPolicy - Returns true if all service principals with Exchange permissions have access policies configured + Returns true if all service principals with Exchange permissions have access policies configured. + It also returns true when the only finding is an app role assignment that it could not evaluate: that result is marked Investigate in the test result details, not in the return value. .LINK https://maester.dev/docs/commands/Test-MtSpExchangeAppAccessPolicy From 08658006d311cdf4b65d0bf6b67662551d956967 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 13 Nov 2026 23:29:39 +0100 Subject: [PATCH 5/6] fix(entra): count a RestrictAccess policy for all applications in MT.1058 --- .../Test-MtSpExchangeAppAccessPolicy.Tests.ps1 | 17 +++++++++++++++++ tests/maester/entra/Test.MT.1058.md | 2 +- tests/maester/entra/Test.MT.1058.ps1 | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 index 93ce24882a..d233cda12f 100644 --- a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 +++ b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 @@ -106,6 +106,23 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { Test-MtSpExchangeAppAccessPolicy | Should -BeTrue } + It 'Passes when a RestrictAccess policy applies to all applications' { + Mock -ModuleName Maester Get-ApplicationAccessPolicy { + [pscustomobject]@{ AppId = @('*'); AccessRight = 'RestrictAccess' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeTrue + $script:Result | Should -Match 'All \*\*1\*\* applications' + } + + It 'Does not count a DenyAccess policy that applies to all applications' { + Mock -ModuleName Maester Get-ApplicationAccessPolicy { + [pscustomobject]@{ AppId = @('*'); AccessRight = 'DenyAccess' } + } + + Test-MtSpExchangeAppAccessPolicy | Should -BeFalse + } + It 'Fails when no application access policies exist' { Test-MtSpExchangeAppAccessPolicy | Should -BeFalse } diff --git a/tests/maester/entra/Test.MT.1058.md b/tests/maester/entra/Test.MT.1058.md index 2cf308256c..1059898e6a 100644 --- a/tests/maester/entra/Test.MT.1058.md +++ b/tests/maester/entra/Test.MT.1058.md @@ -21,7 +21,7 @@ Each permission is matched on the API that defines it. `full_access_as_app` give An app role assignment to one of these two APIs that names a role the API does not define is listed under **App Role Assignments Not Evaluated**. When nothing else fails, the result is marked for investigation instead of passing. `Test-MtSpExchangeAppAccessPolicy` still returns `$true` in that case, so a script that reads only its return value sees a pass. -This check requires a `RestrictAccess` policy for each application. A `DenyAccess` policy only denies access to mailboxes in its scope; it does not restrict access to mailboxes outside that scope and does not satisfy this check. +This check requires a `RestrictAccess` policy for each application; a `RestrictAccess` policy created with `-AppId *` applies to every application. A `DenyAccess` policy only denies access to mailboxes in its scope; it does not restrict access to mailboxes outside that scope and does not satisfy this check. ### Remediation action diff --git a/tests/maester/entra/Test.MT.1058.ps1 b/tests/maester/entra/Test.MT.1058.ps1 index 273035a3d7..90b334c543 100644 --- a/tests/maester/entra/Test.MT.1058.ps1 +++ b/tests/maester/entra/Test.MT.1058.ps1 @@ -120,8 +120,10 @@ $missingPolicies = @() $appsWithPolicies = @() + # A RestrictAccess policy created with -AppId * applies to every application. + $restrictsAllApps = $appAccessPolicies.AppId -contains '*' foreach ($sp in $principalsWithExchangePerms) { - $hasPolicy = $appAccessPolicies.AppId -contains $sp.AppId + $hasPolicy = $restrictsAllApps -or $appAccessPolicies.AppId -contains $sp.AppId $filteredPermissions = $sp.Permissions -split ', ' | Where-Object { $_ -in $exchangePermissions } $appRecord = [PSCustomObject]@{ Id = $sp.Id From 65b28608ec8a89e26064c7907e310a34fb11eab6 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Sat, 14 Nov 2026 02:54:03 +0100 Subject: [PATCH 6/6] fix(entra): return $null from MT.1058 when it asks for investigation Export-MtTestResultXml exports an Investigate result from the value the test returned: $true as Success, $false as Failure, anything else as Ignored. MT.1058 returned $true when its only finding was an assignment it could not resolve, so NUnit/JUnit reported a pass while the Maester report asked for investigation. It now returns $null in that case. --- .../functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 | 3 ++- tests/maester/entra/Test.MT.1058.md | 2 +- tests/maester/entra/Test.MT.1058.ps1 | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 index d233cda12f..2a09949d3b 100644 --- a/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 +++ b/powershell/tests/functions/Test-MtSpExchangeAppAccessPolicy.Tests.ps1 @@ -212,7 +212,8 @@ Describe 'Test-MtSpExchangeAppAccessPolicy' { [pscustomobject]@{ AppRoleId = 'unknown-role'; ResourceId = 'graph-sp' } } - $null = Test-MtSpExchangeAppAccessPolicy + $returned = Test-MtSpExchangeAppAccessPolicy + $returned | Should -BeNullOrEmpty -Because 'an Investigate result that returns $true is exported to NUnit/JUnit as a pass' $script:Investigate | Should -BeTrue $script:Result | Should -Not -Match 'Well done' $script:Result | Should -Match ([regex]::Escape('| Contoso Mail App | Microsoft Graph | unknown-role |')) diff --git a/tests/maester/entra/Test.MT.1058.md b/tests/maester/entra/Test.MT.1058.md index 1059898e6a..0adf5a5e4d 100644 --- a/tests/maester/entra/Test.MT.1058.md +++ b/tests/maester/entra/Test.MT.1058.md @@ -19,7 +19,7 @@ Microsoft Exchange related permissions that should be secured by application acc Each permission is matched on the API that defines it. `full_access_as_app` gives access to every mailbox through EWS, which Microsoft is retiring in Exchange Online; it matters wherever EWS is still enabled. -An app role assignment to one of these two APIs that names a role the API does not define is listed under **App Role Assignments Not Evaluated**. When nothing else fails, the result is marked for investigation instead of passing. `Test-MtSpExchangeAppAccessPolicy` still returns `$true` in that case, so a script that reads only its return value sees a pass. +An app role assignment to one of these two APIs that names a role the API does not define is listed under **App Role Assignments Not Evaluated**. When nothing else fails, the result is marked for investigation instead of passing, and `Test-MtSpExchangeAppAccessPolicy` returns `$null`, so NUnit/JUnit exports ignore it instead of reporting a pass. This check requires a `RestrictAccess` policy for each application; a `RestrictAccess` policy created with `-AppId *` applies to every application. A `DenyAccess` policy only denies access to mailboxes in its scope; it does not restrict access to mailboxes outside that scope and does not satisfy this check. diff --git a/tests/maester/entra/Test.MT.1058.ps1 b/tests/maester/entra/Test.MT.1058.ps1 index 90b334c543..3941abd45c 100644 --- a/tests/maester/entra/Test.MT.1058.ps1 +++ b/tests/maester/entra/Test.MT.1058.ps1 @@ -10,7 +10,7 @@ Test-MtSpExchangeAppAccessPolicy Returns true if all service principals with Exchange permissions have access policies configured. - It also returns true when the only finding is an app role assignment that it could not evaluate: that result is marked Investigate in the test result details, not in the return value. + Returns $null when the only finding is an app role assignment that it could not evaluate: the result is marked Investigate, and NUnit/JUnit exports ignore it instead of reporting a pass. .LINK https://maester.dev/docs/commands/Test-MtSpExchangeAppAccessPolicy @@ -182,8 +182,9 @@ if ($needsReview) { Add-MtTestResultDetail -Result $testResultMarkdown -Investigate - } else { - Add-MtTestResultDetail -Result $testResultMarkdown + # NUnit/JUnit exports an Investigate result from the return value: $true would be exported as a pass. + return $null } + Add-MtTestResultDetail -Result $testResultMarkdown return $result }