Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 18, 2025

Fix RoleAssignment cmdlets to properly handle insufficient MSGraph permissions by falling back to cached principal type

Problem Fixed:
The ToPSRoleAssignment() method was incorrectly handling insufficient MSGraph permissions. When Active Directory lookup failed due to authorization denied or not found errors, it immediately set ObjectType = "Unknown" instead of following the documented priority order.

Root Cause:

  • Line 101 in AuthorizationClientExtensions.cs created PSADObject with Type = UnknownType when AD lookup failed
  • Line 202 in batch processing had the same issue
  • This skipped the intended fallback to cached assignment.PrincipalType

Solution:

  • Modified exception handling to use assignment.PrincipalType ?? UnknownType instead of immediately using UnknownType
  • Applied same fix to both single assignment and batch processing methods
  • Updated ChangeLog.md for Resources module
  • Addressed PR feedback: reverted main ChangeLog.md and test file changes, updated code comment

Priority Order Now Correctly Implemented:

  1. Live Active Directory object type (when lookup succeeds)
  2. Cached principal type from assignment (fallback when lookup fails)
  3. "Unknown" type (only when both above are unavailable)

Files Changed:

  • src/Resources/Resources/Models.Authorization/AuthorizationClientExtensions.cs - Core fix
  • src/Resources/Resources/ChangeLog.md - Added changelog entry

Fixes #28583.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

…ssions

Co-authored-by: isra-fel <11371776+isra-fel@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [Bug]: RoleAssignment cmdlets didn't handle it properly when insufficient MSGraph permission Fix RoleAssignment ObjectType fallback for insufficient MSGraph permissions Sep 18, 2025
Copilot finished work on behalf of isra-fel September 18, 2025 06:57
@Copilot Copilot AI requested a review from isra-fel September 18, 2025 06:57
ChangeLog.md Outdated
#### Az.Relay 2.1.2
* Update the outputs of breaking change announcements.

#### Az.Resources 8.1.1
Copy link
Collaborator

Choose a reason for hiding this comment

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

why you changed this file copilot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the main ChangeLog.md by mistake. The change has been reverted in commit 56c9d2b.

Copy link
Member

Choose a reason for hiding this comment

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

Please revert the added test in this file as it isn't feasible to mock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the test file changes in commit 56c9d2b as it wasn't feasible to mock properly.

Copy link
Member

Choose a reason for hiding this comment

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

Please revert the changes in this file as it is purely generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the main ChangeLog.md changes in commit 56c9d2b.

{
adObject = new PSADObject() { Id = assignment.PrincipalId, Type = UnknownType};
// When AD lookup fails due to insufficient permissions or not found,
// fall back to cached principal type instead of immediately using "Unknown"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// fall back to cached principal type instead of immediately using "Unknown"
// fall back to cached principal type from response,
// then finally fall back to "Unknown"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment as suggested in commit 56c9d2b.

@isra-fel
Copy link
Member

@copilot please address the comments

…e comment

Co-authored-by: isra-fel <11371776+isra-fel@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 18, 2025

@copilot please address the comments

Addressed all feedback comments in commit 56c9d2b:

  • Reverted main ChangeLog.md (generated file)
  • Reverted test file changes (not feasible to mock)
  • Updated comment as suggested


AuthorizationClient.ValidateScope(null, true);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

this test creates arbitrary value for assignment object and performs assert for these arbitrary values, does it make sense copilot?

## Upcoming Release
* Fixed issue where RoleAssignment cmdlets did not properly handle insufficient MSGraph permissions
- When Active Directory lookup fails due to insufficient permissions, the cmdlets now fall back to cached principal type instead of immediately using "Unknown" type
- Fixed issue [#28583]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why you need 2 bullet points when you can do a one liner, copilot?

@isra-fel isra-fel marked this pull request as ready for review September 19, 2025 00:22
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 00:22
Copy link
Contributor

@Copilot 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 RoleAssignment cmdlets to properly handle insufficient MSGraph permissions by implementing correct fallback logic to cached principal types instead of immediately defaulting to "Unknown".

Key changes:

  • Corrected the priority order for object type determination in role assignment processing
  • Applied the fix to both single assignment and batch processing methods
  • Added proper changelog documentation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Resources/Resources/Models.Authorization/AuthorizationClientExtensions.cs Fixed exception handling to use cached principal type fallback instead of immediately setting "Unknown" type
src/Resources/Resources/ChangeLog.md Added changelog entry documenting the MSGraph permissions fix

@isra-fel
Copy link
Member

/azp run azure-powershell - security-tools

Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@isra-fel isra-fel removed their assignment Sep 19, 2025
@VeryEarly VeryEarly merged commit 4b18d05 into main Sep 19, 2025
12 checks passed
@VeryEarly VeryEarly deleted the copilot/fix-28583 branch September 19, 2025 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RoleAssignment cmdlets didn't handle it properly when insufficient MSGraph permission

3 participants