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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions .github/workflows/update-agent-blocked-permissions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
name: update-agent-blocked-permissions

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: {}

concurrency:
group: update-agent-blocked-permissions
cancel-in-progress: false

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:
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
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
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'

$diff = @(git diff --unified=0 -- $env:SNAPSHOT_PATH)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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

$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@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
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/generated/AgentBlockedPermissions.json` from
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
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-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

Loading
Loading