Skip to content

Conversation

atomassi
Copy link

@atomassi atomassi commented Oct 4, 2025

Description

Fixes #28640

The Get-AzRoleAssignment lists Azure RBAC role assignments at the specified scope.
Based on the parameters it performs in a different way. Table below

PowerShell Command Resulting REST API Call
Get-AzRoleAssignment -ObjectId "<objectId>" https://management.azure.com//subscriptions/<sub>/providers/Microsoft.Authorization/roleAssignments?$filter=principalId eq '<objectId>'&api-version=2020-08-01-preview
Get-AzRoleAssignment -ObjectId "<objectId>" -Scope "/subscriptions/<sub>" -AtScope https://management.azure.com//subscriptions/<sub>/providers/Microsoft.Authorization/roleAssignments?$filter=atScope()&api-version=2020-08-01-preview
Get-AzRoleAssignment -ObjectId "87eb1e89-2d6f-4e29-a257-c4d01d0f2957" -Scope "/" -AtScope https://management.azure.com///providers/Microsoft.Authorization/roleAssignments?$filter=atScope()&api-version=2020-08-01-preview
  • In the first case filtering for the principal is made server side by Microsoft.Authorization. Any GUID format will be accepted and filtering will be correctly applied.
  • In the second and third cases, it's made client side.

The issue is that client side principal is compared as string, so this will result in different results based on the principal format

  • Get-AzRoleAssignment -ObjectId "87eb1e89-2d6f-4e29-a257-c4d01d0f2957" would return the same result as Get-AzRoleAssignment -ObjectId "87eb1e892d6f4e29a257c4d01d0f2957"
  • Get-AzRoleAssignment -ObjectId "87eb1e89-2d6f-4e29-a257-c4d01d0f2957" -Scope "/" -AtScope would not return the same result as Get-AzRoleAssignment -ObjectId "87eb1e892d6f4e29a257c4d01d0f2957" -Scope "/" -AtScope

if (needsFilterPrincipalId)
{
result = result.Where(r => r.ObjectId?.Equals(principalId, StringComparison.OrdinalIgnoreCase) ?? false).ToList();
}

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 09:59
Copy link

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

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 a bug in the Get-AzRoleAssignment cmdlet where GUID string comparison for client-side filtering was causing inconsistent results depending on the GUID format used. The issue occurred when using the -AtScope parameter, which triggers client-side filtering instead of server-side filtering.

Key changes:

  • Implements proper GUID comparison in the AuthorizationClient filtering logic
  • Adds comprehensive test coverage for different GUID format handling
  • Ensures consistent results regardless of whether GUIDs are provided in formats like 87eb1e89-2d6f-4e29-a257-c4d01d0f2957 or 87eb1e892d6f4e29a257c4d01d0f2957

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
AuthorizationClient.cs Updates principal ID filtering logic to parse and compare GUIDs properly instead of string comparison
RoleAssignmentTests.ps1 Adds new test function to validate GUID format handling across different GUID string formats
RoleAssignmentTests.cs Registers the new test function as a unit test method

@atomassi atomassi force-pushed the dev/atomassilli/guid branch from 84d27ee to 868b327 Compare October 4, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Get-AzRoleAssignment cmdlet does not handle properly different principal GUID formats
1 participant