Skip to content

Fix Graph scope in SP provisioning script (#414)#415

Open
biswapm wants to merge 1 commit into
mainfrom
pmohapatra-ToolsServicePrincipal
Open

Fix Graph scope in SP provisioning script (#414)#415
biswapm wants to merge 1 commit into
mainfrom
pmohapatra-ToolsServicePrincipal

Conversation

@biswapm
Copy link
Copy Markdown
Contributor

@biswapm biswapm commented May 13, 2026

Summary

  • Replace AppRoleAssignment.ReadWrite.All with Application.ReadWrite.All in Connect-MgGraph — the script only calls Get-MgServicePrincipal/New-MgServicePrincipal, both of which require Application.*, not AppRoleAssignment.*.
  • Update the 403 error-handler hint at line 234 so it no longer points users at the wrong permission.

Fixes #414. With the previous scope, V2 per-server SPs that didn't already exist failed with Authorization_RequestDenied (403). The V1 ATG SP is typically pre-existing so the bug was masked there.

Chose replace over append (the reporter's suggested diff) for least-privilege: the script never exercises AppRoleAssignment.* APIs, so admins shouldn't be asked to consent to that permission.

Test plan

  • Run script on macOS in V1 mode against a tenant where the V1 SP already exists (verify no regression on the pre-existing-SP path).
  • Run script on macOS in V2 mode against a tenant missing one or more V2 per-server SPs (verify creation succeeds where it previously hit 403).
  • Run script in All mode end-to-end.
  • Verify the consent dialog now requests only Application.ReadWrite.All.
  • Trigger the 403 path (e.g. with a non-admin account) and confirm the error hint now displays Application.ReadWrite.All.

New-MgServicePrincipal requires Application.ReadWrite.All, not
AppRoleAssignment.ReadWrite.All. The script never calls any app-role-
assignment APIs, so requesting that scope was both insufficient (caused
403 Authorization_RequestDenied when creating V2 per-server SPs) and
unnecessary over-scope. Replace with the correct least-privilege scope
and update the matching 403 error hint so it no longer points users at
a permission that wouldn't fix their problem.
Copilot AI review requested due to automatic review settings May 13, 2026 08:47
@biswapm biswapm requested review from a team as code owners May 13, 2026 08:47
@github-actions github-actions Bot added the bug Something isn't working label May 13, 2026
@github-actions
Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the Microsoft Graph delegated scope requested by the service principal provisioning PowerShell script so it can successfully create missing per-server (V2) service principals, and updates the related 403 guidance to match the corrected permission.

Changes:

  • Update Connect-MgGraph to request Application.ReadWrite.All (instead of AppRoleAssignment.ReadWrite.All) to align with the script’s actual use of Get-MgServicePrincipal/New-MgServicePrincipal.
  • Update the “Required Permissions” hint in the insufficient-privileges error message to reference Application.ReadWrite.All.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New-Agent365ToolsServicePrincipalProdPublic.ps1 requests insufficient Graph scope — 403 on `New-MgServicePrincipal

4 participants