|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Validates that Private Access Sensors are deployed on domain controllers and enforcing strong authentication policies. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + This test checks if Microsoft Entra Private Access Sensors are deployed to domain controllers |
| 7 | + and configured to enforce strong authentication policies (status active and not in audit mode). |
| 8 | +
|
| 9 | +.NOTES |
| 10 | + Test ID: 25403 |
| 11 | + Category: Private Access |
| 12 | + Required API: onPremisesPublishingProfiles/privateAccess/sensors (beta) |
| 13 | +#> |
| 14 | + |
| 15 | +function Test-Assessment-25403 { |
| 16 | + [ZtTest( |
| 17 | + Category = 'Private Access', |
| 18 | + ImplementationCost = 'Medium', |
| 19 | + MinimumLicense = ('Entra_Suite', 'Entra_Premium_Private_Access'), |
| 20 | + Pillar = 'Network', |
| 21 | + RiskLevel = 'High', |
| 22 | + SfiPillar = 'Protect networks', |
| 23 | + TenantType = ('Workforce'), |
| 24 | + TestId = 25403, |
| 25 | + Title = 'DC Agent is deployed and enforcing strong authentication policies', |
| 26 | + UserImpact = 'Medium' |
| 27 | + )] |
| 28 | + [CmdletBinding()] |
| 29 | + param() |
| 30 | + |
| 31 | + #region Data Collection |
| 32 | + Write-PSFMessage '🟦 Start' -Tag Test -Level VeryVerbose |
| 33 | + |
| 34 | + $activity = 'Checking Private Access Sensors on domain controllers' |
| 35 | + Write-ZtProgress -Activity $activity -Status 'Getting Private Access Sensors' |
| 36 | + |
| 37 | + # Query all Private Access Sensors |
| 38 | + $sensors = Invoke-ZtGraphRequest -RelativeUri 'onPremisesPublishingProfiles/privateAccess/sensors' -ApiVersion beta |
| 39 | + #endregion Data Collection |
| 40 | + |
| 41 | + #region Assessment Logic |
| 42 | + # Initialize test variables |
| 43 | + $testResultMarkdown = '' |
| 44 | + $passed = $false |
| 45 | + |
| 46 | + if ($null -eq $sensors -or $sensors.Count -eq 0) { |
| 47 | + # No sensors found - fail |
| 48 | + $passed = $false |
| 49 | + $testResultMarkdown = "❌ Microsoft Entra Private Access Sensors for domain controllers is not deployed.`n`n%TestResult%" |
| 50 | + } |
| 51 | + else { |
| 52 | + # Identify sensors that are active and enforcing (not in audit mode) |
| 53 | + $enforcingSensors = $sensors | Where-Object { $_.status -eq 'active' -and $_.isAuditMode -eq $false } |
| 54 | + $nonEnforcingSensors = $sensors | Where-Object { $_.status -ne 'active' -or $_.isAuditMode -eq $true } |
| 55 | + |
| 56 | + # Determine pass/fail status |
| 57 | + if ($enforcingSensors.Count -gt 0 -and $nonEnforcingSensors.Count -eq 0) { |
| 58 | + # All sensors are active and enforcing - pass |
| 59 | + $passed = $true |
| 60 | + $testResultMarkdown = "✅ Microsoft Entra Private Access for domain controllers is deployed and enforcing strong authentication policies.`n`n%TestResult%" |
| 61 | + } |
| 62 | + elseif ($enforcingSensors.Count -eq 0) { |
| 63 | + # No sensors are enforcing - fail |
| 64 | + $passed = $false |
| 65 | + $testResultMarkdown = "❌ Microsoft Entra Private Access Sensors are deployed but strong authentication policies are not configured.`n`n%TestResult%" |
| 66 | + } |
| 67 | + else { |
| 68 | + # Some sensors enforcing, some not - partial deployment warning (fail) |
| 69 | + $passed = $false |
| 70 | + $testResultMarkdown = "⚠️ Microsoft Entra Private Access Sensors are partially configured. Some domain controllers are not enforcing strong authentication policies.`n`n%TestResult%" |
| 71 | + } |
| 72 | + } |
| 73 | + #endregion Assessment Logic |
| 74 | + |
| 75 | + #region Report Generation |
| 76 | + # Build detailed markdown information |
| 77 | + $mdInfo = '' |
| 78 | + |
| 79 | + if ($sensors -and $sensors.Count -gt 0) { |
| 80 | + $reportTitle = "Private Access Sensors" |
| 81 | + |
| 82 | + $mdInfo += "`n## $reportTitle`n`n" |
| 83 | + $mdInfo += "[Open Private Access in Entra Portal](https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/PrivateAccessOverview.ReactView)`n`n" |
| 84 | + |
| 85 | + # Summary statistics |
| 86 | + $mdInfo += "- **Total sensors**: $($sensors.Count)`n" |
| 87 | + $mdInfo += "- **Active and enforcing**: $($enforcingSensors.Count)`n" |
| 88 | + $mdInfo += "- **Not enforcing**: $($nonEnforcingSensors.Count)`n`n" |
| 89 | + |
| 90 | + # Show warning for sensors not enforcing |
| 91 | + if ($nonEnforcingSensors.Count -gt 0) { |
| 92 | + $mdInfo += "**⚠️ Sensors not enforcing policies:** $($nonEnforcingSensors.Count)`n`n" |
| 93 | + } |
| 94 | + |
| 95 | + # Build table rows - show problematic sensors first |
| 96 | + $allSensors = @() |
| 97 | + $allSensors += $nonEnforcingSensors | ForEach-Object { $_ | Add-Member -NotePropertyName 'Priority' -NotePropertyValue 1 -PassThru -Force } |
| 98 | + $allSensors += $enforcingSensors | ForEach-Object { $_ | Add-Member -NotePropertyName 'Priority' -NotePropertyValue 2 -PassThru -Force } |
| 99 | + |
| 100 | + $tableRows = $allSensors | Sort-Object -Property Priority, machineName | ForEach-Object { |
| 101 | + $statusIcon = if ($_.status -eq 'active') { '✅' } else { '❌' } |
| 102 | + $auditModeIcon = if ($_.isAuditMode) { '⚠️ Yes' } else { '✅ No' } |
| 103 | + $machineName = Get-SafeMarkdown $_.machineName |
| 104 | + $version = Get-SafeMarkdown $_.version |
| 105 | + $externalIp = Get-SafeMarkdown $_.externalIp |
| 106 | + |
| 107 | + "| $machineName | $statusIcon $($_.status) | $auditModeIcon | $version | $externalIp |" |
| 108 | + } |
| 109 | + |
| 110 | + $mdInfo += @' |
| 111 | +| Machine name | Status | Audit mode | Version | External IP | |
| 112 | +| :----------- | :----- | :--------- | :------ | :---------- | |
| 113 | +{0} |
| 114 | +
|
| 115 | +'@ -f ($tableRows -join "`n") |
| 116 | + } |
| 117 | + |
| 118 | + # Replace the placeholder with detailed information |
| 119 | + $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $mdInfo |
| 120 | + #endregion Report Generation |
| 121 | + |
| 122 | + $params = @{ |
| 123 | + TestId = '25403' |
| 124 | + Title = 'DC Agent is deployed and enforcing strong authentication policies' |
| 125 | + Status = $passed |
| 126 | + Result = $testResultMarkdown |
| 127 | + } |
| 128 | + |
| 129 | + Add-ZtTestResultDetail @params |
| 130 | +} |
0 commit comments