Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions powershell/assets/MaesterSettings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
SchemaVersion = '1.0'
Settings = @{
EmergencyAccessAccounts = @{ Type = 'object[]'; Default = @(); Sensitive = $false; Description = 'Emergency access (break glass) accounts and groups excluded from Conditional Access checks.' }
DelegatedAdminTenants = @{ Type = 'string[]'; Default = @(); Sensitive = $false; Description = 'Tenant IDs allowed to administer this tenant through Tenant Governance or GDAP (allowlist).' }
DataverseEnvironmentUrl = @{ Type = 'string'; Default = ''; Sensitive = $false; Description = 'URL of the Dataverse environment that the Copilot Studio checks read.' }
AzureDevOpsOrganization = @{ Type = 'string'; Default = ''; Sensitive = $false; Description = 'Azure DevOps organization that Connect-Maester -Service AzureDevOps connects to.' }
GitHubOrganization = @{ Type = 'string'; Default = ''; Sensitive = $false; Description = 'GitHub organization that the GitHub checks read.' }
Expand Down
3 changes: 2 additions & 1 deletion powershell/assets/templates/maester-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"GlobalSettings": {
"EmergencyAccessAccounts": []
"EmergencyAccessAccounts": [],
"DelegatedAdminTenants": []
},
"TestSettings": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
function Get-MtCaRiskRemediationPolicyResult {
<#
.SYNOPSIS
Evaluates the Conditional Access policies that require risk remediation for risky users.

.DESCRIPTION
Shared evaluation of MT.1253, also used by MT.1013 to skip the password change check when MT.1253's
requirement is met. A policy qualifies when it:
- is enabled,
- includes all users, excluding only emergency access accounts and the guest/external-user selector,
- targets all resources and excludes none,
- is scoped to every user risk level from MinimumUserRiskLevel up to high, and
- is not narrowed by platform, location, device filter or sign-in risk conditions, and
- requires the riskRemediation grant control.

Emergency access comes from the EmergencyAccessAccounts setting. Without the setting, a user or group excluded
from every Conditional Access policy that targets users (at least two) is taken as emergency access, as MT.1005
does. Get-MtEmergencyAccessAccount throws when a configured entry cannot be resolved.

Returns one object with the policies, a report row per risk remediation policy and whether any policy qualifies.

.EXAMPLE
(Get-MtCaRiskRemediationPolicyResult).Pass

Returns $true when at least one policy requires risk remediation for high-risk users as MT.1253 requires.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
param(
# Lowest user risk level that a qualifying policy must cover; every higher level must be covered too.
[ValidateSet('high', 'medium', 'low')]
[string] $MinimumUserRiskLevel = 'high'
)

$requiredRiskLevels = switch ($MinimumUserRiskLevel) {
'low' { @('low', 'medium', 'high') }
'medium' { @('medium', 'high') }
default { @('high') }
}

$policies = @(Get-MtConditionalAccessPolicy)
$riskRemediationPolicies = @($policies | Where-Object {
@($_.grantControls.builtInControls) -contains 'riskRemediation'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Request the evolvable enum value before evaluating risk remediation

This evaluator depends on the literal riskRemediation value, but Get-MtConditionalAccessPolicy calls the beta endpoint through Invoke-MtGraphRequest, whose request headers contain only ConsistencyLevel. Microsoft explicitly requires Prefer: include-unknown-enum-members to retrieve riskRemediation, including on the beta endpoint: conditionalAccessGrantControls documentation.

I exercised the real policy helper and request-building code with the transport response stubbed to model that documented enum behavior. The captured headers were {"ConsistencyLevel":"eventual"}. An otherwise qualifying policy returned as unknownFutureValue produced Pass = false and zero recognized remediation policies; returning the same policy with the explicit riskRemediation value produced Pass = true. This is an offline reproduction based on the documented API contract, not a live-tenant observation.

Consequently, a tenant that already follows the recommended remediation can fail MT.1253, and MT.1013 will not take its intended replacement-policy skip. The new unit tests mock Get-MtConditionalAccessPolicy with the literal value and therefore miss the request boundary.

Please add the required header through the shared cached transport/policy-read path, preserve it across pagination, and add request-level regression coverage plus the MT.1013 integration case. Preserve the session-cache contract; bypassing the cache is not a fix.

AI-assisted review: GPT-6 (Codex), final-review lane.

} | Sort-Object -Property displayName)

# Emergency access exclusions are allowed. They come from the EmergencyAccessAccounts setting; the helper fails if
# a configured object cannot be resolved. Without the setting, a user or group excluded from every Conditional
# Access policy that targets users is taken as emergency access, as MT.1005 does. One policy is not enough to
# tell an emergency access account from any other exclusion.
$emergencyAccess = @(Get-MtEmergencyAccessAccount)
$emergencyUserIds = @($emergencyAccess | Where-Object { $_.Type -eq 'user' -and $_.ObjectId } | ForEach-Object { $_.ObjectId })
$emergencyGroupIds = @($emergencyAccess | Where-Object { $_.Type -eq 'group' -and $_.ObjectId } | ForEach-Object { $_.ObjectId })
$emergencyAccessDetected = $false
if ($emergencyAccess.Count -eq 0) {
$userPolicies = @($policies | Where-Object {
-not $_.conditions.applications.includeAuthenticationContextClassReferences -and
-not $_.conditions.clientApplications.includeServicePrincipals -and
-not $_.conditions.clientApplications.includeAgentIdServicePrincipals
})
if ($userPolicies.Count -ge 2) {
$excludedFromAll = {
param([string] $Property)
@($userPolicies | ForEach-Object { @($_.conditions.users.$Property | Where-Object { $_ -and $_ -ne 'GuestsOrExternalUsers' } | Select-Object -Unique) } |
Group-Object | Where-Object { $_.Count -eq $userPolicies.Count } | ForEach-Object { $_.Name })
}
$emergencyUserIds = & $excludedFromAll 'excludeUsers'
$emergencyGroupIds = & $excludedFromAll 'excludeGroups'
$emergencyAccessDetected = ($emergencyUserIds.Count + $emergencyGroupIds.Count) -gt 0
}
}

$report = foreach ($policy in $riskRemediationPolicies) {
$userRiskLevels = @($policy.conditions.userRiskLevels | Where-Object { $_ })
$missingRiskLevels = @($requiredRiskLevels | Where-Object { $_ -notin $userRiskLevels })
$users = $policy.conditions.users
# Both the legacy GuestsOrExternalUsers token and excludeGuestsOrExternalUsers select only guest/external
# users, for whom risk remediation is unsupported. Neither exempts arbitrary workforce users or roles.
$unapprovedUsers = @($users.excludeUsers | Where-Object { $_ -and $_ -ne 'GuestsOrExternalUsers' -and $_ -notin $emergencyUserIds })
$unapprovedGroups = @($users.excludeGroups | Where-Object { $_ -and $_ -notin $emergencyGroupIds })
$excludedRoles = @($users.excludeRoles | Where-Object { $_ })
$checks = [ordered]@{
'Enabled' = $policy.state -eq 'enabled'
'All users' = @($policy.conditions.users.includeUsers) -contains 'All'
'Only approved user exclusions' = ($unapprovedUsers.Count + $unapprovedGroups.Count + $excludedRoles.Count) -eq 0
'All resources' = (@($policy.conditions.applications.includeApplications) -contains 'All') -and
@($policy.conditions.applications.excludeApplications | Where-Object { $_ }).Count -eq 0
"User risk $($requiredRiskLevels -join ', ')" = $missingRiskLevels.Count -eq 0
'No platform, location, device or sign-in risk scoping' = (
@($policy.conditions.signInRiskLevels | Where-Object { $_ }).Count -eq 0 -and
-not $policy.conditions.devices.deviceFilter -and
@($policy.conditions.platforms.includePlatforms | Where-Object { $_ -and $_ -ne 'all' }).Count -eq 0 -and
@($policy.conditions.platforms.excludePlatforms | Where-Object { $_ }).Count -eq 0 -and
@($policy.conditions.locations.includeLocations | Where-Object { $_ -and $_ -ne 'All' }).Count -eq 0 -and
@($policy.conditions.locations.excludeLocations | Where-Object { $_ }).Count -eq 0
)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$exclusionCount = @($policy.conditions.users.excludeUsers | Where-Object { $_ }).Count +
@($policy.conditions.users.excludeGroups | Where-Object { $_ }).Count +
@($policy.conditions.users.excludeRoles | Where-Object { $_ }).Count +
$(if ($users.excludeGuestsOrExternalUsers) { 1 } else { 0 })

[pscustomobject]@{
Policy = $policy
UserRiskLevels = if ($userRiskLevels.Count -gt 0) { $userRiskLevels -join ', ' } else { 'None' }
Exclusions = $exclusionCount
Failed = $failed -join ', '
Pass = $failed.Count -eq 0
}
}
$report = @($report)

[pscustomobject]@{
RequiredRiskLevels = $requiredRiskLevels
Policies = $policies
Report = $report
Pass = @($report | Where-Object { $_.Pass }).Count -gt 0
EmergencyUserIds = @($emergencyUserIds)
EmergencyGroupIds = @($emergencyGroupIds)
EmergencyAccessDetected = $emergencyAccessDetected
}
}
Loading
Loading