|
| 1 | +"""Check for open health issues in Microsoft Defender for Identity. |
| 2 | +
|
| 3 | +This module provides a security check that verifies there are no unresolved |
| 4 | +health issues in the Microsoft Defender for Identity deployment. |
| 5 | +""" |
| 6 | + |
| 7 | +from typing import List |
| 8 | + |
| 9 | +from prowler.lib.check.models import Check, CheckReportM365, Severity |
| 10 | +from prowler.providers.m365.services.defenderidentity.defenderidentity_client import ( |
| 11 | + defenderidentity_client, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +class defenderidentity_health_issues_no_open(Check): |
| 16 | + """Ensure Microsoft Defender for Identity has no unresolved health issues. |
| 17 | +
|
| 18 | + This check evaluates whether there are open health issues in the MDI deployment |
| 19 | + that require attention to maintain proper hybrid identity protection. |
| 20 | +
|
| 21 | + - PASS: The health issue has been resolved (status is not open). |
| 22 | + - FAIL: The health issue is open and requires attention. |
| 23 | + - FAIL: No sensors are deployed (MDI cannot protect the environment). |
| 24 | + """ |
| 25 | + |
| 26 | + def execute(self) -> List[CheckReportM365]: |
| 27 | + """Execute the check for open MDI health issues. |
| 28 | +
|
| 29 | + This method iterates through all health issues from Microsoft Defender |
| 30 | + for Identity and reports on their status. Open issues indicate potential |
| 31 | + configuration problems or sensor health concerns that need resolution. |
| 32 | +
|
| 33 | + Returns: |
| 34 | + List[CheckReportM365]: A list of reports containing the result of the check. |
| 35 | + """ |
| 36 | + findings = [] |
| 37 | + |
| 38 | + # Check sensors first - None means API error, empty list means no sensors |
| 39 | + sensors_api_failed = defenderidentity_client.sensors is None |
| 40 | + health_issues_api_failed = defenderidentity_client.health_issues is None |
| 41 | + has_sensors = ( |
| 42 | + defenderidentity_client.sensors and len(defenderidentity_client.sensors) > 0 |
| 43 | + ) |
| 44 | + |
| 45 | + # If both APIs failed, it's likely a permission issue |
| 46 | + if sensors_api_failed and health_issues_api_failed: |
| 47 | + report = CheckReportM365( |
| 48 | + metadata=self.metadata(), |
| 49 | + resource={}, |
| 50 | + resource_name="Defender for Identity", |
| 51 | + resource_id="defenderIdentity", |
| 52 | + ) |
| 53 | + report.status = "FAIL" |
| 54 | + report.status_extended = ( |
| 55 | + "Defender for Identity APIs are not accessible. " |
| 56 | + "Ensure the Service Principal has SecurityIdentitiesSensors.Read.All and " |
| 57 | + "SecurityIdentitiesHealth.Read.All permissions granted." |
| 58 | + ) |
| 59 | + findings.append(report) |
| 60 | + return findings |
| 61 | + |
| 62 | + # If only health issues API failed but we have sensors |
| 63 | + if health_issues_api_failed and has_sensors: |
| 64 | + report = CheckReportM365( |
| 65 | + metadata=self.metadata(), |
| 66 | + resource={}, |
| 67 | + resource_name="Defender for Identity", |
| 68 | + resource_id="defenderIdentity", |
| 69 | + ) |
| 70 | + report.status = "FAIL" |
| 71 | + report.status_extended = ( |
| 72 | + f"Cannot read health issues from Defender for Identity " |
| 73 | + f"(found {len(defenderidentity_client.sensors)} sensor(s) deployed). " |
| 74 | + "Ensure the Service Principal has SecurityIdentitiesHealth.Read.All permission." |
| 75 | + ) |
| 76 | + findings.append(report) |
| 77 | + return findings |
| 78 | + |
| 79 | + # If no sensors are deployed (empty list, not None), MDI cannot monitor |
| 80 | + if not has_sensors and not sensors_api_failed: |
| 81 | + report = CheckReportM365( |
| 82 | + metadata=self.metadata(), |
| 83 | + resource={}, |
| 84 | + resource_name="Defender for Identity", |
| 85 | + resource_id="defenderIdentity", |
| 86 | + ) |
| 87 | + report.status = "FAIL" |
| 88 | + report.status_extended = ( |
| 89 | + "No sensors deployed in Defender for Identity. " |
| 90 | + "Without sensors, MDI cannot monitor health issues in the environment. " |
| 91 | + "Deploy sensors on domain controllers to enable protection." |
| 92 | + ) |
| 93 | + findings.append(report) |
| 94 | + return findings |
| 95 | + |
| 96 | + # If health_issues is empty list - no issues exist, this is compliant |
| 97 | + if not defenderidentity_client.health_issues: |
| 98 | + report = CheckReportM365( |
| 99 | + metadata=self.metadata(), |
| 100 | + resource={}, |
| 101 | + resource_name="Defender for Identity", |
| 102 | + resource_id="defenderIdentity", |
| 103 | + ) |
| 104 | + report.status = "PASS" |
| 105 | + report.status_extended = ( |
| 106 | + "No open health issues found in Defender for Identity." |
| 107 | + ) |
| 108 | + findings.append(report) |
| 109 | + return findings |
| 110 | + |
| 111 | + for health_issue in defenderidentity_client.health_issues: |
| 112 | + report = CheckReportM365( |
| 113 | + metadata=self.metadata(), |
| 114 | + resource=health_issue, |
| 115 | + resource_name=health_issue.display_name, |
| 116 | + resource_id=health_issue.id, |
| 117 | + ) |
| 118 | + |
| 119 | + issue_type = health_issue.health_issue_type or "unknown" |
| 120 | + severity = health_issue.severity or "unknown" |
| 121 | + status = (health_issue.status or "").lower() |
| 122 | + |
| 123 | + if status != "open": |
| 124 | + report.status = "PASS" |
| 125 | + report.status_extended = f"Defender for Identity {issue_type} health issue {health_issue.display_name} is resolved." |
| 126 | + else: |
| 127 | + report.status = "FAIL" |
| 128 | + report.status_extended = f"Defender for Identity {issue_type} health issue {health_issue.display_name} is open with {severity} severity." |
| 129 | + |
| 130 | + # Adjust severity based on issue severity |
| 131 | + if severity == "high": |
| 132 | + report.check_metadata.Severity = Severity.high |
| 133 | + elif severity == "medium": |
| 134 | + report.check_metadata.Severity = Severity.medium |
| 135 | + elif severity == "low": |
| 136 | + report.check_metadata.Severity = Severity.low |
| 137 | + |
| 138 | + findings.append(report) |
| 139 | + |
| 140 | + return findings |
0 commit comments