Skip to content
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

GH Workflow update for Policy Testing #1538

Merged
merged 44 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4f4fd29
Changing when Policy Tests run
Springstone Jan 17, 2024
6b07e62
.
Springstone Jan 17, 2024
a4c3511
test workflow
Springstone Jan 17, 2024
d374a74
Merge branch 'Azure:main' into PolicyTestingUpdate
Springstone Jan 17, 2024
d061c1d
.
Springstone Jan 17, 2024
8f61d3b
.
Springstone Jan 17, 2024
4d6531a
.
Springstone Jan 17, 2024
c965574
.
Springstone Jan 17, 2024
5d7c057
.
Springstone Jan 17, 2024
70a344c
.
Springstone Jan 17, 2024
996e1bc
.
Springstone Jan 17, 2024
945d5d6
.
Springstone Jan 17, 2024
1fa6300
.
Springstone Jan 17, 2024
37d2089
.
Springstone Jan 17, 2024
734d0b3
.
Springstone Jan 17, 2024
67259b2
.
Springstone Jan 17, 2024
2b8fc7f
.
Springstone Jan 17, 2024
165af82
.
Springstone Jan 17, 2024
94a10ac
Merge pull request #5 from Springstone/temptemptemp
Springstone Jan 17, 2024
4a66e83
.
Springstone Jan 17, 2024
1231541
.
Springstone Jan 17, 2024
725b820
.
Springstone Jan 17, 2024
852c92d
.
Springstone Jan 17, 2024
642c694
.
Springstone Jan 17, 2024
3405800
.
Springstone Jan 17, 2024
e96b012
.
Springstone Jan 17, 2024
0face0b
.
Springstone Jan 17, 2024
956aee0
.
Springstone Jan 17, 2024
c0c65b7
.
Springstone Jan 17, 2024
311b8cf
.
Springstone Jan 17, 2024
2f692a1
.
Springstone Jan 17, 2024
5b6dd89
.
Springstone Jan 17, 2024
60a8e34
.
Springstone Jan 17, 2024
147ba55
.
Springstone Jan 17, 2024
0304deb
.
Springstone Jan 17, 2024
661122f
.
Springstone Jan 17, 2024
b4120c3
.
Springstone Jan 17, 2024
2d38c84
.
Springstone Jan 17, 2024
05a410a
.
Springstone Jan 17, 2024
90679fc
.
Springstone Jan 17, 2024
4c0f786
.
Springstone Jan 17, 2024
ab26382
.
Springstone Jan 18, 2024
e9583d6
What's New update
Springstone Jan 18, 2024
d0d4cd1
.
Springstone Jan 18, 2024
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
63 changes: 63 additions & 0 deletions .github/actions-pester/PTF-TestPolicies.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Import-Module -Name $PSScriptRoot\PolicyPesterTestHelper.psm1 -Force -Verbose
Import-Module Pester -Force

function RunPester
{
param (
[Parameter()]
[String]$PolicyTest
)

$pesterConfiguration = @{
Run = @{
Container = New-PesterContainer -Path $PolicyTest
PassThru = $true
}
Output = @{
Verbosity = 'Detailed'
CIFormat = 'Auto'
}
}
$result = Invoke-Pester -Configuration $pesterConfiguration
#exit $result.FailedCount
}

$ModifiedFiles = @(Get-PolicyFiles -DiffFilter "M")
if ([String]::IsNullOrEmpty($ModifiedFiles))
{
Write-Warning "These are the modified policies: $($ModifiedFiles)"
}
else
{
Write-Warning "There are no modified policies"
}

$AddedFiles = @(Get-PolicyFiles -DiffFilter "A")
if ([String]::IsNullOrEmpty($AddedFiles))
{
Write-Warning "These are the added policies: $($AddedFiles)"
}
else
{
Write-Warning "There are no added policies"
}

$ModifiedAddedFiles = $ModifiedFiles + $AddedFiles

$ModifiedAddedFiles | ForEach-Object {

$PolicyFile = Split-Path $_ -Leaf
$PolicyFileClean = $PolicyFile -replace ".json", ""

$testPath = "tests/policy/$($PolicyFileClean).Tests.ps1"

if (Test-Path $testPath)
{
Write-Warning "Running pester tests on $PolicyFileClean"
RunPester($testPath)
}
else
{
Write-Warning "There are no tests for $PolicyFileClean"
}
}
22 changes: 7 additions & 15 deletions .github/workflows/test-portal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ env:
GITHUB_PR_ID: ${{ github.event.pull_request.id }}
TEMP_SUBSCRIPTIONS_JSON_PATH: "./src/data/subscriptions.json"
TEMP_DEPLOYMENT_OBJECT_PATH: "./src/data/eslzArm.test.deployment.json"
POLICY_DIR: "src/resources/Microsoft.Authorization/policyDefinitions"
POLICYSET_DIR: "src/resources/Microsoft.Authorization/policySetDefinitions"

permissions:
contents: read
Expand Down Expand Up @@ -149,21 +151,11 @@ jobs:
Update-AzConfig -DisplayBreakingChangeWarning $false

- name: Pester Test for Policies
shell: pwsh
run: |
Import-Module Pester -Force
$pesterConfiguration = @{
Run = @{
Path = "tests/*.tests.ps1"
PassThru = $true
}
Output = @{
Verbosity = 'Detailed'
CIFormat = 'Auto'
}
}
$result = Invoke-Pester -Configuration $pesterConfiguration
exit $result.FailedCount
uses: azure/powershell@v1
with:
inlineScript: |
./.github/actions-pester/PTF-TestPolicies.ps1
azPSVersion: "latest"
env:
SUBSCRIPTION_ID: ${{ secrets.AZURE_POLICY_SUBSCRIPTION1_ID }}
SUBSCRIPTION2_ID: ${{ secrets.AZURE_POLICY_SUBSCRIPTION2_ID }} #Used for policy tests that require a second subscription (e.g. cross subscription peering)
Expand Down
1 change: 1 addition & 0 deletions docs/wiki/Whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Here's what's changed in Enterprise Scale/Azure Landing Zones:
- Bug fix for Portal Accelerator, removing region restrictions for VPN Gateways when deploying regional (not AZ).
- Bug fix for Portal Accelerator deployment when deploying using a single platform subscription. Previously, a single tenant deployment would have three failed deployments for diagnostic settings which were looking for non-existent management groups (Management, Identity and Connectivity). This has been fixed and the deployment will now succeed.
- Added drop down selection option for Azure Private Link Private DNS Zones as part of portal based ALZ deployment experience where you can select to deploy or not to deploy a subset of Private Link Private DNS zones.
- Updated ALZ policy testing framework on pull request to only test new or changed policies, drastically speeding up the testing process.

### December 2023

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"policyType": "Custom",
"mode": "All",
"displayName": "Management port access from the Internet should be blocked",
"description": "This policy denies any network security rule that allows management port access from the Internet",
"description": "This policy denies any network security rule that allows management port access from the Internet, by default blocking SSH/RDP ports.",
"metadata": {
"version": "2.1.0",
"version": "2.1.1",
"category": "Network",
"source": "https://github.com/Azure/Enterprise-Scale/",
"replacesPolicy": "Deny-RDP-From-Internet",
Expand Down Expand Up @@ -252,4 +252,4 @@
}
}
}
}
}
Loading