Skip to content
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

New-AzRoleAssignment failing with error 'Object reference not set to an instance of an object' in Az.Resources 6.3.0 #19793

Closed
rakku-ms opened this issue Oct 12, 2022 · 6 comments · Fixed by #19806
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. good first issue Issues suited for folks who want to help for the first time. Resource Authorization AzRole* in Az.Resources Service Attention This issue is responsible by Azure service team. Tracking We will track status and follow internally

Comments

@rakku-ms
Copy link

Description

SP role assignment is failing in the latest version of Az.Resources (6.3.0) module

PS C:\WINDOWS\system32> New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.AppId
New-AzRoleAssignment : Object reference not set to an instance of an object.
At line:1 char:1

  • New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.Ap ...
  •   + CategoryInfo          : CloseError: (:) [New-AzRoleAssignment], NullReferenceException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
    
    

Issue script & Debug output

PS C:\WINDOWS\system32> $DebugPreference = 'Continue'
PS C:\WINDOWS\system32> New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.AppId
DEBUG: 1:46:32 PM - NewAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithSPNParameterSet'.
DEBUG: 1:46:32 PM - using account id '<redacted>'...
DEBUG: 1:46:32 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:46:32 PM - [ConfigManager] Got [True] from [EnableDataCollection], Module = [], Cmdlet = [].
New-AzRoleAssignment : Object reference not set to an instance of an object.
At line:1 char:1
+ New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.Ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzRoleAssignment], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
 
DEBUG: 1:46:32 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Resources:6.3.0; CommandName: New-AzRoleAssignment; PSVersion: 5.1.22621.608; IsSuccess: False; Duration: 00:00:00.0450351; Exception: Object reference not
 set to an instance of an object.;
DEBUG: 1:46:32 PM - NewAzureRoleAssignmentCommand end processing.

PS C:\WINDOWS\system32> $sp
DisplayName Id                                   AppId                               
----------- --                                   -----                               
test sp     2179d65e-3374-4a74-a7ee-9e08b67ad51d 934a80d1-211e-44ad-91e6-684d8dfade96

Environment data

PS C:\WINDOWS\system32> $PSVersionTable
Name                           Value                                                                                                                                                       
----                           -----                                                                                                                                                       
PSVersion                      5.1.22621.608                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                     
BuildVersion                   10.0.22621.608                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                             
WSManStackVersion              3.0                                                                                                                                                         
PSRemotingProtocolVersion      2.3                                                                                                                                                         
SerializationVersion           1.1.0.1

Module versions

PS C:\WINDOWS\system32> Get-Module Az*

ModuleType Version    Name                                ExportedCommands                                                                                                                 
---------- -------    ----                                ----------------                                                                                                                 
Script     2.10.2     Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}                                                         
Script     6.3.0      Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}

Error output

PS C:\WINDOWS\system32> Resolve-AzError
DEBUG: 1:49:04 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 1:49:04 PM - using account id '<redacted>'...
DEBUG: 1:49:04 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.


   HistoryId: 23


Message        : Object reference not set to an instance of an object.
StackTrace     :    at Microsoft.Azure.Commands.Resources.Models.Authorization.FilterRoleAssignmentsOptions.get_Scope()
                    at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.NullReferenceException
InvocationInfo : {New-AzRoleAssignment}
Line           : New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.AppId
Position       : At line:1 char:1
                 + New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.Ap ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 23
@rakku-ms rakku-ms added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Oct 12, 2022
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Oct 12, 2022
@dingmeng-xue dingmeng-xue added Resource Authorization AzRole* in Az.Resources Service Attention This issue is responsible by Azure service team. good first issue Issues suited for folks who want to help for the first time. labels Oct 13, 2022
@ghost
Copy link

ghost commented Oct 13, 2022

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @darshanhs90, @AshishGargMicrosoft.

Issue Details

Description

SP role assignment is failing in the latest version of Az.Resources (6.3.0) module

PS C:\WINDOWS\system32> New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.AppId
New-AzRoleAssignment : Object reference not set to an instance of an object.
At line:1 char:1

  • New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.Ap ...
  •   + CategoryInfo          : CloseError: (:) [New-AzRoleAssignment], NullReferenceException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
    
    

Issue script & Debug output

PS C:\WINDOWS\system32> $DebugPreference = 'Continue'
PS C:\WINDOWS\system32> New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.AppId
DEBUG: 1:46:32 PM - NewAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithSPNParameterSet'.
DEBUG: 1:46:32 PM - using account id '<redacted>'...
DEBUG: 1:46:32 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:46:32 PM - [ConfigManager] Got [True] from [EnableDataCollection], Module = [], Cmdlet = [].
New-AzRoleAssignment : Object reference not set to an instance of an object.
At line:1 char:1
+ New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.Ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzRoleAssignment], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
 
DEBUG: 1:46:32 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Resources:6.3.0; CommandName: New-AzRoleAssignment; PSVersion: 5.1.22621.608; IsSuccess: False; Duration: 00:00:00.0450351; Exception: Object reference not
 set to an instance of an object.;
DEBUG: 1:46:32 PM - NewAzureRoleAssignmentCommand end processing.

PS C:\WINDOWS\system32> $sp
DisplayName Id                                   AppId                               
----------- --                                   -----                               
test sp     2179d65e-3374-4a74-a7ee-9e08b67ad51d 934a80d1-211e-44ad-91e6-684d8dfade96

Environment data

PS C:\WINDOWS\system32> $PSVersionTable
Name                           Value                                                                                                                                                       
----                           -----                                                                                                                                                       
PSVersion                      5.1.22621.608                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                     
BuildVersion                   10.0.22621.608                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                             
WSManStackVersion              3.0                                                                                                                                                         
PSRemotingProtocolVersion      2.3                                                                                                                                                         
SerializationVersion           1.1.0.1

Module versions

PS C:\WINDOWS\system32> Get-Module Az*

ModuleType Version    Name                                ExportedCommands                                                                                                                 
---------- -------    ----                                ----------------                                                                                                                 
Script     2.10.2     Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}                                                         
Script     6.3.0      Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}

Error output

PS C:\WINDOWS\system32> Resolve-AzError
DEBUG: 1:49:04 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 1:49:04 PM - using account id '<redacted>'...
DEBUG: 1:49:04 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.


   HistoryId: 23


Message        : Object reference not set to an instance of an object.
StackTrace     :    at Microsoft.Azure.Commands.Resources.Models.Authorization.FilterRoleAssignmentsOptions.get_Scope()
                    at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.NullReferenceException
InvocationInfo : {New-AzRoleAssignment}
Line           : New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.AppId
Position       : At line:1 char:1
                 + New-AzRoleAssignment -RoleDefinitionName Reader -ApplicationId $sp.Ap ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 23
Author: rakku-ms
Assignees: -
Labels:

Resource Authorization, Service Attention, bug, good first issue

Milestone: -

@dingmeng-xue dingmeng-xue added the Tracking We will track status and follow internally label Oct 13, 2022
@ellio246t
Copy link

I'm getting the same error using the same module versions but a different parameter set:

New-AzRoleAssignment -ResourceGroupName bieno-da12-d-00000-rg -ObjectId "8ef6f3b3-df36-4bbe-89bf-371811e437a9" -RoleDefinitionName Contributor -Debug
DEBUG: 4:05:09 PM - NewAzureRoleAssignmentCommand begin processing with ParameterSet 'ResourceGroupWithObjectIdParameterSet'.
DEBUG: 4:05:09 PM - using account id 'd0f394e7-a998-422d-xxxxxxxxxxxxxxxxx'...
DEBUG: 4:05:09 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 4:05:09 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
New-AzRoleAssignment: Object reference not set to an instance of an object.
DEBUG: 4:05:09 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Resources:6.3.0; CommandName: New-AzRoleAssignment; PSVersion: 7.2.6; IsSuccess: False; Duration: 00:00:00.0681178; Exception: Object reference not set to an instance of an object.;
DEBUG: 4:05:09 PM - NewAzureRoleAssignmentCommand end processing.

@Goxu92
Copy link

Goxu92 commented Oct 13, 2022

Hello! our build system is also facing the similar issue starting with similar time with other folks here.
$role = Get-AzRoleAssignment -SignInName $user.Email -ResourceGroupName $ResourceGroupName -ResourceName $ApplicationGroup.ApplicationGroupName -ResourceType Microsoft.DesktopVirtualization/applicationgroups -RoleDefinitionName "Desktop Virtualization User" 2>&1
if ($null -eq $role)
{
$result = New-AzRoleAssignment -SignInName $user.Email -ResourceGroupName $ResourceGroupName -ResourceName $ApplicationGroup.ApplicationGroupName -ResourceType Microsoft.DesktopVirtualization/applicationgroups -RoleDefinitionName "Desktop Virtualization User" 2>&1
CheckResult($result)
}

Failure we get is this:
##[error]New-AzRoleAssignment : Object reference not set to an instance of an object.
At D:\a_work\1\s\src\yaml\templates\scripts\CreateArmWorkSpace.ps1:534 char:35

  • ... $result = New-AzRoleAssignment -SignInName $user.Email -ResourceGro ...

  • 
    
  • CategoryInfo : CloseError: (:) [New-AzRoleAssignment], NullReferenceException

  • FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand

@andrePKI
Copy link

I got the same/very similar errors. Not when I run with a user account from a powershell session (Connect-AzAccount/set-AzContext/New-AzRoleAssignment), but when I run exact same script from Azure DevOps pipeline I get this error. Build agent has az.Resources version 6.3.0 and Powershell

Name                           Value                                                                                                                                                                 
----                           -----                                                                                                                                                                 
PSVersion                      5.1.14393.5127                                                                                                                                                    
PSEdition                      Desktop                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                               
BuildVersion                   10.0.14393.5127                                                                                                                                                     
CLRVersion                     4.0.30319.42000                                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                                   
SerializationVersion           1.1.0.1

@dingmeng-xue
Copy link
Member

We are fixing this issue. You can expect a hotfix in the next week.

@dingmeng-xue
Copy link
Member

We have published https://www.powershellgallery.com/packages/Az.Resources/6.3.1. Please try it. Close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. good first issue Issues suited for folks who want to help for the first time. Resource Authorization AzRole* in Az.Resources Service Attention This issue is responsible by Azure service team. Tracking We will track status and follow internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants