Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
525 changes: 525 additions & 0 deletions packs/zero-trust-assessment/helpers/Add-MtZtaObjectFact.ps1

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packs/zero-trust-assessment/maester-pack.guide.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
{ "Name": "ZeroTrustAssessment.Connect", "Default": "none", "Text": "Further Connect-ZtAssessment parameters, for example { \"Service\": [\"Graph\", \"Azure\"], \"UseDeviceCode\": true }." },
{ "Name": "ZeroTrustAssessment.ShowLog", "Default": "true", "Text": "List the tests the assessment runs in its live output." },
{ "Name": "ZeroTrustAssessment.EmbedReport", "Default": "true", "Text": "Embed the assessment's own HTML report in the Maester report." },
{ "Name": "ZeroTrustAssessment.ObjectFacts", "Default": "true", "Text": "Add what the assessment's export says about each app, user, device and policy to the Affected objects page." },
{ "Name": "ZeroTrustAssessment.OutputPath", "Default": "temporary", "Text": "Where the assessment writes its report and export. Kept when set." },
{ "Name": "ZeroTrustAssessment.ReportPath", "Default": "empty", "Text": "Read a report you already have instead of running the assessment." },
{ "Name": "ZeroTrustAssessment.DisableTelemetry", "Default": "true", "Text": "The assessment sends the tenant ID to Microsoft unless this is true." }
Expand Down
1 change: 1 addition & 0 deletions packs/zero-trust-assessment/maester-pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"RequiresMaester": ">=3.0",
"Code": "ZTA",
"Suites": ["tests"],
"Helpers": ["helpers"],
"Catalog": "catalog.json",
"Uses": {
"Services": ["Graph"],
Expand Down
2 changes: 2 additions & 0 deletions packs/zero-trust-assessment/tests/Test.ZTA.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function Get-MtZtaInstance {
}

Add-MtZtaReportAttachment -ReportPath $reportPath
# Facts from the assessment's tenant export for the Affected objects page (helpers/Add-MtZtaObjectFact.ps1).
Add-MtZtaObjectFact -ReportPath $reportPath -Report $report
ConvertTo-MtZtaInstance -Report $report
} finally {
# A collection into a temporary folder leaves nothing behind: the export holds raw tenant data.
Expand Down
1 change: 1 addition & 0 deletions powershell/Maester.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Add-MtAffectedObjectFact',
'Add-MtMaesterAppFederatedCredential',
'Add-MtReportAttachment',
'Add-MtTestResultDetail',
Expand Down
1 change: 1 addition & 0 deletions powershell/Maester.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $__MtSession = @{
ADCredential = $null # Active Directory credential retained only for the connected session
ADCollectionTime = $null # Timestamp of last AD data collection
IncludeAffectedObjects = $false # Set by Invoke-Maester -IncludeAffectedObjects; gates per-test object capture
AffectedObjectFacts = $null # Add-MtAffectedObjectFact: System|Type|Id -> facts about an object, merged into the AffectedObjects
Console = $null # Get-MtConsoleMode result for the current Invoke-Maester run
PackConnections = @{} # Maester Packs: service -> connection state a pack connector set with Set-MtConnectionState
ReportAttachments = $null # Add-MtReportAttachment: reports of other tools embedded in the HTML report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ function Get-MtAffectedObject {
if ($record.DisplayName) { return "name:$($record.DisplayName)" }
return ''
}
# Facts that Add-MtAffectedObjectFact recorded during the run, keyed System|Type|Id. They describe
# objects the run lists: facts about an object that no source found add no record.
$factsByKey = $__MtSession.AffectedObjectFacts
$inventory = $records | Group-Object -Property { "$($_.System)|$($_.Type)|$(& $identityOf $_)" } | ForEach-Object {
$best = $_.Group | Sort-Object {
$rank = $sourceRank[[string]$_.Source]
if ($null -eq $rank) { [int]::MaxValue } else { $rank }
} | Select-Object -First 1
$uniqueId = Get-MtAffectedObjectUniqueId -System $best.System -Type $best.Type -Id (& $identityOf $best)
$facts = $null
if ($factsByKey -and $best.Id) { $null = $factsByKey.TryGetValue("$($best.System)|$($best.Type)|$($best.Id)", [ref]$facts) }
[PSCustomObject]@{
System = $best.System
AnchorKind = $best.AnchorKind
Expand All @@ -135,6 +140,7 @@ function Get-MtAffectedObject {
PortalLink = ($_.Group.PortalLink | Where-Object { $_ } | Select-Object -First 1)
Tests = @($_.Group.TestId | Where-Object { $_ } | Select-Object -Unique)
Sources = @($_.Group.Source | Select-Object -Unique)
Facts = @($facts | Where-Object { $_ })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ function Get-MtAffectedObjectFromMarkdown {
@{ System = 'EntraID'; Type = 'User'; Regex = "UserProfileMenuBlade/~/\w+/userId/($guid)" }
@{ System = 'EntraID'; Type = 'Group'; Regex = "GroupDetailsMenuBlade/~/\w+/groupId/($guid)" }
@{ System = 'EntraID'; Type = 'Device'; Regex = "DeviceDetailsMenuBlade/~/\w+/objectId/($guid)" }
@{ System = 'EntraID'; Type = 'AgentIdentity'; Regex = "AgentIdentity\.MenuView/~/\w+/objectId/($guid)" }
# By appId the link opens the blueprint (an application); by objectId, its service principal.
@{ System = 'EntraID'; Type = 'AgentIdentityBlueprint'; Regex = "AgentBlueprintDetails\.MenuView/~/\w+/appId/($guid)" }
@{ System = 'EntraID'; Type = 'AgentIdentityBlueprintPrincipal'; Regex = "AgentBlueprintDetails\.MenuView/~/\w+/objectId/($guid)" }
@{ System = 'Intune'; Type = 'ConfigurationPolicy'; Regex = "Microsoft_Intune_Workflows/PolicySummaryBlade/policyId/($guid)" }
@{ System = 'EntraID'; Type = 'AccessPackageCatalog'; Regex = "Microsoft_Azure_ELMAdmin/CatalogBlade/catalogId/($guid)" }
@{ System = 'EntraID'; Type = 'AccessPackage'; Regex = "EntitlementMenuBlade/~/overview/entitlementId/($guid)" }
@{ System = 'EntraID'; Type = 'PimAlert'; Regex = "Microsoft_Azure_PIMCommon/AlertDetail/providerId/aadroles/alertId/([^/)\s]+)" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
EntraID = @(
'AccessPackage'
'AccessPackageCatalog'
'AgentIdentity'
'AgentIdentityBlueprint'
'AgentIdentityBlueprintPrincipal'
'AppRegistration'
'AuthenticationMethod'
'AuthorizationPolicy'
Expand All @@ -50,6 +53,9 @@
'SharingPolicy'
'TransportRule'
)
Intune = @(
'ConfigurationPolicy'
)
GitHub = @(
'GitHubOrganization'
'GitHubRepository'
Expand Down
32 changes: 27 additions & 5 deletions powershell/internal/report/affected-objects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Every source normalizes into the same record shape so results can be merged and
| `PortalLink` | Admin-portal deep link when a template exists for the type |
| `Tests` | Test ids (`MT.xxxx`, ...) that referenced the object (aggregated) |
| `Sources` | Which of the three detection sources found it (aggregated) |
| `Facts` | What a pack or test added about the object with `Add-MtAffectedObjectFact` (see [Facts](#facts)); empty if none |

## Anchor kinds

Expand Down Expand Up @@ -105,6 +106,10 @@ pattern acts as a type system:
| `UserProfileMenuBlade/~/*/userId/{guid}` | User |
| `GroupDetailsMenuBlade/~/*/groupId/{guid}` | Group |
| `DeviceDetailsMenuBlade/~/*/objectId/{guid}` | Device |
| `AgentIdentity.MenuView/~/*/objectId/{guid}` | AgentIdentity |
| `AgentBlueprintDetails.MenuView/~/*/appId/{guid}` | AgentIdentityBlueprint |
| `AgentBlueprintDetails.MenuView/~/*/objectId/{guid}` | AgentIdentityBlueprintPrincipal |
| `Microsoft_Intune_Workflows/PolicySummaryBlade/policyId/{guid}` | ConfigurationPolicy (Intune) |
| `Microsoft_Azure_ELMAdmin/CatalogBlade/catalogId/{guid}` | AccessPackageCatalog |
| `EntitlementMenuBlade/~/overview/entitlementId/{guid}` | AccessPackage |
| `Microsoft_Azure_PIMCommon/AlertDetail/.../alertId/{id}` | PimAlert |
Expand Down Expand Up @@ -197,11 +202,11 @@ After the merge, `Select-MtAffectedObjectByType` filters the inventory against t
| `ExcludedTypes` | Recognised types that are deliberately not affected objects. Dropped silently. |
| Everything else | Systems absent from `KnownTypes` (`MicrosoftGraph`) pass through unchanged — their `Type` is a Graph resource path and cannot be enumerated. |

Currently inventoried: `EntraID` — AccessPackage, AccessPackageCatalog, AppRegistration,
AuthenticationMethod, AuthorizationPolicy, ConditionalAccessPolicy, ConsentPolicy, Device,
DirectoryRole, Domains, Group, ServicePrincipal, User; `DefenderXDR` — Device;
`ExchangeOnline` — SharingPolicy, TransportRule; `GitHub` — GitHubOrganization,
GitHubRepository, GitHubResource.
Currently inventoried: `EntraID` — AccessPackage, AccessPackageCatalog, AgentIdentity,
AgentIdentityBlueprint, AgentIdentityBlueprintPrincipal, AppRegistration, AuthenticationMethod, AuthorizationPolicy,
ConditionalAccessPolicy, ConsentPolicy, Device, DirectoryRole, Domains, Group, ServicePrincipal, User;
`DefenderXDR` — Device; `ExchangeOnline` — SharingPolicy, TransportRule; `Intune` —
ConfigurationPolicy; `GitHub` — GitHubOrganization, GitHubRepository, GitHubResource.

Excluded: `EntraID` — `EntraRecommendation`, `PimAlert`. Both describe a condition of the
tenant (a recommendation, an alert), not an addressable object, so they are findings that
Expand All @@ -216,6 +221,23 @@ up as an explicit maintenance item instead of silently reaching the report. Add
`IdentityProtection` objects are the users at risk, so they are recorded as `User`
(`Instance` with a user profile deep link) rather than as the Identity Protection blade.

## Facts

`Add-MtAffectedObjectFact` (exported, so packs and custom tests can call it) records facts about an
object while the run collects affected objects: `Name`, `Value`, `Tone` (`Risk`, `Warning`, `Good` or
`Info`), `Source` and `AsOf`, and optionally a `Key` and `Raw` value for code that reads facts without
parsing their text. The shared keys (`user.mfaRegistered`, `signIn.daysSince`, `device.managed`...) are
listed in `website/docs/writing-tests/formatting-test-results.md` under "Fact keys"; a fact is replaced by
one with the same `Key` (or, without one, the same `Name`) from the same `Source`. They are kept in `$__MtSession.AffectedObjectFacts`, keyed `System|Type|Id`,
and `Get-MtAffectedObject` copies them onto the record with that key. Facts never add a record: an object
no source found is not listed, however much is known about it. The html report embeds the facts of the
objects that have any; the CSV joins them into one `Facts` column.

The Zero Trust Assessment pack is the first source (`packs/zero-trust-assessment/helpers/Add-MtZtaObjectFact.ps1`):
it reads the assessment's tenant export. Keys must match the records: an app registration is keyed by its
appId, as its portal link is, and so is an agent identity blueprint; a blueprint principal is keyed by its
service principal's object id.

## Extending detection

- **New portal deep-link pattern** → add a row to the regex table in
Expand Down
1 change: 1 addition & 0 deletions powershell/internal/session/Clear-ModuleVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Clear-ModuleVariable {
Clear-MtADCache
$__MtSession.AIAgentInfo = $null
$__MtSession.IncludeAffectedObjects = $false
$__MtSession.AffectedObjectFacts = $null
$__MtSession.AzureDevOpsConnectionCache = $null
# Invoke-Maester resets the per-run cache but preserves the existing GitHub session.
# Disconnect-MtGitHub, including through Disconnect-Maester, owns clearing GitHubConnection and GitHubAuthHeader.
Expand Down
14 changes: 13 additions & 1 deletion powershell/public/report/Get-MtHtmlReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# objects files keep the full records.
if ($null -ne $copy.AffectedObjects) {
$copy.AffectedObjects = @($copy.AffectedObjects | ForEach-Object {
[PSCustomObject]@{
$slim = [ordered]@{
System = $_.System
Type = $_.Type
Id = $_.Id
Expand All @@ -109,6 +109,18 @@
Tests = @($_.Tests)
Referenced = [bool](@($_.Sources) | Where-Object { $_ -in 'GraphObjects', 'Markdown' })
}
# Only objects that have facts carry the property, so a report without any stays as small as before.
$facts = @(Get-ObjectProperty $_ 'Facts' | Where-Object { $_ })
if ($facts.Count -gt 0) {
$slim.Facts = @($facts | ForEach-Object {
$fact = [ordered]@{ Name = $_.Name; Value = $_.Value; Tone = $_.Tone; Source = $_.Source; AsOf = $_.AsOf }
# Key and Raw let the report's own summaries read a fact without parsing its text.
$key = Get-ObjectProperty $_ 'Key'
if ($key) { $fact.Key = $key; $fact.Raw = $_.Raw }
[PSCustomObject]$fact
})
}
[PSCustomObject]$slim
})
}
# The report data lists each attachment without its content, which is written into its own element.
Expand Down
Loading
Loading