Repository navigation
feat(entra): Add Entra risk remediation, drift, and delegated admin checks #2705
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
Cloud-Architekt
wants to merge
12
commits into
maester365:main
Choose a base branch
from
Cloud-Architekt:tnh-EntraGovernanceChecks
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
12 commits
Select commit
Hold shift + click to select a range
1f744bb
feat(entra): add risk remediation, drift, and delegated admin checks
Cloud-Architekt 8679418
feat(entra): add new tenant governance and configuration monitoring s…
Cloud-Architekt d499529
fix(tests): remove unused parameters in drift test cases
Cloud-Architekt 2589777
Merge remote-tracking branch 'upstream/main' into tnh-EntraGovernance…
Cloud-Architekt d3e058f
Merge branch 'main' into tnh-EntraGovernanceChecks
Cloud-Architekt 31b293c
Merge branch 'main' into tnh-EntraGovernanceChecks
Cloud-Architekt 47ec100
Merge branch 'maester365:main' into tnh-EntraGovernanceChecks
Cloud-Architekt e287c32
fix(entra): refine descriptions and conditions for risk remediation p…
Cloud-Architekt 012ce4b
fix(entra): enhance risk remediation policy checks and update related…
Cloud-Architekt 6f4ce5c
Merge branch 'main' into tnh-EntraGovernanceChecks
Cloud-Architekt 9091dfe
feat(entra): enhance Invoke-MtGraphRequest to support IncludeUnknownE…
Cloud-Architekt 36125cd
Merge branch 'main' into tnh-EntraGovernanceChecks
Cloud-Architekt 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
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
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,6 +1,7 @@ | ||
| { | ||
| "GlobalSettings": { | ||
| "EmergencyAccessAccounts": [] | ||
| "EmergencyAccessAccounts": [], | ||
| "DelegatedAdminTenants": [] | ||
| }, | ||
| "TestSettings": [] | ||
| } |
122 changes: 122 additions & 0 deletions
122
powershell/internal/checks/maester/entra/Get-MtCaRiskRemediationPolicyResult.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,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' | ||
| } | 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 | ||
| ) | ||
| } | ||
|
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 | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
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
riskRemediationvalue, butGet-MtConditionalAccessPolicycalls the beta endpoint throughInvoke-MtGraphRequest, whose request headers contain onlyConsistencyLevel. Microsoft explicitly requiresPrefer: include-unknown-enum-membersto retrieveriskRemediation, 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 asunknownFutureValueproducedPass = falseand zero recognized remediation policies; returning the same policy with the explicitriskRemediationvalue producedPass = 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-MtConditionalAccessPolicywith 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.