Repository navigation
feat: add CISA SCuBA Power Platform baseline checks #2799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JeremyFinney-lgtm
wants to merge
9
commits into
maester365:main
Choose a base branch
from
JeremyFinney-lgtm:feat/cisa-powerplatform-baseline-alignment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec50626
feat: add CISA SCuBA Power Platform baseline checks
JeremyFinney-lgtm d7dfba0
fix: address Power Platform PR review feedback
JeremyFinney-lgtm 7f7b9d4
fix: scope environment-level DLP policies, guard tenant mismatch, cle…
JeremyFinney-lgtm 11c6b88
chore: credit reviewer findings on Power Platform tests
JeremyFinney-lgtm bb77e76
Merge upstream main into Power Platform baseline branch
JeremyFinney-lgtm 97b6d2c
fix: escape Power Platform result table values
JeremyFinney-lgtm 3599016
fix: align Power Apps sharing impact metadata
JeremyFinney-lgtm b416a71
fix: avoid passing incomplete Power Platform DLP scope
JeremyFinney-lgtm 7acdf90
docs: clarify Power Platform DLP scope outcomes
JeremyFinney-lgtm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
powershell/internal/checks/cisa/power-platform/Test-MtCisaPowerPlatformDlpPolicyScope.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
46 changes: 46 additions & 0 deletions
46
powershell/internal/checks/cisa/power-platform/Test-MtCisaPowerPlatformTenantIsolation.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
56 changes: 56 additions & 0 deletions
56
powershell/internal/checks/cisa/power-platform/Test-MtCisaPowerPlatformTenantSetting.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
54 changes: 54 additions & 0 deletions
54
powershell/internal/services/power-platform/Get-MtPowerPlatformDlpPolicy.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) { | ||
| $filter = $policy.properties.definition.constraints.environmentFilter1 | ||
| $scope = 'AllEnvironments' | ||
| $environmentNames = @() | ||
| if ($null -ne $filter) { | ||
|
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 | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
powershell/internal/services/power-platform/Get-MtPowerPlatformEnvironment.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
27 changes: 27 additions & 0 deletions
27
powershell/internal/services/power-platform/Get-MtPowerPlatformTenantIsolation.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
24 changes: 24 additions & 0 deletions
24
powershell/internal/services/power-platform/Get-MtPowerPlatformTenantSetting.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.