Skip to content

Commit 66feea3

Browse files
authored
add Infrastructure pillar changes (#1410)
fixes #1408 changes as per microsoft/ztspecs#942
2 parents 8d00863 + 7c880d1 commit 66feea3

4 files changed

Lines changed: 56 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Connect-ZtAssessment
1717
Invoke-ZtAssessment
1818
```
1919

20+
## Infrastructure Pillar Scope
21+
22+
Infrastructure pillar results are based on Microsoft Defender for Cloud recommendations and only include Azure subscriptions tagged with `ZeroTrustAssessment:Infrastructure`.
23+
2024
## Quicklinks
2125

2226
* [aka.ms/zerotrust/assessment](https://aka.ms/zerotrust/assessment) → Microsoft Learn docs page for the assessment (includes install guide).

src/powershell/assets/ReportTemplate.html

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

src/powershell/tests/Test-Assessment.50001.ps1

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
(microsoft.security/securescores/securescorecontrols
4141
+ microsoft.security/assessments
4242
+ microsoft.security/regulatorycompliancestandards/.../regulatorycomplianceassessments)
43+
MDC Query Reference: https://github.com/microsoft/ESA/blob/main/src/MDC.kql
44+
MCSB Query Reference: https://github.com/microsoft/ESA/blob/main/src/MCSB.kql
4345
#>
4446

4547
function Test-Assessment-50001 {
@@ -116,12 +118,49 @@ function Test-Assessment-50001 {
116118

117119
$activity = 'Checking Microsoft Defender for Cloud Recommendations'
118120

119-
Write-ZtProgress -Activity $activity -Status 'Checking Azure connection'
121+
$taggedSubscriptionQuery = @'
122+
resourcecontainers
123+
| where type == 'microsoft.resources/subscriptions'
124+
| where tags['ZeroTrustAssessment'] =~ 'Infrastructure'
125+
| project subscriptionId, subscriptionName = name
126+
'@
127+
128+
Write-ZtProgress -Activity $activity -Status 'Finding subscriptions tagged for Infrastructure scan'
129+
$taggedSubscriptions = @()
130+
try {
131+
$taggedSubscriptions = @(Invoke-ZtAzureResourceGraphRequest -Query $taggedSubscriptionQuery)
132+
Write-PSFMessage "Infrastructure tag query returned $($taggedSubscriptions.Count) subscriptions" -Tag Test -Level VeryVerbose
133+
}
134+
catch {
135+
Write-PSFMessage "Infrastructure tag ARG query failed: $($_.Exception.Message)" -Tag Test -Level Warning
136+
$httpStatusCode = $null
137+
# Invoke-ZtAzureRequestCache throws a string like:
138+
# "Azure REST request failed with status 403: ..."
139+
# so there is no .Response property. Parse the message instead.
140+
if ($_.Exception.Message -match 'with status (\d+):') {
141+
$httpStatusCode = [int]$Matches[1]
142+
}
143+
144+
if ($httpStatusCode -in @(401, 403)) {
145+
Write-PSFMessage "Infrastructure tag ARG query returned (HTTP $httpStatusCode) — insufficient permissions." -Tag Test -Level Warning
146+
Add-ZtTestResultDetail -SkippedBecause NoAzureAccess -Result 'Unable to query tagged subscriptions for Infrastructure scan due to insufficient Azure permissions. Ensure you have Azure Resource Graph read access and the subscriptions are tagged with ZeroTrustAssessment:Infrastructure.'
147+
return
148+
}
149+
Write-PSFMessage "Infrastructure tag ARG query returned (HTTP $httpStatusCode) — unexpected error." -Tag Test -Level Warning
150+
Add-ZtTestResultDetail -SkippedBecause NotSupported -Result 'Unable to query tagged subscriptions for Infrastructure scan due to an Azure Resource Graph error. Ensure Azure Resource Graph access is available and subscriptions are tagged with ZeroTrustAssessment:Infrastructure.'
151+
return
152+
}
153+
154+
[string[]] $taggedSubscriptionIds = @(
155+
$taggedSubscriptions |
156+
Select-Object -ExpandProperty subscriptionId |
157+
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
158+
Sort-Object -Unique
159+
)
120160

121-
$azContext = Get-AzContext -ErrorAction SilentlyContinue
122-
if (-not $azContext) {
123-
Write-PSFMessage 'Not connected to Azure.' -Level Warning
124-
Add-ZtTestResultDetail -SkippedBecause NotConnectedAzure
161+
if ($taggedSubscriptionIds.Count -eq 0) {
162+
Write-PSFMessage 'No subscriptions found with Infrastructure scan tag.' -Tag Test -Level Verbose
163+
Add-ZtTestResultDetail -SkippedBecause NotApplicable -Result 'No subscriptions are tagged for Infrastructure scan. Apply the tag ZeroTrustAssessment:Infrastructure to each subscription that should be included.'
125164
return
126165
}
127166

@@ -350,7 +389,7 @@ securityresources
350389
Write-ZtProgress -Activity $activity -Status 'Querying Azure Resource Graph for secure score recommendations'
351390
$secureScoreRecs = @()
352391
try {
353-
$secureScoreRecs = @(Invoke-ZtAzureResourceGraphRequest -Query $secureScoreQuery)
392+
$secureScoreRecs = @(Invoke-ZtAzureResourceGraphRequest -Query $secureScoreQuery -SubscriptionId $taggedSubscriptionIds)
354393
Write-PSFMessage "Secure Score query returned $($secureScoreRecs.Count) records" -Tag Test -Level VeryVerbose
355394
}
356395
catch {
@@ -360,7 +399,7 @@ securityresources
360399
Write-ZtProgress -Activity $activity -Status 'Querying Azure Resource Graph for MCSB compliance assessments'
361400
$mcsbRecs = @()
362401
try {
363-
$mcsbRecs = @(Invoke-ZtAzureResourceGraphRequest -Query $mcsbQuery)
402+
$mcsbRecs = @(Invoke-ZtAzureResourceGraphRequest -Query $mcsbQuery -SubscriptionId $taggedSubscriptionIds)
364403
Write-PSFMessage "MCSB query returned $($mcsbRecs.Count) records" -Tag Test -Level VeryVerbose
365404
}
366405
catch {

src/report/src/pages/Infrastructure.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function Infrastructure() {
1414
<CardHeader>
1515
<CardTitle className="mb-3">Assessment results</CardTitle>
1616
<CardDescription>
17-
The results below are based on Microsoft Defender for Cloud recommendations identified in the scanned environment.
17+
The results below are based on Microsoft Defender for Cloud recommendations identified in the scanned environment. You must apply the following tag to each Azure subscription which you want to be included in the scan: ZeroTrustAssessment:Infrastructure.
1818
</CardDescription>
1919
</CardHeader>
2020
<CardContent className="gap-4 px-4 pb-4 pt-1">

0 commit comments

Comments
 (0)