Repository navigation
feat: add monthly agent blocked permissions snapshot automation #2637
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
Dfrank77
wants to merge
13
commits into
maester365:main
Choose a base branch
from
Dfrank77:feat/agent-blocked-permissions-automation
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
13 commits
Select commit
Hold shift + click to select a range
6720444
feat: add monthly agent blocked permissions snapshot automation
Dfrank77 3c8ea4c
fix: address CI failure and CodeRabbit findings
Dfrank77 3496a95
fix: move snapshot to internal/generated and address review feedback
Dfrank77 20d422a
fix: add BOM and correct stale comments
Dfrank77 9ac6984
Merge remote-tracking branch 'upstream/main' into feat/agent-blocked-…
Dfrank77 f1cf8b1
fix: make missing snapshot fail the drift test and remove dead code
Dfrank77 ae851e0
Merge remote-tracking branch 'upstream/main' into feat/agent-blocked-…
Dfrank77 11e661c
Read MT.1223's permission list from a shared function in the drift test
Dfrank77 b0323c2
Check the snapshot path literally in the drift test
Dfrank77 e255d08
fix: sort agent blocked permissions ordinally and validate the source…
Dfrank77 6fc9320
feat: report failed snapshot runs and replace the fixed row floor
Dfrank77 9782d75
Merge remote-tracking branch 'upstream/main' into feat/agent-blocked-…
Dfrank77 197754d
Drift test: fail only when a permission is blocked for both paths
Dfrank77 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
196 changes: 196 additions & 0 deletions
196
.github/workflows/update-agent-blocked-permissions.yaml
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,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) | ||
| 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 | ||
|
|
||
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.