From 6720444789e4322703d668e75d5a8049f83211c7 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sat, 31 Oct 2026 19:01:59 -0600 Subject: [PATCH 01/10] feat: add monthly agent blocked permissions snapshot automation Adds build script, drift test, and GitHub Actions workflow that snapshots Microsoft's agent blocked permissions list monthly and opens a PR when it drifts from MT.1223's curated list. Part of #2233 (point 4) Co-Authored-By: Claude Opus 4.6 --- .../update-agent-blocked-permissions.yaml | 137 ++++++++++++++++ build/Update-MtAgentBlockedPermissions.ps1 | 152 ++++++++++++++++++ .../AgentBlockedPermissionDrift.Tests.ps1 | 55 +++++++ 3 files changed, 344 insertions(+) create mode 100644 .github/workflows/update-agent-blocked-permissions.yaml create mode 100644 build/Update-MtAgentBlockedPermissions.ps1 create mode 100644 powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 diff --git a/.github/workflows/update-agent-blocked-permissions.yaml b/.github/workflows/update-agent-blocked-permissions.yaml new file mode 100644 index 0000000000..8665848808 --- /dev/null +++ b/.github/workflows/update-agent-blocked-permissions.yaml @@ -0,0 +1,137 @@ +--- +name: update-agent-blocked-permissions + +on: + schedule: + - cron: "0 8 10 * *" # Monthly on the 10th at 08:00 UTC + workflow_dispatch: + +permissions: {} + +concurrency: + group: update-agent-blocked-permissions + cancel-in-progress: false + +env: + SNAPSHOT_PATH: powershell/internal/data/AgentBlockedPermissions.json + +jobs: + update-agent-blocked-permissions: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Update agent blocked permissions snapshot + shell: pwsh + run: ./build/Update-MtAgentBlockedPermissions.ps1 -Verbose + + - name: Summarize snapshot changes + id: diff + shell: pwsh + run: | + $ErrorActionPreference = 'Stop' + + $diff = @(git diff --unified=0 -- $env:SNAPSHOT_PATH) + if ($diff.Count -eq 0) { + Write-Host 'No changes to the blocked permissions snapshot.' + 'changed=false' | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + exit 0 + } + + $newSnapshot = Get-Content -LiteralPath $env:SNAPSHOT_PATH -Raw | ConvertFrom-Json + $newPerms = @{} + foreach ($p in $newSnapshot.Permissions) { + $newPerms[$p.Permission] = $p + } + + $addedPattern = '^\+\s*"Permission":\s*"(.+)"' + $removedPattern = '^-\s*"Permission":\s*"(.+)"' + + $addedNames = @($diff | Select-String -Pattern $addedPattern | ForEach-Object { $_.Matches[0].Groups[1].Value }) + $removedNames = @($diff | Select-String -Pattern $removedPattern | ForEach-Object { $_.Matches[0].Groups[1].Value }) + + $trulyAdded = @($addedNames | Where-Object { $_ -notin $removedNames } | Sort-Object) + $trulyRemoved = @($removedNames | Where-Object { $_ -notin $addedNames } | Sort-Object) + + $lines = [System.Collections.Generic.List[string]]::new() + $lines.Add("| Change | Permissions |") + $lines.Add("| --- | --- |") + $lines.Add("| Added | $($trulyAdded.Count) |") + $lines.Add("| Removed | $($trulyRemoved.Count) |") + $lines.Add("| New total | $($newSnapshot.Count) |") + $lines.Add('') + + if ($trulyAdded.Count -gt 0) { + $lines.Add('### Newly blocked permissions') + $lines.Add('') + $lines.Add('Microsoft now blocks these for agents. If any appear in MT.1223''s curated list, the check is watching a permission that can no longer fire.') + $lines.Add('') + foreach ($name in $trulyAdded) { + $lines.Add("- ``$name``") + } + $lines.Add('') + } + + if ($trulyRemoved.Count -gt 0) { + $lines.Add('### Unblocked permissions') + $lines.Add('') + $lines.Add('Microsoft removed the block on these. Agents can now hold them. Evaluate whether any are dangerous enough to add to MT.1223.') + $lines.Add('') + foreach ($name in $trulyRemoved) { + $lines.Add("- ``$name``") + } + $lines.Add('') + } + + $summary = $lines -join "`n" + Write-Host $summary + $summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8 + + $delimiter = "DIFF_$(New-Guid)" + "changed=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + "diff_summary<<$delimiter`n$summary`n$delimiter" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + + - name: Generate maester-bot app token + id: app-token + if: steps.diff.outputs.changed == 'true' + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + app-id: ${{ secrets.MAESTER_BOT_APP_ID }} + private-key: ${{ secrets.MAESTER_BOT_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + + - name: Create Pull Request + if: steps.diff.outputs.changed == 'true' + uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 + with: + token: ${{ steps.app-token.outputs.token }} + commit-message: "chore: update agent blocked permissions snapshot" + branch: "automation/update-agent-blocked-permissions" + delete-branch: true + title: "chore: update agent blocked permissions snapshot" + body: | + Refreshes `powershell/internal/data/AgentBlockedPermissions.json` from + Microsoft's [agent identity platform overview](https://learn.microsoft.com/en-us/graph/api/resources/agentid-platform-overview) + documentation. + + Why this matters in Maester: + - `AgentBlockedPermissionDrift.Tests.ps1` compares MT.1223's curated list of high-risk + agent permissions against this snapshot. If Microsoft blocks a permission that MT.1223 + watches for, the test fails so someone can remove the dead entry. + - Newly unblocked permissions may be dangerous enough to add to MT.1223. + + ## Diff summary + + ${{ steps.diff.outputs.diff_summary }} + + Reviewer note: + - **Newly blocked** permissions that overlap with MT.1223 need to be removed from + `Get-MtEntraAgentHighRiskGraphPermissionFinding` because agents can no longer hold them. + - **Unblocked** permissions need a judgment call on whether they belong in MT.1223. + labels: automation diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 new file mode 100644 index 0000000000..e78c299809 --- /dev/null +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -0,0 +1,152 @@ +<# + .SYNOPSIS + Updates the checked-in snapshot of Microsoft Graph permissions blocked for agent identities. + + .DESCRIPTION + Downloads Microsoft's agentid-platform-overview.md from the public docs repo, + parses the "Microsoft Graph permissions blocked for agents" table, validates the + result, and writes a JSON snapshot into the module's internal data folder. + The update-agent-blocked-permissions workflow runs this monthly and raises a pull + request when the table changes. + For reproducibility, pass a commit-pinned raw URL with -SourceUrl. + + .EXAMPLE + ./build/Update-MtAgentBlockedPermissions.ps1 +#> + +[CmdletBinding()] +param ( + # Path to the generated JSON snapshot. + [string] $SnapshotPath = "$PSScriptRoot/../powershell/internal/data/AgentBlockedPermissions.json", + + # Raw URL of Microsoft's agent ID platform overview page. + [string] $SourceUrl = 'https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/v1.0/resources/agentid-platform-overview.md', + + # Minimum expected row count. The table has 57 rows today. + [int] $MinimumRowCount = 50 +) + +$ErrorActionPreference = 'Stop' + +# --- Download --- + +Write-Verbose "Downloading agent blocked permissions from $SourceUrl..." +try { + $response = Invoke-WebRequest -Uri $SourceUrl -UseBasicParsing -ErrorAction Stop +} catch { + throw "Failed to download agent permissions doc from $SourceUrl. Error: $_" +} + +if ($response.StatusCode -ne 200) { + throw "Unexpected HTTP status code $($response.StatusCode) from $SourceUrl" +} + +$content = $response.Content +if ([string]::IsNullOrWhiteSpace($content) -or $content.Length -lt 1000) { + throw "Downloaded content appears empty or too short ($($content.Length) chars). Aborting." +} + +# --- Find the table --- + +$lines = $content -split "`n" +$tableStartIndex = -1 +for ($i = 0; $i -lt $lines.Count; $i++) { + if ($lines[$i] -match '^\|\s*Permission name\s*\|') { + $tableStartIndex = $i + break + } +} + +if ($tableStartIndex -lt 0) { + throw "Could not find the 'Permission name' table header in the downloaded markdown. Microsoft may have renamed or moved the section." +} + +# --- Parse rows --- + +$permissions = [System.Collections.Generic.List[hashtable]]::new() + +# Skip the header row and the separator row (the |---|---|---| line) +for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { + $line = $lines[$i].Trim() + + # Stop at the first non-table line + if (-not $line.StartsWith('|')) { break } + + # Split on | and trim. The split gives us empty strings at the start and end. + $cells = $line -split '\|' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' } + + if ($cells.Count -lt 3) { continue } + + # Column 0: permission name (may be a markdown link like [Name](url)) + $permName = $cells[0] + if ($permName -match '^\[([^\]]+)\]') { + $permName = $Matches[1] + } + $permName = $permName.Trim() + + # Column 1: Delegated, Column 2: Application + # The values use symbols, not words, but handle both + $delegated = $cells[1] -match ([regex]::Escape([char]0x274C)) # ❌ + $application = $cells[2] -match ([regex]::Escape([char]0x274C)) # ❌ + + if ([string]::IsNullOrWhiteSpace($permName)) { continue } + + $permissions.Add(@{ + Permission = $permName + Delegated = $delegated + Application = $application + }) +} + +# --- Validate --- + +if ($permissions.Count -lt $MinimumRowCount) { + throw "Only $($permissions.Count) permissions parsed; expected at least $MinimumRowCount. The table format may have changed." +} + +Write-Verbose "Parsed $($permissions.Count) blocked permissions." + +# --- Hash the source for traceability --- + +$sourceBytes = [System.Text.Encoding]::UTF8.GetBytes($content) +$sha256 = [System.Security.Cryptography.SHA256]::Create() +try { + $sourceHash = (-join ($sha256.ComputeHash($sourceBytes) | ForEach-Object { $_.ToString('x2') })) +} finally { + $sha256.Dispose() +} + +# --- Build output --- + +$output = [ordered]@{ + SourceUrl = $SourceUrl + SourceSha256 = $sourceHash + GeneratedAt = (Get-Date -Format 'o') + Count = $permissions.Count + Permissions = @($permissions | Sort-Object { $_.Permission } | ForEach-Object { + [ordered]@{ + Permission = $_.Permission + Delegated = $_.Delegated + Application = $_.Application + } + }) +} + +# --- Write --- + +$resolvedPath = $SnapshotPath +if (Test-Path -LiteralPath $SnapshotPath) { + $resolvedPath = (Resolve-Path -LiteralPath $SnapshotPath).ProviderPath +} else { + $parent = Split-Path -Parent $SnapshotPath + if (-not (Test-Path -LiteralPath $parent)) { + New-Item -ItemType Directory -Path $parent -Force | Out-Null + } + $resolvedPath = [System.IO.Path]::GetFullPath($SnapshotPath) +} + +$json = $output | ConvertTo-Json -Depth 5 +$utf8NoBom = [System.Text.UTF8Encoding]::new($false) +[System.IO.File]::WriteAllText($resolvedPath, $json + "`n", $utf8NoBom) + +Write-Verbose "Updated $resolvedPath with $($permissions.Count) permissions; source SHA-256: $sourceHash" diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 new file mode 100644 index 0000000000..b90aad86fb --- /dev/null +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -0,0 +1,55 @@ +BeforeDiscovery { + $snapshotPath = Join-Path $PSScriptRoot '../../internal/data/AgentBlockedPermissions.json' + if (-not (Test-Path -LiteralPath $snapshotPath)) { + throw "AgentBlockedPermissions.json not found at $snapshotPath. Run build/Update-MtAgentBlockedPermissions.ps1 first." + } + + $snapshot = Get-Content -LiteralPath $snapshotPath -Raw | ConvertFrom-Json + $script:BlockedPermissions = $snapshot.Permissions + + # MT.1223's curated list from Get-MtEntraAgentHighRiskGraphPermissionFinding.ps1. + # These are the permissions the check looks for on agent identities. + # If Microsoft blocks any of these for agents, the permission is dead weight in the check. + $script:Mt1223Permissions = @( + 'AdministrativeUnit.ReadWrite.All' + 'Application.ReadUpdate.All' + 'DeviceManagementConfiguration.ReadWrite.All' + 'DeviceManagementRBAC.ReadWrite.All' + 'Policy.ReadWrite.ConditionalAccess' + 'PrivilegedAccess.ReadWrite.AzureADGroup' + 'PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup' + 'PrivilegedEligibilitySchedule.ReadWrite.AzureADGroup' + 'RoleAssignmentSchedule.ReadWrite.Directory' + 'RoleEligibilitySchedule.ReadWrite.Directory' + 'RoleManagementPolicy.ReadWrite.AzureADGroup' + 'RoleManagementPolicy.ReadWrite.Directory' + ) +} + +Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { + + BeforeAll { + $snapshotPath = Join-Path $PSScriptRoot '../../internal/data/AgentBlockedPermissions.json' + $snapshot = Get-Content -LiteralPath $snapshotPath -Raw | ConvertFrom-Json + $script:BlockedPermissions = $snapshot.Permissions + } + + It 'Snapshot file should have at least 50 permissions' { + $script:BlockedPermissions.Count | Should -BeGreaterOrEqual 50 + } + + It ' should not be blocked for Application in the snapshot' -ForEach @( + $script:Mt1223Permissions | ForEach-Object { @{ Permission = $_ } } + ) { + $entry = $script:BlockedPermissions | Where-Object { $_.Permission -eq $permission } + if ($null -eq $entry) { + # Permission isn't in the blocked list at all, which means it's grantable. Pass. + $true | Should -BeTrue + } else { + # If it IS in the blocked list with Application = true, it can't be granted to agents. + # That means MT.1223 is checking a permission that can never fire. + $entry.Application | Should -BeFalse -Because ` + "'$permission' is now blocked for Application by Microsoft (per AgentBlockedPermissions.json). It should be removed from MT.1223's curated list because agents can no longer hold it." + } + } +} From 3c8ea4cd475116361783595de1645ed987ccfc93 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sat, 31 Oct 2026 19:46:28 -0600 Subject: [PATCH 02/10] fix: address CI failure and CodeRabbit findings --- .../update-agent-blocked-permissions.yaml | 32 ++ build/Update-MtAgentBlockedPermissions.ps1 | 20 +- .../data/AgentBlockedPermissions.json | 302 ++++++++++++++++++ .../AgentBlockedPermissionDrift.Tests.ps1 | 24 +- 4 files changed, 369 insertions(+), 9 deletions(-) create mode 100644 powershell/internal/data/AgentBlockedPermissions.json diff --git a/.github/workflows/update-agent-blocked-permissions.yaml b/.github/workflows/update-agent-blocked-permissions.yaml index 8665848808..3f044e9c6d 100644 --- a/.github/workflows/update-agent-blocked-permissions.yaml +++ b/.github/workflows/update-agent-blocked-permissions.yaml @@ -36,6 +36,37 @@ jobs: run: | $ErrorActionPreference = 'Stop' + # Check whether git already tracks this file. On the very first run + # after the automation is merged, the snapshot won't be in git yet. + # In that case every permission is "new", so we treat the entire file + # as an addition. + $tracked = git ls-files -- $env:SNAPSHOT_PATH + if (-not $tracked) { + Write-Host 'Snapshot file is new (first run). Treating entire file as a change.' + $newSnapshot = Get-Content -LiteralPath $env:SNAPSHOT_PATH -Raw | ConvertFrom-Json + + $lines = [System.Collections.Generic.List[string]]::new() + $lines.Add("| Change | Permissions |") + $lines.Add("| --- | --- |") + $lines.Add("| Added | $($newSnapshot.Count) |") + $lines.Add("| Removed | 0 |") + $lines.Add("| New total | $($newSnapshot.Count) |") + $lines.Add('') + $lines.Add('### Initial snapshot') + $lines.Add('') + $lines.Add('This is the first snapshot. All permissions are newly recorded.') + $lines.Add('') + + $summary = $lines -join "`n" + Write-Host $summary + $summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8 + + $delimiter = "DIFF_$(New-Guid)" + "changed=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + "diff_summary<<$delimiter`n$summary`n$delimiter" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + exit 0 + } + $diff = @(git diff --unified=0 -- $env:SNAPSHOT_PATH) if ($diff.Count -eq 0) { Write-Host 'No changes to the blocked permissions snapshot.' @@ -135,3 +166,4 @@ jobs: `Get-MtEntraAgentHighRiskGraphPermissionFinding` because agents can no longer hold them. - **Unblocked** permissions need a judgment call on whether they belong in MT.1223. labels: automation + diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 index e78c299809..b60ad1e466 100644 --- a/build/Update-MtAgentBlockedPermissions.ps1 +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -75,7 +75,10 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { # Split on | and trim. The split gives us empty strings at the start and end. $cells = $line -split '\|' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' } - if ($cells.Count -lt 3) { continue } + if ($cells.Count -lt 3) { + Write-Warning "Skipping malformed row (fewer than 3 columns): $line" + continue + } # Column 0: permission name (may be a markdown link like [Name](url)) $permName = $cells[0] @@ -84,12 +87,15 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { } $permName = $permName.Trim() + if ([string]::IsNullOrWhiteSpace($permName)) { + Write-Warning "Skipping row with empty permission name: $line" + continue + } + # Column 1: Delegated, Column 2: Application # The values use symbols, not words, but handle both - $delegated = $cells[1] -match ([regex]::Escape([char]0x274C)) # ❌ - $application = $cells[2] -match ([regex]::Escape([char]0x274C)) # ❌ - - if ([string]::IsNullOrWhiteSpace($permName)) { continue } + $delegated = $cells[1] -match ([regex]::Escape([char]0x274C)) # red X + $application = $cells[2] -match ([regex]::Escape([char]0x274C)) # red X $permissions.Add(@{ Permission = $permName @@ -117,11 +123,13 @@ try { } # --- Build output --- +# Note: GeneratedAt is metadata only and is excluded from the diff-detection +# input. The workflow's git-diff step compares the Permissions array, Count, +# SourceUrl, and SourceSha256, which change only when Microsoft's table does. $output = [ordered]@{ SourceUrl = $SourceUrl SourceSha256 = $sourceHash - GeneratedAt = (Get-Date -Format 'o') Count = $permissions.Count Permissions = @($permissions | Sort-Object { $_.Permission } | ForEach-Object { [ordered]@{ diff --git a/powershell/internal/data/AgentBlockedPermissions.json b/powershell/internal/data/AgentBlockedPermissions.json new file mode 100644 index 0000000000..d4142a8384 --- /dev/null +++ b/powershell/internal/data/AgentBlockedPermissions.json @@ -0,0 +1,302 @@ +{ + "SourceUrl": "https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/v1.0/resources/agentid-platform-overview.md", + "SourceSha256": "d0ad7a4c720e8c64e97aa2615811233fe8020866e509c1c4b2e6d538c38385aa", + "Count": 59, + "Permissions": [ + { + "Permission": "AgentIdentity.Create", + "Delegated": false, + "Application": true + }, + { + "Permission": "AgentIdentity.Create.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "AgentIdentity.CreateAsManager", + "Delegated": false, + "Application": true + }, + { + "Permission": "AgentIdentityBlueprint.Create", + "Delegated": false, + "Application": true + }, + { + "Permission": "AgentIdentityBlueprint.CreateAsManager", + "Delegated": false, + "Application": true + }, + { + "Permission": "AgentIdentityBlueprint.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "AgentIdentityBlueprintPrincipal.Create", + "Delegated": false, + "Application": true + }, + { + "Permission": "AppRoleAssignment.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Application.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Application.ReadWrite.OwnedBy", + "Delegated": false, + "Application": true + }, + { + "Permission": "BitlockerKey.Read.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Calendars.Read", + "Delegated": false, + "Application": true + }, + { + "Permission": "ChannelMessage.Read.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "ChannelMessage.Read.Group", + "Delegated": false, + "Application": true + }, + { + "Permission": "Chat.Read.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Chat.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "ConsentRequest.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "CustomSecAttributeAssignment.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "CustomSecAttributeDefinition.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "DelegatedPermissionGrant.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "Device.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Device.Write.Restricted", + "Delegated": true, + "Application": true + }, + { + "Permission": "DeviceManagementConfiguration.Read.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Directory.AccessAsUser.All", + "Delegated": true, + "Application": false + }, + { + "Permission": "Directory.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "Directory.Write.Restricted", + "Delegated": true, + "Application": true + }, + { + "Permission": "Domain.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "EduRoster.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "EntitlementManagement.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Files.Read.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Files.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Group.Create", + "Delegated": false, + "Application": true + }, + { + "Permission": "Group.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "Group.Write.Restricted", + "Delegated": true, + "Application": false + }, + { + "Permission": "GroupMember.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "IdentityProvider.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "LifecycleManagement.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Organization.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Policy.ReadWrite.AuthenticationMethod", + "Delegated": false, + "Application": true + }, + { + "Permission": "Policy.ReadWrite.CrossTenantAccess", + "Delegated": false, + "Application": true + }, + { + "Permission": "Policy.ReadWrite.PermissionGrant", + "Delegated": false, + "Application": true + }, + { + "Permission": "Policy.ReadWrite.SecurityDefaults", + "Delegated": false, + "Application": true + }, + { + "Permission": "PrintJob.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "PrivilegedAccess.ReadWrite.AzureAD", + "Delegated": false, + "Application": true + }, + { + "Permission": "PrivilegedAccess.ReadWrite.AzureResources", + "Delegated": false, + "Application": true + }, + { + "Permission": "RoleManagement.ReadWrite.All", + "Delegated": true, + "Application": false + }, + { + "Permission": "RoleManagement.ReadWrite.Directory", + "Delegated": true, + "Application": true + }, + { + "Permission": "Sites.FullControl.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Sites.Manage.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Sites.Read.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Sites.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "Tasks.ReadWrite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "User-PasswordProfile.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "User.DeleteRestore.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "User.EnableDisableAccount.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "User.Invite.All", + "Delegated": false, + "Application": true + }, + { + "Permission": "User.ReadWrite.All", + "Delegated": true, + "Application": true + }, + { + "Permission": "UserAuthenticationMethod.Read.All", + "Delegated": true, + "Application": false + }, + { + "Permission": "UserAuthenticationMethod.ReadWrite.All", + "Delegated": true, + "Application": true + } + ] +} diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index b90aad86fb..e53e826139 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -1,9 +1,17 @@ BeforeDiscovery { $snapshotPath = Join-Path $PSScriptRoot '../../internal/data/AgentBlockedPermissions.json' + + # The snapshot is generated by build/Update-MtAgentBlockedPermissions.ps1 and + # checked in. It won't exist on a fresh clone until the automation runs, so + # skip discovery gracefully instead of throwing. if (-not (Test-Path -LiteralPath $snapshotPath)) { - throw "AgentBlockedPermissions.json not found at $snapshotPath. Run build/Update-MtAgentBlockedPermissions.ps1 first." + $script:SnapshotMissing = $true + $script:BlockedPermissions = @() + $script:Mt1223Permissions = @() + return } + $script:SnapshotMissing = $false $snapshot = Get-Content -LiteralPath $snapshotPath -Raw | ConvertFrom-Json $script:BlockedPermissions = $snapshot.Permissions @@ -30,15 +38,25 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { BeforeAll { $snapshotPath = Join-Path $PSScriptRoot '../../internal/data/AgentBlockedPermissions.json' + + if ($script:SnapshotMissing) { + return + } + $snapshot = Get-Content -LiteralPath $snapshotPath -Raw | ConvertFrom-Json $script:BlockedPermissions = $snapshot.Permissions } - It 'Snapshot file should have at least 50 permissions' { + It 'Snapshot file should exist' { + $script:SnapshotMissing | Should -BeFalse -Because ` + 'AgentBlockedPermissions.json must be checked in. Run build/Update-MtAgentBlockedPermissions.ps1 to generate it.' + } + + It 'Snapshot file should have at least 50 permissions' -Skip:($script:SnapshotMissing) { $script:BlockedPermissions.Count | Should -BeGreaterOrEqual 50 } - It ' should not be blocked for Application in the snapshot' -ForEach @( + It ' should not be blocked for Application in the snapshot' -Skip:($script:SnapshotMissing) -ForEach @( $script:Mt1223Permissions | ForEach-Object { @{ Permission = $_ } } ) { $entry = $script:BlockedPermissions | Where-Object { $_.Permission -eq $permission } From 3496a958c8416129ce150372b8e61882be71711e Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sat, 31 Oct 2026 20:32:06 -0600 Subject: [PATCH 03/10] fix: move snapshot to internal/generated and address review feedback --- .../update-agent-blocked-permissions.yaml | 4 ++-- build/Update-MtAgentBlockedPermissions.ps1 | 14 +++++++------- .../AgentBlockedPermissions.json | 0 .../general/AgentBlockedPermissionDrift.Tests.ps1 | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) rename powershell/internal/{data => generated}/AgentBlockedPermissions.json (100%) diff --git a/.github/workflows/update-agent-blocked-permissions.yaml b/.github/workflows/update-agent-blocked-permissions.yaml index 3f044e9c6d..793a687bf4 100644 --- a/.github/workflows/update-agent-blocked-permissions.yaml +++ b/.github/workflows/update-agent-blocked-permissions.yaml @@ -13,7 +13,7 @@ concurrency: cancel-in-progress: false env: - SNAPSHOT_PATH: powershell/internal/data/AgentBlockedPermissions.json + SNAPSHOT_PATH: powershell/internal/generated/AgentBlockedPermissions.json jobs: update-agent-blocked-permissions: @@ -147,7 +147,7 @@ jobs: delete-branch: true title: "chore: update agent blocked permissions snapshot" body: | - Refreshes `powershell/internal/data/AgentBlockedPermissions.json` from + Refreshes `powershell/internal/generated/AgentBlockedPermissions.json` from Microsoft's [agent identity platform overview](https://learn.microsoft.com/en-us/graph/api/resources/agentid-platform-overview) documentation. diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 index b60ad1e466..71b434f5c5 100644 --- a/build/Update-MtAgentBlockedPermissions.ps1 +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -5,7 +5,7 @@ .DESCRIPTION Downloads Microsoft's agentid-platform-overview.md from the public docs repo, parses the "Microsoft Graph permissions blocked for agents" table, validates the - result, and writes a JSON snapshot into the module's internal data folder. + result, and writes a JSON snapshot into the module's internal generated folder. The update-agent-blocked-permissions workflow runs this monthly and raises a pull request when the table changes. For reproducibility, pass a commit-pinned raw URL with -SourceUrl. @@ -17,7 +17,7 @@ [CmdletBinding()] param ( # Path to the generated JSON snapshot. - [string] $SnapshotPath = "$PSScriptRoot/../powershell/internal/data/AgentBlockedPermissions.json", + [string] $SnapshotPath = "$PSScriptRoot/../powershell/internal/generated/AgentBlockedPermissions.json", # Raw URL of Microsoft's agent ID platform overview page. [string] $SourceUrl = 'https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/v1.0/resources/agentid-platform-overview.md', @@ -76,7 +76,7 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { $cells = $line -split '\|' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' } if ($cells.Count -lt 3) { - Write-Warning "Skipping malformed row (fewer than 3 columns): $line" + throw "Malformed row (expected 3 columns): $line" continue } @@ -88,14 +88,14 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { $permName = $permName.Trim() if ([string]::IsNullOrWhiteSpace($permName)) { - Write-Warning "Skipping row with empty permission name: $line" + throw "Empty permission name in row: $line" continue } # Column 1: Delegated, Column 2: Application # The values use symbols, not words, but handle both - $delegated = $cells[1] -match ([regex]::Escape([char]0x274C)) # red X - $application = $cells[2] -match ([regex]::Escape([char]0x274C)) # red X + $delegated = if ($cells[1] -match [char]0x274C) { $true } elseif ($cells[1] -match [char]0x2796) { $false } else { throw "Unexpected Delegated value $($cells[1]) for $permName" } + $application = if ($cells[2] -match [char]0x274C) { $true } elseif ($cells[2] -match [char]0x2796) { $false } else { throw "Unexpected Application value $($cells[2]) for $permName" } $permissions.Add(@{ Permission = $permName @@ -114,7 +114,7 @@ Write-Verbose "Parsed $($permissions.Count) blocked permissions." # --- Hash the source for traceability --- -$sourceBytes = [System.Text.Encoding]::UTF8.GetBytes($content) +$sourceBytes = [System.Text.Encoding]::UTF8.GetBytes(($lines[$tableStartIndex..($i - 1)] -join "`n")) $sha256 = [System.Security.Cryptography.SHA256]::Create() try { $sourceHash = (-join ($sha256.ComputeHash($sourceBytes) | ForEach-Object { $_.ToString('x2') })) diff --git a/powershell/internal/data/AgentBlockedPermissions.json b/powershell/internal/generated/AgentBlockedPermissions.json similarity index 100% rename from powershell/internal/data/AgentBlockedPermissions.json rename to powershell/internal/generated/AgentBlockedPermissions.json diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index e53e826139..141980222c 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -1,5 +1,5 @@ BeforeDiscovery { - $snapshotPath = Join-Path $PSScriptRoot '../../internal/data/AgentBlockedPermissions.json' + $snapshotPath = Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' # The snapshot is generated by build/Update-MtAgentBlockedPermissions.ps1 and # checked in. It won't exist on a fresh clone until the automation runs, so @@ -37,7 +37,7 @@ BeforeDiscovery { Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { BeforeAll { - $snapshotPath = Join-Path $PSScriptRoot '../../internal/data/AgentBlockedPermissions.json' + $snapshotPath = Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' if ($script:SnapshotMissing) { return From 20d422a6d1e83fb4ff7c9113ecd50a935a082f8a Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Thu, 5 Nov 2026 13:18:36 -0700 Subject: [PATCH 04/10] fix: add BOM and correct stale comments --- build/Update-MtAgentBlockedPermissions.ps1 | 9 ++++----- .../tests/general/AgentBlockedPermissionDrift.Tests.ps1 | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 index 71b434f5c5..497dbbd002 100644 --- a/build/Update-MtAgentBlockedPermissions.ps1 +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Updates the checked-in snapshot of Microsoft Graph permissions blocked for agent identities. @@ -22,7 +22,7 @@ param ( # Raw URL of Microsoft's agent ID platform overview page. [string] $SourceUrl = 'https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/v1.0/resources/agentid-platform-overview.md', - # Minimum expected row count. The table has 57 rows today. + # Minimum expected row count. The table has 59 rows today. [int] $MinimumRowCount = 50 ) @@ -123,9 +123,8 @@ try { } # --- Build output --- -# Note: GeneratedAt is metadata only and is excluded from the diff-detection -# input. The workflow's git-diff step compares the Permissions array, Count, -# SourceUrl, and SourceSha256, which change only when Microsoft's table does. +# The snapshot holds no timestamp, so the workflow's git diff is non-empty only when +# Microsoft's table or SourceUrl changes. $output = [ordered]@{ SourceUrl = $SourceUrl diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index 141980222c..10b1857c62 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -1,9 +1,8 @@ -BeforeDiscovery { +BeforeDiscovery { $snapshotPath = Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' # The snapshot is generated by build/Update-MtAgentBlockedPermissions.ps1 and - # checked in. It won't exist on a fresh clone until the automation runs, so - # skip discovery gracefully instead of throwing. + # checked in. If it is missing, the "Snapshot file should exist" test fails. if (-not (Test-Path -LiteralPath $snapshotPath)) { $script:SnapshotMissing = $true $script:BlockedPermissions = @() From f1cf8b1c9d65508db9115f12d6538b57f19a29f0 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Thu, 5 Nov 2026 14:27:02 -0700 Subject: [PATCH 05/10] fix: make missing snapshot fail the drift test and remove dead code --- .../update-agent-blocked-permissions.yaml | 35 ------------------- build/Update-MtAgentBlockedPermissions.ps1 | 2 -- .../AgentBlockedPermissionDrift.Tests.ps1 | 4 +-- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/.github/workflows/update-agent-blocked-permissions.yaml b/.github/workflows/update-agent-blocked-permissions.yaml index 793a687bf4..b147a06904 100644 --- a/.github/workflows/update-agent-blocked-permissions.yaml +++ b/.github/workflows/update-agent-blocked-permissions.yaml @@ -36,37 +36,6 @@ jobs: run: | $ErrorActionPreference = 'Stop' - # Check whether git already tracks this file. On the very first run - # after the automation is merged, the snapshot won't be in git yet. - # In that case every permission is "new", so we treat the entire file - # as an addition. - $tracked = git ls-files -- $env:SNAPSHOT_PATH - if (-not $tracked) { - Write-Host 'Snapshot file is new (first run). Treating entire file as a change.' - $newSnapshot = Get-Content -LiteralPath $env:SNAPSHOT_PATH -Raw | ConvertFrom-Json - - $lines = [System.Collections.Generic.List[string]]::new() - $lines.Add("| Change | Permissions |") - $lines.Add("| --- | --- |") - $lines.Add("| Added | $($newSnapshot.Count) |") - $lines.Add("| Removed | 0 |") - $lines.Add("| New total | $($newSnapshot.Count) |") - $lines.Add('') - $lines.Add('### Initial snapshot') - $lines.Add('') - $lines.Add('This is the first snapshot. All permissions are newly recorded.') - $lines.Add('') - - $summary = $lines -join "`n" - Write-Host $summary - $summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8 - - $delimiter = "DIFF_$(New-Guid)" - "changed=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 - "diff_summary<<$delimiter`n$summary`n$delimiter" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 - exit 0 - } - $diff = @(git diff --unified=0 -- $env:SNAPSHOT_PATH) if ($diff.Count -eq 0) { Write-Host 'No changes to the blocked permissions snapshot.' @@ -75,10 +44,6 @@ jobs: } $newSnapshot = Get-Content -LiteralPath $env:SNAPSHOT_PATH -Raw | ConvertFrom-Json - $newPerms = @{} - foreach ($p in $newSnapshot.Permissions) { - $newPerms[$p.Permission] = $p - } $addedPattern = '^\+\s*"Permission":\s*"(.+)"' $removedPattern = '^-\s*"Permission":\s*"(.+)"' diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 index 497dbbd002..371282ce68 100644 --- a/build/Update-MtAgentBlockedPermissions.ps1 +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -77,7 +77,6 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { if ($cells.Count -lt 3) { throw "Malformed row (expected 3 columns): $line" - continue } # Column 0: permission name (may be a markdown link like [Name](url)) @@ -89,7 +88,6 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { if ([string]::IsNullOrWhiteSpace($permName)) { throw "Empty permission name in row: $line" - continue } # Column 1: Delegated, Column 2: Application diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index 10b1857c62..c9062b9e1c 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { BeforeAll { $snapshotPath = Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' - if ($script:SnapshotMissing) { + if (-not (Test-Path -LiteralPath $snapshotPath)) { return } @@ -47,7 +47,7 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { } It 'Snapshot file should exist' { - $script:SnapshotMissing | Should -BeFalse -Because ` + Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' | Should -Exist -Because ` 'AgentBlockedPermissions.json must be checked in. Run build/Update-MtAgentBlockedPermissions.ps1 to generate it.' } From 11e661cb906fb27f0fa45fb52e69121cc60e032f Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sun, 8 Nov 2026 11:33:32 -0700 Subject: [PATCH 06/10] Read MT.1223's permission list from a shared function in the drift test --- ...et-MtEntraAgentHighRiskGraphPermission.ps1 | 30 +++++++++++++++++ ...traAgentHighRiskGraphPermissionFinding.ps1 | 15 +-------- .../AgentBlockedPermissionDrift.Tests.ps1 | 32 ++++++++----------- 3 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermission.ps1 diff --git a/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermission.ps1 b/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermission.ps1 new file mode 100644 index 0000000000..e89cde8617 --- /dev/null +++ b/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermission.ps1 @@ -0,0 +1,30 @@ +function Get-MtEntraAgentHighRiskGraphPermission { + <# + .SYNOPSIS + Returns the Microsoft Graph application permissions MT.1223 treats as high risk on agent identities. + + .DESCRIPTION + The single source of the MT.1223 permission list. Each key is a permission name and each value is + its attack path: Direct when the permission can grant privilege on its own, Indirect when it opens + a path to privilege. Get-MtEntraAgentHighRiskGraphPermissionFinding uses it to find the + permissions, and the agent blocked permissions drift test reads it so the two cannot drift apart. + #> + [CmdletBinding()] + [OutputType([hashtable])] + param() + + @{ + 'AdministrativeUnit.ReadWrite.All' = 'Indirect' + 'Application.ReadUpdate.All' = 'Indirect' + 'DeviceManagementConfiguration.ReadWrite.All' = 'Indirect' + 'DeviceManagementRBAC.ReadWrite.All' = 'Indirect' + 'Policy.ReadWrite.ConditionalAccess' = 'Direct' + 'PrivilegedAccess.ReadWrite.AzureADGroup' = 'Direct' + 'PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup' = 'Direct' + 'PrivilegedEligibilitySchedule.ReadWrite.AzureADGroup' = 'Indirect' + 'RoleAssignmentSchedule.ReadWrite.Directory' = 'Direct' + 'RoleEligibilitySchedule.ReadWrite.Directory' = 'Indirect' + 'RoleManagementPolicy.ReadWrite.AzureADGroup' = 'Indirect' + 'RoleManagementPolicy.ReadWrite.Directory' = 'Indirect' + } +} diff --git a/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermissionFinding.ps1 b/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermissionFinding.ps1 index 464470a655..53c30dc759 100644 --- a/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermissionFinding.ps1 +++ b/powershell/internal/services/entra/Get-MtEntraAgentHighRiskGraphPermissionFinding.ps1 @@ -3,20 +3,7 @@ [OutputType([pscustomobject])] param() - $RiskPaths = @{ - 'AdministrativeUnit.ReadWrite.All' = 'Indirect' - 'Application.ReadUpdate.All' = 'Indirect' - 'DeviceManagementConfiguration.ReadWrite.All' = 'Indirect' - 'DeviceManagementRBAC.ReadWrite.All' = 'Indirect' - 'Policy.ReadWrite.ConditionalAccess' = 'Direct' - 'PrivilegedAccess.ReadWrite.AzureADGroup' = 'Direct' - 'PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup' = 'Direct' - 'PrivilegedEligibilitySchedule.ReadWrite.AzureADGroup' = 'Indirect' - 'RoleAssignmentSchedule.ReadWrite.Directory' = 'Direct' - 'RoleEligibilitySchedule.ReadWrite.Directory' = 'Indirect' - 'RoleManagementPolicy.ReadWrite.AzureADGroup' = 'Indirect' - 'RoleManagementPolicy.ReadWrite.Directory' = 'Indirect' - } + $RiskPaths = Get-MtEntraAgentHighRiskGraphPermission $AgentIdentities = @( Invoke-MtGraphRequest -ApiVersion 'v1.0' ` -RelativeUri 'servicePrincipals/microsoft.graph.agentIdentity' ` diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index c9062b9e1c..f72d1f3b4a 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -1,4 +1,12 @@ BeforeDiscovery { + # MT.1223's list comes from the same function the check uses, so a change to the check's list + # is picked up here automatically. If Microsoft blocks any of these for agents, the permission + # is dead weight in the check. + Import-Module (Join-Path $PSScriptRoot '../../Maester.psd1') -Force + $script:Mt1223Permissions = @( + (& (Get-Module Maester) { Get-MtEntraAgentHighRiskGraphPermission }).Keys | Sort-Object + ) + $snapshotPath = Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' # The snapshot is generated by build/Update-MtAgentBlockedPermissions.ps1 and @@ -6,31 +14,12 @@ if (-not (Test-Path -LiteralPath $snapshotPath)) { $script:SnapshotMissing = $true $script:BlockedPermissions = @() - $script:Mt1223Permissions = @() return } $script:SnapshotMissing = $false $snapshot = Get-Content -LiteralPath $snapshotPath -Raw | ConvertFrom-Json $script:BlockedPermissions = $snapshot.Permissions - - # MT.1223's curated list from Get-MtEntraAgentHighRiskGraphPermissionFinding.ps1. - # These are the permissions the check looks for on agent identities. - # If Microsoft blocks any of these for agents, the permission is dead weight in the check. - $script:Mt1223Permissions = @( - 'AdministrativeUnit.ReadWrite.All' - 'Application.ReadUpdate.All' - 'DeviceManagementConfiguration.ReadWrite.All' - 'DeviceManagementRBAC.ReadWrite.All' - 'Policy.ReadWrite.ConditionalAccess' - 'PrivilegedAccess.ReadWrite.AzureADGroup' - 'PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup' - 'PrivilegedEligibilitySchedule.ReadWrite.AzureADGroup' - 'RoleAssignmentSchedule.ReadWrite.Directory' - 'RoleEligibilitySchedule.ReadWrite.Directory' - 'RoleManagementPolicy.ReadWrite.AzureADGroup' - 'RoleManagementPolicy.ReadWrite.Directory' - ) } Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { @@ -51,6 +40,11 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { 'AgentBlockedPermissions.json must be checked in. Run build/Update-MtAgentBlockedPermissions.ps1 to generate it.' } + It 'MT.1223 permission list should not be empty' -ForEach @(@{ PermissionCount = $script:Mt1223Permissions.Count }) { + $PermissionCount | Should -BeGreaterThan 0 -Because ` + 'Get-MtEntraAgentHighRiskGraphPermission returned no permissions, so the drift check below would run nothing.' + } + It 'Snapshot file should have at least 50 permissions' -Skip:($script:SnapshotMissing) { $script:BlockedPermissions.Count | Should -BeGreaterOrEqual 50 } From b0323c218ff93d1b9be169b02e941dd885ba1c9f Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sun, 8 Nov 2026 11:50:23 -0700 Subject: [PATCH 07/10] Check the snapshot path literally in the drift test --- powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index f72d1f3b4a..91cd0abc13 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -36,7 +36,7 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { } It 'Snapshot file should exist' { - Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json' | Should -Exist -Because ` + Test-Path -LiteralPath (Join-Path $PSScriptRoot '../../internal/generated/AgentBlockedPermissions.json') | Should -BeTrue -Because ` 'AgentBlockedPermissions.json must be checked in. Run build/Update-MtAgentBlockedPermissions.ps1 to generate it.' } From e255d08ed27622071363a60be6404ef272674d73 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Mon, 16 Nov 2026 08:21:58 -0700 Subject: [PATCH 08/10] fix: sort agent blocked permissions ordinally and validate the source table Sort-Object compares by the machine's culture, so the snapshot order changed from one machine to another. Sort with String.CompareOrdinal, as suggested in review. The script now stops instead of writing the snapshot when the table has a duplicate name, unexpected or reordered columns, a second table, a missing separator row, a row with an extra cell, a cell that is not exactly one symbol, or a name with characters outside letters, digits, '.', '_' and '-'. Regenerate the snapshot so SourceSha256 matches the current source. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WrYw8C2gSDFxzWqZ2zKtJB --- build/Update-MtAgentBlockedPermissions.ps1 | 73 +++++++++++++++---- .../generated/AgentBlockedPermissions.json | 2 +- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 index 371282ce68..a61491126b 100644 --- a/build/Update-MtAgentBlockedPermissions.ps1 +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -49,17 +49,28 @@ if ([string]::IsNullOrWhiteSpace($content) -or $content.Length -lt 1000) { # --- Find the table --- $lines = $content -split "`n" -$tableStartIndex = -1 -for ($i = 0; $i -lt $lines.Count; $i++) { - if ($lines[$i] -match '^\|\s*Permission name\s*\|') { - $tableStartIndex = $i - break - } -} +$headerIndexes = @(for ($i = 0; $i -lt $lines.Count; $i++) { + if ($lines[$i] -match '^\|\s*Permission name\s*\|') { $i } +}) -if ($tableStartIndex -lt 0) { +if ($headerIndexes.Count -eq 0) { throw "Could not find the 'Permission name' table header in the downloaded markdown. Microsoft may have renamed or moved the section." } +if ($headerIndexes.Count -gt 1) { + throw "Found $($headerIndexes.Count) tables with a 'Permission name' header (lines $(($headerIndexes | ForEach-Object { $_ + 1 }) -join ', ')); expected one. Check which table lists the blocked permissions." +} +$tableStartIndex = $headerIndexes[0] + +# Rows are read by column position, so check the column names and their order first. +# A swapped or added column would otherwise put the wrong values in the snapshot. +$expectedHeader = @('Permission name', 'Delegated', 'Application') +$headerCells = @($lines[$tableStartIndex].Trim() -split '\|' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }) +if (-not [string]::Equals(($headerCells -join ' | '), ($expectedHeader -join ' | '), [StringComparison]::OrdinalIgnoreCase)) { + throw "Unexpected table columns '$($headerCells -join ' | ')'; expected '$($expectedHeader -join ' | ')'. Microsoft may have added, removed or reordered a column." +} +if ($tableStartIndex + 1 -ge $lines.Count -or $lines[$tableStartIndex + 1].Trim() -notmatch '^\|(\s*:?-+:?\s*\|){3}$') { + throw "Expected a three-column separator row (|---|---|---|) after the table header." +} # --- Parse rows --- @@ -75,8 +86,8 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { # Split on | and trim. The split gives us empty strings at the start and end. $cells = $line -split '\|' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' } - if ($cells.Count -lt 3) { - throw "Malformed row (expected 3 columns): $line" + if ($cells.Count -ne 3) { + throw "Malformed row (expected 3 columns, found $($cells.Count)): $line" } # Column 0: permission name (may be a markdown link like [Name](url)) @@ -90,10 +101,27 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { throw "Empty permission name in row: $line" } - # Column 1: Delegated, Column 2: Application - # The values use symbols, not words, but handle both - $delegated = if ($cells[1] -match [char]0x274C) { $true } elseif ($cells[1] -match [char]0x2796) { $false } else { throw "Unexpected Delegated value $($cells[1]) for $permName" } - $application = if ($cells[2] -match [char]0x274C) { $true } elseif ($cells[2] -match [char]0x2796) { $false } else { throw "Unexpected Application value $($cells[2]) for $permName" } + # Graph permission names use only letters, digits, '.', '_' and '-', as in Microsoft's Graph + # permissions reference. Anything else (a space, a backtick, an invisible character) would put a + # name in the snapshot that is not the real permission name. A space breaks the drift test's + # match; an invisible character does not even show, because PowerShell's -eq ignores it. The + # check is case-sensitive (-cnotmatch) because a case-insensitive [A-Za-z] also accepts the + # Kelvin sign. + if ($permName -cnotmatch '^[A-Za-z0-9][A-Za-z0-9._-]*\z') { + throw "Unexpected characters in permission name '$permName' in row: $line" + } + + # Column 1: Delegated, column 2: Application. Each cell must hold exactly one symbol: + # U+274C (cross mark) means blocked, U+2796 (heavy minus sign) means not blocked. A trailing + # U+FE0F (emoji presentation selector) does not change the meaning, so it is removed first. + # Compared ordinally: -ceq ignores U+FE0F and zero-width characters on some machines and not on + # others (not when .NET runs in invariant globalization mode). + $delegated, $application = foreach ($column in 1, 2) { + $value = $cells[$column].Replace([string][char]0xFE0F, '').Trim() + if ([string]::Equals($value, [string][char]0x274C, [StringComparison]::Ordinal)) { $true } + elseif ([string]::Equals($value, [string][char]0x2796, [StringComparison]::Ordinal)) { $false } + else { throw "Unexpected $($expectedHeader[$column]) value '$($cells[$column])' for $permName" } + } $permissions.Add(@{ Permission = $permName @@ -108,6 +136,15 @@ if ($permissions.Count -lt $MinimumRowCount) { throw "Only $($permissions.Count) permissions parsed; expected at least $MinimumRowCount. The table format may have changed." } +# A name listed twice makes the snapshot ambiguous (which row's values apply?), and the ordinal +# sort below does not keep equal names in a fixed order. Stop instead of writing either. +$seen = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) +foreach ($p in $permissions) { + if (-not $seen.Add($p.Permission)) { + throw "Permission '$($p.Permission)' appears more than once in the table. Check the source before updating the snapshot." + } +} + Write-Verbose "Parsed $($permissions.Count) blocked permissions." # --- Hash the source for traceability --- @@ -124,11 +161,17 @@ try { # The snapshot holds no timestamp, so the workflow's git diff is non-empty only when # Microsoft's table or SourceUrl changes. +# Sort by ordinal (character code) comparison. Sort-Object compares by the machine's culture, +# which orders some names differently from one machine to another and would make the +# snapshot change without any change in Microsoft's table. +$sorted = [System.Collections.Generic.List[hashtable]]::new($permissions) +$sorted.Sort([System.Comparison[hashtable]] { param($a, $b) [string]::CompareOrdinal($a.Permission, $b.Permission) }) + $output = [ordered]@{ SourceUrl = $SourceUrl SourceSha256 = $sourceHash Count = $permissions.Count - Permissions = @($permissions | Sort-Object { $_.Permission } | ForEach-Object { + Permissions = @($sorted | ForEach-Object { [ordered]@{ Permission = $_.Permission Delegated = $_.Delegated diff --git a/powershell/internal/generated/AgentBlockedPermissions.json b/powershell/internal/generated/AgentBlockedPermissions.json index d4142a8384..63d0c9b374 100644 --- a/powershell/internal/generated/AgentBlockedPermissions.json +++ b/powershell/internal/generated/AgentBlockedPermissions.json @@ -1,6 +1,6 @@ { "SourceUrl": "https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/v1.0/resources/agentid-platform-overview.md", - "SourceSha256": "d0ad7a4c720e8c64e97aa2615811233fe8020866e509c1c4b2e6d538c38385aa", + "SourceSha256": "f526e4be67d44498c78a91f52eca42920dcfea4329e78951395e83479647fe56", "Count": 59, "Permissions": [ { From 6fc932003b0c3601529918acc96148edeca82161 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Tue, 17 Nov 2026 06:47:39 -0700 Subject: [PATCH 09/10] feat: report failed snapshot runs and replace the fixed row floor A failed scheduled run now opens an issue labelled agent-blocked-permissions (or comments on the open one) with a link to the run, and a later successful run closes it, as eidsca-sync does. The snapshot keeps no timestamp, so an unchanged table still raises no pull request. The generator compares with the snapshot already checked in instead of a fixed minimum of 50: more than 20% of its permissions dropping out in one update stops the run, and -AllowLargeRemoval (allow_large_removal when the workflow is run manually) accepts a checked large removal. The fixed minimum still applies when there is no earlier snapshot. The drift test checks that the committed file is not empty, that Count matches its entries and that no permission is listed twice, instead of requiring 50. The pull request body now asks reviewers to review the diff as data and names Get-MtEntraAgentHighRiskGraphPermission, where MT.1223's list lives. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WrYw8C2gSDFxzWqZ2zKtJB --- .../update-agent-blocked-permissions.yaml | 68 ++++++++++++++++++- build/Update-MtAgentBlockedPermissions.ps1 | 44 ++++++++++-- .../AgentBlockedPermissionDrift.Tests.ps1 | 19 +++++- 3 files changed, 122 insertions(+), 9 deletions(-) diff --git a/.github/workflows/update-agent-blocked-permissions.yaml b/.github/workflows/update-agent-blocked-permissions.yaml index b147a06904..fa69347c58 100644 --- a/.github/workflows/update-agent-blocked-permissions.yaml +++ b/.github/workflows/update-agent-blocked-permissions.yaml @@ -5,6 +5,11 @@ on: schedule: - cron: "0 8 10 * *" # Monthly on the 10th at 08:00 UTC workflow_dispatch: + inputs: + allow_large_removal: + description: Accept more removed permissions than the script allows. Tick only after checking Microsoft's table. + type: boolean + default: false permissions: {} @@ -14,6 +19,8 @@ concurrency: env: SNAPSHOT_PATH: powershell/internal/generated/AgentBlockedPermissions.json + FAILURE_LABEL: agent-blocked-permissions + FAILURE_TITLE: The agent blocked permissions snapshot could not be updated jobs: update-agent-blocked-permissions: @@ -28,7 +35,12 @@ jobs: - name: Update agent blocked permissions snapshot shell: pwsh - run: ./build/Update-MtAgentBlockedPermissions.ps1 -Verbose + env: + ALLOW_LARGE_REMOVAL: ${{ inputs.allow_large_removal == true }} + run: | + $parameters = @{ Verbose = $true } + if ($env:ALLOW_LARGE_REMOVAL -eq 'true') { $parameters.AllowLargeRemoval = $true } + ./build/Update-MtAgentBlockedPermissions.ps1 @parameters - name: Summarize snapshot changes id: diff @@ -113,9 +125,15 @@ jobs: title: "chore: update agent blocked permissions snapshot" body: | Refreshes `powershell/internal/generated/AgentBlockedPermissions.json` from - Microsoft's [agent identity platform overview](https://learn.microsoft.com/en-us/graph/api/resources/agentid-platform-overview) + Microsoft's [agent identity platform overview](https://learn.microsoft.com/graph/api/resources/agentid-platform-overview) documentation. + **Review the diff as data, not as a routine bump.** The source is `main` of + [microsoftgraph/microsoft-graph-docs-contrib](https://github.com/microsoftgraph/microsoft-graph-docs-contrib), + a public docs repository that takes community pull requests. `SourceSha256` shows the snapshot + matches the table that was downloaded; it does not show that the edit upstream was correct. + Check each added or removed permission against Microsoft's documentation before merging. + Why this matters in Maester: - `AgentBlockedPermissionDrift.Tests.ps1` compares MT.1223's curated list of high-risk agent permissions against this snapshot. If Microsoft blocks a permission that MT.1223 @@ -128,7 +146,51 @@ jobs: Reviewer note: - **Newly blocked** permissions that overlap with MT.1223 need to be removed from - `Get-MtEntraAgentHighRiskGraphPermissionFinding` because agents can no longer hold them. + `Get-MtEntraAgentHighRiskGraphPermission` because agents can no longer hold them. - **Unblocked** permissions need a judgment call on whether they belong in MT.1223. labels: automation + # The update runs on a schedule and stops on purpose when Microsoft's table changes shape, so a failed run would + # otherwise go unnoticed while the drift test keeps passing against the old snapshot. Like eidsca-sync, one issue + # (labelled agent-blocked-permissions) stays open while runs fail and closes when a run succeeds. The snapshot keeps + # no timestamp, so an unchanged table still raises no pull request. + report-update-status: + needs: update-agent-blocked-permissions + if: always() + runs-on: ubuntu-latest + permissions: + issues: write + + steps: + - name: Open, update or close the failure issue + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RESULT: ${{ needs.update-agent-blocked-permissions.result }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + issue=$(gh issue list --label "$FAILURE_LABEL" --state open --limit 1 --json number --jq '.[0].number // empty') + if [ "$RESULT" = "failure" ]; then + body=$(printf '%s\n' \ + "The \`update-agent-blocked-permissions\` workflow failed, so \`$SNAPSHOT_PATH\` was not refreshed: $RUN_URL" \ + "" \ + "The drift test keeps passing against the old snapshot, so this issue is the signal that the snapshot is going stale." \ + "" \ + "The script stops on purpose when Microsoft's table no longer looks the way it expects: a renamed section, changed columns or symbols, a duplicate name, or more removed permissions than it allows in one update. Read the error in the run log and check the [source table](https://learn.microsoft.com/graph/api/resources/agentid-platform-overview). Then fix the script, or, if a large removal is real, run the workflow manually with **allow_large_removal** ticked." \ + "" \ + "This issue closes when a run succeeds.") + if [ -n "$issue" ]; then + gh issue comment "$issue" --body "$body" + echo "Commented on issue #$issue." + else + gh label create "$FAILURE_LABEL" --color d93f0b --description "The agent blocked permissions snapshot could not be updated" --force + url=$(gh issue create --title "$FAILURE_TITLE" --body "$body" --label "$FAILURE_LABEL") + echo "Opened issue ${url##*/}." + fi + elif [ "$RESULT" = "success" ] && [ -n "$issue" ]; then + gh issue close "$issue" --reason completed --comment "The snapshot update ran successfully again: $RUN_URL" + echo "Closed issue #$issue." + else + echo "Update job result: $RESULT. Nothing to report." + fi + diff --git a/build/Update-MtAgentBlockedPermissions.ps1 b/build/Update-MtAgentBlockedPermissions.ps1 index a61491126b..16396772b2 100644 --- a/build/Update-MtAgentBlockedPermissions.ps1 +++ b/build/Update-MtAgentBlockedPermissions.ps1 @@ -22,8 +22,17 @@ param ( # Raw URL of Microsoft's agent ID platform overview page. [string] $SourceUrl = 'https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/v1.0/resources/agentid-platform-overview.md', - # Minimum expected row count. The table has 59 rows today. - [int] $MinimumRowCount = 50 + # Fewest rows accepted when there is no earlier snapshot to compare with. The table has 59 rows today. + [int] $MinimumRowCount = 50, + + # Most permissions that may drop out of the table in one update, as a percentage of the earlier snapshot. + # A larger drop is more likely a broken parse or a bad edit upstream than a real change, so the script + # stops. After checking Microsoft's table, run it again with -AllowLargeRemoval. + [ValidateRange(0, 100)] + [int] $MaximumRemovedPercent = 20, + + # Accept more removals than -MaximumRemovedPercent allows. Use it only after checking Microsoft's table. + [switch] $AllowLargeRemoval ) $ErrorActionPreference = 'Stop' @@ -132,8 +141,35 @@ for ($i = $tableStartIndex + 2; $i -lt $lines.Count; $i++) { # --- Validate --- -if ($permissions.Count -lt $MinimumRowCount) { - throw "Only $($permissions.Count) permissions parsed; expected at least $MinimumRowCount. The table format may have changed." +# Compare with the snapshot already checked in. A fixed minimum stops a real shrink by Microsoft just as it +# stops a broken parse, so the guard is relative to the earlier snapshot: too many permissions dropping out at +# once stops the update. With no earlier snapshot (the first run), the fixed minimum still applies. +$previousNames = @() +if (Test-Path -LiteralPath $SnapshotPath) { + try { + $previousSnapshot = Get-Content -LiteralPath $SnapshotPath -Raw | ConvertFrom-Json + } catch { + throw "Could not read the existing snapshot at $SnapshotPath to compare with. $($_.Exception.Message)" + } + $previousNames = @($previousSnapshot.Permissions | ForEach-Object { [string]$_.Permission }) +} + +if ($previousNames.Count -eq 0) { + if ($permissions.Count -lt $MinimumRowCount) { + throw "Only $($permissions.Count) permissions parsed; expected at least $MinimumRowCount. The table format may have changed." + } +} else { + $currentNames = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) + foreach ($p in $permissions) { [void]$currentNames.Add($p.Permission) } + $removedNames = @($previousNames | Where-Object { -not $currentNames.Contains($_) }) + $allowedRemovals = [math]::Floor($previousNames.Count * $MaximumRemovedPercent / 100) + if ($removedNames.Count -gt $allowedRemovals -and -not $AllowLargeRemoval) { + throw ("$($removedNames.Count) of the $($previousNames.Count) permissions in the current snapshot are no longer in the table, " + + "more than the $allowedRemovals ($MaximumRemovedPercent%) allowed in one update. That is more likely a broken parse or a bad edit " + + "upstream than a real change. Check the source; if the removals are real, run again with -AllowLargeRemoval. " + + "No longer listed: $($removedNames -join ', ')") + } + Write-Verbose "$($removedNames.Count) permission(s) dropped out of the table since the last snapshot (at most $allowedRemovals allowed)." } # A name listed twice makes the snapshot ambiguous (which row's values apply?), and the ordinal diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index 91cd0abc13..56ce1dfa83 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -33,6 +33,7 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { $snapshot = Get-Content -LiteralPath $snapshotPath -Raw | ConvertFrom-Json $script:BlockedPermissions = $snapshot.Permissions + $script:SnapshotCount = $snapshot.Count } It 'Snapshot file should exist' { @@ -45,8 +46,22 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { 'Get-MtEntraAgentHighRiskGraphPermission returned no permissions, so the drift check below would run nothing.' } - It 'Snapshot file should have at least 50 permissions' -Skip:($script:SnapshotMissing) { - $script:BlockedPermissions.Count | Should -BeGreaterOrEqual 50 + # The generator stops on a broken table, so these check that the committed file is whole rather than its + # size: a fixed minimum here would fail CI on a real shrink by Microsoft that a reviewer had accepted. + It 'Snapshot should not be empty' -Skip:($script:SnapshotMissing) { + @($script:BlockedPermissions).Count | Should -BeGreaterThan 0 -Because ` + 'an empty snapshot would make every per-permission check below pass without checking anything.' + } + + It 'Snapshot Count should match the number of permissions it lists' -Skip:($script:SnapshotMissing) { + $script:SnapshotCount | Should -Be @($script:BlockedPermissions).Count -Because ` + 'a mismatch means the file was edited by hand or written incompletely. Regenerate it with build/Update-MtAgentBlockedPermissions.ps1.' + } + + It 'Snapshot should not list a permission twice' -Skip:($script:SnapshotMissing) { + $seen = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) + $duplicates = @($script:BlockedPermissions | Where-Object { -not $seen.Add([string]$_.Permission) } | ForEach-Object { $_.Permission }) + $duplicates | Should -BeNullOrEmpty -Because 'the generator stops on a duplicate name, so one here means the file was edited by hand.' } It ' should not be blocked for Application in the snapshot' -Skip:($script:SnapshotMissing) -ForEach @( From 197754db4009573c5fa679d0c12cc0f08051a46a Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Wed, 18 Nov 2026 07:20:32 -0700 Subject: [PATCH 10/10] Drift test: fail only when a permission is blocked for both paths MT.1223 reports a permission held as an application permission or as a delegated grant, so it can still fire while either is allowed. The drift test now fails only when a permission MT.1223 watches is blocked for both Application and Delegated, and says so. Pin create-pull-request to v8.1.3 (3ffccac), as the other workflows do. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WrYw8C2gSDFxzWqZ2zKtJB --- .../workflows/update-agent-blocked-permissions.yaml | 2 +- .../general/AgentBlockedPermissionDrift.Tests.ps1 | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/update-agent-blocked-permissions.yaml b/.github/workflows/update-agent-blocked-permissions.yaml index fa69347c58..878061a613 100644 --- a/.github/workflows/update-agent-blocked-permissions.yaml +++ b/.github/workflows/update-agent-blocked-permissions.yaml @@ -116,7 +116,7 @@ jobs: - name: Create Pull Request if: steps.diff.outputs.changed == 'true' - uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 + uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3 with: token: ${{ steps.app-token.outputs.token }} commit-message: "chore: update agent blocked permissions snapshot" diff --git a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 index 56ce1dfa83..f0a7f1c138 100644 --- a/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 +++ b/powershell/tests/general/AgentBlockedPermissionDrift.Tests.ps1 @@ -64,7 +64,7 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { $duplicates | Should -BeNullOrEmpty -Because 'the generator stops on a duplicate name, so one here means the file was edited by hand.' } - It ' should not be blocked for Application in the snapshot' -Skip:($script:SnapshotMissing) -ForEach @( + It ' should not be blocked for both Application and Delegated in the snapshot' -Skip:($script:SnapshotMissing) -ForEach @( $script:Mt1223Permissions | ForEach-Object { @{ Permission = $_ } } ) { $entry = $script:BlockedPermissions | Where-Object { $_.Permission -eq $permission } @@ -72,10 +72,10 @@ Describe 'MT.1223 permission list vs. agent blocked permissions snapshot' { # Permission isn't in the blocked list at all, which means it's grantable. Pass. $true | Should -BeTrue } else { - # If it IS in the blocked list with Application = true, it can't be granted to agents. - # That means MT.1223 is checking a permission that can never fire. - $entry.Application | Should -BeFalse -Because ` - "'$permission' is now blocked for Application by Microsoft (per AgentBlockedPermissions.json). It should be removed from MT.1223's curated list because agents can no longer hold it." + # MT.1223 reports a permission held as an application permission or as a delegated grant, so it can + # still fire while either one is allowed. Only a permission blocked for both can never fire. + ($entry.Application -and $entry.Delegated) | Should -BeFalse -Because ` + "'$permission' is now blocked for both Application and Delegated by Microsoft (per AgentBlockedPermissions.json). It should be removed from MT.1223's curated list because agents can no longer hold it either way." } } }