Skip to content
Open
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enforces them. When writing or reviewing a change, check every added, moved or r
(`global-secure-access`, not `GlobalSecureAccess`). No two paths may differ only in case.
- One name per service, the same everywhere: `ad`, `azure`, `azure-devops`, `copilot`,
`copilot-studio`, `defender`, `entra`, `exchange`, `fabric`, `foundry`, `github`,
`global-secure-access`, `graph`, `intune`, `purview`, `sharepoint`, `teams`, `xspm`.
`global-secure-access`, `graph`, `intune`, `power-platform`, `purview`, `sharepoint`, `teams`, `xspm`.
Folders name the product whose settings a check reads, never a theme: an AI check goes in
the folder of its product (an Entra agent identity check in `entra/`) and declares
`Area = 'ai'`. A new service must be added to the guide and the test.
Expand Down
1 change: 1 addition & 0 deletions powershell/Maester.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $__MtSession = @{
DataverseEnvironmentId = $null # Environment identifier for display (e.g. org123.crm.dynamics.com)
SpoCache = @{} # Cache for SharePoint Online tenant settings retrieved via PnP
FabricCache = @{} # Fabric admin API data cached for the current test run
PowerPlatformCache = @{} # Power Platform admin API data cached for the current test run
GitHubCache = @{} # Per-session REST response cache; cleared each Invoke-Maester run
ADCache = @{} # Active Directory data cache
ADConnection = $null # Active Directory connection state
Expand Down
12 changes: 12 additions & 0 deletions powershell/assets/MaesterTaxonomy.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@
@{ Key = 'tenant-settings'; Name = 'Tenant settings' }
)
}
@{
Key = 'power-platform'
Name = 'Power Platform'
Aliases = @('Power Platform', 'Power Apps', 'Power Automate', 'Power Pages')
Features = @(
@{ Key = 'environments'; Name = 'Environments' }
@{ Key = 'data-policies'; Name = 'Data policies' }
@{ Key = 'tenant-isolation'; Name = 'Tenant isolation' }
@{ Key = 'power-apps'; Name = 'Power Apps' }
@{ Key = 'power-pages'; Name = 'Power Pages' }
)
}
@{
Key = 'microsoft-365'
Name = 'Microsoft 365'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function Test-MtCisaPowerPlatformDlpPolicyScope {
<#
.SYNOPSIS
Evaluates whether Power Platform data loss prevention (DLP) policies cover the environments a CISA SCuBA check names.

.DESCRIPTION
Follows the ScubaGear audit for MS.POWERPLATFORM.2.1 and MS.POWERPLATFORM.2.2.
A policy covers an environment when its scope is all environments, when it names the environment in an
OnlyEnvironments scope, or when it excludes other environments but not this one.
DefaultEnvironment passes when at least one policy covers the default environment.
NonDefaultEnvironment passes when a policy applies to all environments. Otherwise, the returned inventory cannot
prove that every non-default environment is covered, so apparent complete coverage requires investigation.

.EXAMPLE
Test-MtCisaPowerPlatformDlpPolicyScope -Scope DefaultEnvironment

Returns true when a DLP policy applies to the default environment.
#>
[CmdletBinding()]
[OutputType([bool])]
param(
# DefaultEnvironment checks the default environment; NonDefaultEnvironment checks every other environment.
[Parameter(Mandatory)]
[ValidateSet('DefaultEnvironment', 'NonDefaultEnvironment')]
[string] $Scope
)

$environments = @(Get-MtPowerPlatformEnvironment)
$policies = @(Get-MtPowerPlatformDlpPolicy)
$defaultEnvironments = @($environments | Where-Object { $_.IsDefault })
if ($defaultEnvironments.Count -ne 1) {
throw "Expected exactly one default Power Platform environment; received $($defaultEnvironments.Count)."
}

$covers = {
param($Policy, $EnvironmentName)
switch ($Policy.Scope) {
'AllEnvironments' { $true }
'OnlyEnvironments' { $Policy.Environments -contains $EnvironmentName }
default { $Policy.Environments -notcontains $EnvironmentName }
}
}

$defaultName = $defaultEnvironments[0].Name
$investigate = $false
if ($Scope -eq 'DefaultEnvironment') {
$coveringPolicies = @($policies | Where-Object { & $covers $_ $defaultName })
$checkResult = $coveringPolicies.Count -gt 0

if ($checkResult) {
$message = 'Well done. At least one DLP policy applies to the default Power Platform environment.'
}
elseif ($policies.Count -eq 0) {
$message = 'No Power Platform DLP policy exists. Create a policy that restricts connectors in the default environment.'
}
else {
$message = 'No Power Platform DLP policy applies to the default environment. Add the default environment to a DLP policy scope.'
}

$resultMd = "| Policy | Scope | Covers default environment |`n"
$resultMd += "| --- | --- | --- |`n"
foreach ($policy in $policies) {
$covered = if (& $covers $policy $defaultName) { 'Yes' } else { 'No' }
$resultMd += "| $(Get-MtSafeMarkdown $policy.DisplayName) | $(Get-MtSafeMarkdown $policy.Scope) | $covered |`n"
}
}
else {
$nonDefaultEnvironments = @($environments | Where-Object { -not $_.IsDefault })
$allEnvironmentPolicies = @($policies | Where-Object { $_.Scope -eq 'AllEnvironments' })
$uncovered = @($nonDefaultEnvironments | Where-Object {
$environment = $_
-not ($policies | Where-Object { & $covers $_ $environment.Name })
})
# The admin API does not indicate whether this inventory is complete for the tenant.
$environmentInventoryComplete = $false
$checkResult = $allEnvironmentPolicies.Count -gt 0 -or ($environmentInventoryComplete -and $uncovered.Count -eq 0)
$investigate = -not $environmentInventoryComplete -and $allEnvironmentPolicies.Count -eq 0 -and $uncovered.Count -eq 0

if ($allEnvironmentPolicies.Count -gt 0) {
$message = 'Well done. At least one DLP policy applies to all Power Platform environments.'
}
elseif ($investigate) {
$message = 'Unable to verify that the returned environment inventory is complete for the tenant. Confirm the full inventory with a tenant-wide Power Platform administrator.'
}
else {
$message = 'Some non-default Power Platform environments are not covered by any DLP policy. Add them to a DLP policy scope.'
}

$resultMd = "| Environment | Type | Covered by a DLP policy |`n"
$resultMd += "| --- | --- | --- |`n"
foreach ($environment in $nonDefaultEnvironments) {
$covered = if ($environment -in $uncovered) { 'No' } else { 'Yes' }
$resultMd += "| $(Get-MtSafeMarkdown $environment.DisplayName) | $(Get-MtSafeMarkdown $environment.EnvironmentType) | $covered |`n"
}
}

Add-MtTestResultDetail -Result "$message`n`n$resultMd" -Investigate:$investigate
return $checkResult
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function Test-MtCisaPowerPlatformTenantIsolation {
<#
.SYNOPSIS
Evaluates whether Power Platform tenant isolation is enabled.

.DESCRIPTION
Follows the ScubaGear audit for MS.POWERPLATFORM.3.1: the tenant isolation policy must exist and its isDisabled
property must be false. A tenant that has never configured the policy fails.

.EXAMPLE
Test-MtCisaPowerPlatformTenantIsolation

Returns true when Power Platform tenant isolation is enabled.
#>
[CmdletBinding()]
[OutputType([bool])]
param()

$policy = Get-MtPowerPlatformTenantIsolation
if ($null -eq $policy) {
Add-MtTestResultDetail -Result 'The Power Platform tenant isolation policy has never been configured in this tenant, so cross-tenant connections are not restricted.'
return $false
}

$isDisabledProperty = if ($null -eq $policy.properties) { $null } else { $policy.properties.PSObject.Properties['isDisabled'] }
if ($null -eq $isDisabledProperty -or $isDisabledProperty.Value -isnot [bool]) {
throw 'The Power Platform tenant isolation policy did not include a Boolean isDisabled value.'
}

$testResult = -not $isDisabledProperty.Value
$enabledText = if ($testResult) { 'On' } else { 'Off' }
$resultText = if ($testResult) { 'Pass' } else { 'Fail' }
$resultMd = "| Setting | Value | Result |`n"
$resultMd += "| --- | --- | --- |`n"
$resultMd += "| Restrict cross-tenant connections | $enabledText | $resultText |`n"

if ($testResult) {
$message = 'Well done. Power Platform tenant isolation is enabled.'
}
else {
$message = 'Power Platform tenant isolation is disabled, so cross-tenant connections are not restricted.'
}

Add-MtTestResultDetail -Result "$message`n`n$resultMd"
return $testResult
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function Test-MtCisaPowerPlatformTenantSetting {
<#
.SYNOPSIS
Evaluates a Power Platform tenant setting that must be true for a CISA SCuBA check.

.DESCRIPTION
Reads one Boolean tenant setting from the Power Platform admin API, records the observed value, and returns true
when it is true. A missing or non-Boolean value is an error rather than a failed audit, because the baseline cannot
be assessed without it.

.EXAMPLE
Test-MtCisaPowerPlatformTenantSetting -SettingName 'disableEnvironmentCreationByNonAdminUsers' -SettingTitle 'Production and sandbox environment creation is restricted to administrators'

Returns true when only administrators can create production and sandbox environments.
#>
[CmdletBinding()]
[OutputType([bool])]
param(
# Dot-separated path of the Boolean tenant setting, for example powerPlatform.powerApps.disableShareWithEveryone.
[Parameter(Mandatory)]
[string] $SettingName,

# Sentence-style description of the restriction the setting enforces, without a trailing period.
[Parameter(Mandatory)]
[string] $SettingTitle
)

$value = Get-MtPowerPlatformTenantSetting
foreach ($segment in $SettingName.Split('.')) {
$property = if ($null -eq $value) { $null } else { $value.PSObject.Properties[$segment] }
if ($null -eq $property) {
throw "Power Platform tenant setting '$SettingName' was not returned by the tenant settings API."
}

$value = $property.Value
}

if ($value -isnot [bool]) {
throw "Power Platform tenant setting '$SettingName' did not have a Boolean value."
}

$resultText = if ($value) { 'Pass' } else { 'Fail' }
$resultMd = "| Setting | Value | Result |`n"
$resultMd += "| --- | --- | --- |`n"
$resultMd += "| ``$SettingName`` | $value | $resultText |`n"

if ($value) {
$message = "Well done. $SettingTitle."
}
else {
$message = "$SettingTitle is not enforced. Set ``$SettingName`` to ``true``."
}

Add-MtTestResultDetail -Result "$message`n`n$resultMd"
return $value
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function Get-MtPowerPlatformDlpPolicy {
<#
.SYNOPSIS
Retrieves the Power Platform data loss prevention (DLP) policies.

.DESCRIPTION
Returns one object per policy with its scope: AllEnvironments, OnlyEnvironments or ExceptEnvironments, and the
names of the environments the scope lists, cached for the current test run. The API lists tenant-level and
environment-level policies together. A policy stored under an environment is scoped to that environment only; a
tenant-level policy without an environment filter applies to every environment.
#>
[CmdletBinding()]
[OutputType([object[]])]
param()

if ($__MtSession.PowerPlatformCache.ContainsKey('DlpPolicies')) {
return $__MtSession.PowerPlatformCache['DlpPolicies']
}

$response = Invoke-MtPowerPlatformRequest -RelativeUri '/providers/Microsoft.BusinessAppPlatform/scopes/admin/apiPolicies?api-version=2016-11-01'
if ($null -eq $response -or $null -eq $response.PSObject.Properties['value']) {
throw 'The Power Platform data policy API did not return a policy collection.'
}

$policies = @(foreach ($policy in @($response.value)) {
Comment thread
JeremyFinney-lgtm marked this conversation as resolved.
Resolved
$filter = $policy.properties.definition.constraints.environmentFilter1
$scope = 'AllEnvironments'
$environmentNames = @()
if ($null -ne $filter) {
Comment thread
JeremyFinney-lgtm marked this conversation as resolved.
Resolved
if ($filter.parameters.filterType -eq 'include') {
$scope = 'OnlyEnvironments'
}
else {
$scope = 'ExceptEnvironments'
}

$environmentNames = @($filter.parameters.environments | Where-Object { $_ } | ForEach-Object { $_.name })
}
elseif ($policy.id -match '/environments/(?<environment>[^/]+)/apiPolicies/') {
$scope = 'OnlyEnvironments'
$environmentNames = @($Matches['environment'])
}

[pscustomobject]@{
Name = $policy.name
DisplayName = $policy.properties.displayName
Scope = $scope
Environments = $environmentNames
}
})

$__MtSession.PowerPlatformCache['DlpPolicies'] = $policies
return $policies
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Get-MtPowerPlatformEnvironment {
<#
.SYNOPSIS
Retrieves the Power Platform environments of the tenant.

.DESCRIPTION
Returns one object per environment with its name, display name, type and whether it is the default environment,
cached for the current test run.
#>
[CmdletBinding()]
[OutputType([object[]])]
param()

if ($__MtSession.PowerPlatformCache.ContainsKey('Environments')) {
return $__MtSession.PowerPlatformCache['Environments']
}

$response = Invoke-MtPowerPlatformRequest -RelativeUri '/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments?api-version=2023-06-01'
$environments = @(foreach ($environment in @($response.value)) {
[pscustomobject]@{
Name = $environment.name
DisplayName = $environment.properties.displayName
IsDefault = $environment.properties.isDefault -eq $true
EnvironmentType = $environment.properties.environmentSku
}
})

$__MtSession.PowerPlatformCache['Environments'] = $environments
return $environments
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Get-MtPowerPlatformTenantIsolation {
<#
.SYNOPSIS
Retrieves the Power Platform tenant isolation policy.

.DESCRIPTION
Returns the tenant isolation policy of the signed-in tenant, cached for the current test run. Returns $null when the
policy has never been configured.
#>
[CmdletBinding()]
[OutputType([object])]
param()

if ($__MtSession.PowerPlatformCache.ContainsKey('TenantIsolation')) {
return $__MtSession.PowerPlatformCache['TenantIsolation']
}

$tenantId = (Get-AzContext -ErrorAction Stop).Tenant.Id
$policy = Invoke-MtPowerPlatformRequest -RelativeUri "/providers/PowerPlatform.Governance/v1/tenants/$tenantId/tenantIsolationPolicy?api-version=2020-06-01"
# Windows PowerShell keeps a null response body as the text "null".
if ($policy -is [string]) {
$policy = $null
}

$__MtSession.PowerPlatformCache['TenantIsolation'] = $policy
return $policy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Get-MtPowerPlatformTenantSetting {
<#
.SYNOPSIS
Retrieves the Power Platform tenant settings.

.DESCRIPTION
Returns the tenant settings object of the Power Platform admin API, cached for the current test run.
#>
[CmdletBinding()]
[OutputType([object])]
param()

if ($__MtSession.PowerPlatformCache.ContainsKey('TenantSettings')) {
return $__MtSession.PowerPlatformCache['TenantSettings']
}

$settings = Invoke-MtPowerPlatformRequest -Method Post -RelativeUri '/providers/Microsoft.BusinessAppPlatform/listTenantSettings?api-version=2023-06-01'
if ($null -eq $settings) {
throw 'The Power Platform admin API returned no tenant settings.'
}

$__MtSession.PowerPlatformCache['TenantSettings'] = $settings
return $settings
}
Loading
Loading