|
| 1 | +from prowler.lib.check.models import Check, CheckReportM365 |
| 2 | +from prowler.providers.m365.services.entra.entra_client import entra_client |
| 3 | +from prowler.providers.m365.services.entra.entra_service import ( |
| 4 | + ConditionalAccessGrantControl, |
| 5 | + ConditionalAccessPolicyState, |
| 6 | + InsiderRiskLevel, |
| 7 | +) |
| 8 | + |
| 9 | + |
| 10 | +class entra_conditional_access_policy_block_elevated_insider_risk(Check): |
| 11 | + """Check if a Conditional Access policy blocks all cloud app access for elevated insider risk users. |
| 12 | +
|
| 13 | + This check verifies that at least one enabled Conditional Access policy |
| 14 | + blocks access to all cloud applications for users with an elevated insider |
| 15 | + risk level, as determined by Microsoft Purview Insider Risk Management |
| 16 | + and Adaptive Protection. |
| 17 | +
|
| 18 | + - PASS: An enabled CA policy blocks all cloud app access for elevated insider risk users. |
| 19 | + - FAIL: No enabled CA policy blocks broad cloud app access based on insider risk signals. |
| 20 | + """ |
| 21 | + |
| 22 | + def execute(self) -> list[CheckReportM365]: |
| 23 | + """Execute the check logic. |
| 24 | +
|
| 25 | + Returns: |
| 26 | + A list of reports containing the result of the check. |
| 27 | + """ |
| 28 | + findings = [] |
| 29 | + report = CheckReportM365( |
| 30 | + metadata=self.metadata(), |
| 31 | + resource={}, |
| 32 | + resource_name="Conditional Access Policies", |
| 33 | + resource_id="conditionalAccessPolicies", |
| 34 | + ) |
| 35 | + report.status = "FAIL" |
| 36 | + report.status_extended = "No Conditional Access Policy blocks access for users with elevated insider risk." |
| 37 | + |
| 38 | + for policy in entra_client.conditional_access_policies.values(): |
| 39 | + if policy.state == ConditionalAccessPolicyState.DISABLED: |
| 40 | + continue |
| 41 | + |
| 42 | + if not policy.conditions.application_conditions: |
| 43 | + continue |
| 44 | + |
| 45 | + if "All" not in policy.conditions.user_conditions.included_users: |
| 46 | + continue |
| 47 | + |
| 48 | + if ( |
| 49 | + "All" |
| 50 | + not in policy.conditions.application_conditions.included_applications |
| 51 | + ): |
| 52 | + continue |
| 53 | + |
| 54 | + if ( |
| 55 | + ConditionalAccessGrantControl.BLOCK |
| 56 | + not in policy.grant_controls.built_in_controls |
| 57 | + ): |
| 58 | + continue |
| 59 | + |
| 60 | + if policy.conditions.insider_risk_levels is None: |
| 61 | + report = CheckReportM365( |
| 62 | + metadata=self.metadata(), |
| 63 | + resource=policy, |
| 64 | + resource_name=policy.display_name, |
| 65 | + resource_id=policy.id, |
| 66 | + ) |
| 67 | + report.status = "FAIL" |
| 68 | + if policy.state == ConditionalAccessPolicyState.ENABLED_FOR_REPORTING: |
| 69 | + report.status_extended = f"Conditional Access Policy {policy.display_name} is configured in report-only mode to block all cloud apps and Microsoft Purview Adaptive Protection is not providing insider risk signals." |
| 70 | + else: |
| 71 | + report.status_extended = f"Conditional Access Policy {policy.display_name} is configured to block all cloud apps and Microsoft Purview Adaptive Protection is not providing insider risk signals." |
| 72 | + continue |
| 73 | + |
| 74 | + if policy.conditions.insider_risk_levels != InsiderRiskLevel.ELEVATED: |
| 75 | + continue |
| 76 | + |
| 77 | + report = CheckReportM365( |
| 78 | + metadata=self.metadata(), |
| 79 | + resource=policy, |
| 80 | + resource_name=policy.display_name, |
| 81 | + resource_id=policy.id, |
| 82 | + ) |
| 83 | + |
| 84 | + if policy.state == ConditionalAccessPolicyState.ENABLED_FOR_REPORTING: |
| 85 | + report.status = "FAIL" |
| 86 | + report.status_extended = f"Conditional Access Policy {policy.display_name} reports blocking all cloud apps for elevated insider risk users but does not enforce it." |
| 87 | + else: |
| 88 | + report.status = "PASS" |
| 89 | + report.status_extended = f"Conditional Access Policy {policy.display_name} blocks access to all cloud apps for users with elevated insider risk." |
| 90 | + break |
| 91 | + |
| 92 | + findings.append(report) |
| 93 | + return findings |
0 commit comments