Get-AzureRmRoleAssignment command failing
Cmdlet(s)
PowerShell Version
Instructions: to get PowerShell version, type $PSVersionTable and look for the value associated with PSVersion
latest
Module Version
Azure PS version: 1.0.0
OS Version
Instructions: to get OS version, type $PSversionTable and look for value associated with BuildVersion
Windows 2012 R2
Description
Error when trying to run the PS command: Get-AzureRmRoleAssignment : ##[error]Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown. 2017-01-18T08:40:40.1990848Z Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition
Debug Output
Instructions: to get Debug Output, set $DebugPreference="Continue" and then execute the cmdlet or script causing the issue
Script/Steps for Reproduction
2017-01-18T17:43:54.3907947Z ##[debug]Leaving Initialize-Azure.
2017-01-18T17:43:54.4499767Z ##[command]& 'C:\Users\buildguest\AppData\Local\Temp\bfdd2b32-1828-48c5-a451-d7143f0a9e30.ps1'
2017-01-18T17:43:56.0065186Z ##[debug]Error record:
2017-01-18T17:43:56.1317540Z ##[debug]Get-AzureRmRoleAssignment : Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.
2017-01-18T17:43:56.1337554Z ##[debug]At C:\Users\buildguest\AppData\Local\Temp\bfdd2b32-1828-48c5-a451-d7143f0a9e30.ps1:3 char:1
2017-01-18T17:43:56.1357540Z ##[debug]+ Get-AzureRmRoleAssignment -verbose
2017-01-18T17:43:56.1367563Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-01-18T17:43:56.1387550Z ##[debug] + CategoryInfo : CloseError: (:) [Get-AzureRmRoleAssignment], CloudException
2017-01-18T17:43:56.1407543Z ##[debug] + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.GetAzureRoleAssignmentCommand
2017-01-18T17:43:56.1417557Z ##[debug]
2017-01-18T17:43:56.1447543Z ##[debug]Script stack trace:
2017-01-18T17:43:56.1497562Z ##[debug]at 1 objectIds)
2017-01-18T17:43:56.2549680Z ##[debug] at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClientExtensions.ToPSRoleAssignments(IEnumerable1 assignments, List`1 roleDefinitions, AuthorizationClient policyClient, ActiveDirectoryClient activeDirectoryClient, Boolean excludeAssignmentsForDeletedPrincipals)
2017-01-18T17:43:56.2569844Z ##[debug] at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.FilterRoleAssignments(FilterRoleAssignmentsOptions options, String currentSubscription)
2017-01-18T17:43:56.2579843Z ##[debug] at Microsoft.Azure.Commands.Resources.GetAzureRoleAssignmentCommand.ExecuteCmdlet()
2017-01-18T17:43:56.2599842Z ##[debug] at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
2017-01-18T17:43:56.2959008Z ##[error]Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.
2017-01-18T17:43:56.2959008Z ##[debug]Processed: ##vso[task.logissue type=error]Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.
2017-01-18T17:43:56.2989006Z ##[debug]Processed: ##vso[task.complete result=Failed]
2017-01-18T17:43:56.3229004Z ##[section]Finishing: Azure PowerShell script: InlineScript
@dmittal02 Please include the text of the cmdlet invocation (what command line did you use) and a description of the expected result. Also, can you try your command with the latest version?
To give you more context, we are using this command line in VSTS build Azure PowerShell build task. this is the command line, we use: Get-AzureRmRoleAssignment and this command line will be executed on hosted build agent. In fact for customer when he run it on the private build agent to which he can remote, he get the required data, but I am getting authorization error there as well. Please let me know if that helps. You can also reach out to me at: [email protected] to discuss in more detail.
@markcowl We get the same error when we try to call Get-AzureRmRoleAssignment in our VSTS release pipeline from an Azure PowerShell release task. This is running on a hosted agent with an Azure Resource Manager connection. The Azure PowerShell version on the hosted agent is 3.1.0.
@markcowl Here is the script as with which we are able to reproduce it locally:
$psCredential = New-Object System.Management.Automation.PSCredential(
"serviceprincipalID",
(ConvertTo-SecureString "Password" -AsPlainText -Force))
Add-AzureRMAccount -ServicePrincipal -Tenant "
$additional = @{}
$additional['TenantId'] = "
Get-AzureRmRoleAssignment -debug
You will get the issue. Service principal ID choosen is owner on the subscription.
What are the permissions in ActiveDirectory of your service principal? To use the role assignment cmdlets, you need access to the graph api, which is managed by permissions granted to your service principal in AD. To view role assignments, you will need at least read access to the tenant in AD.
@markcowl It looks like missing AAD permissions were the cause of our issue. Thanks.
@efridman @dmittal02 Can you guys verify that this was resolved?
@markcowl Yes, our problem did turn out to be that the SPN did not have permissions on AAD. Thanks.
@efridman We are running into the same problem. Can you elaborate on what permissions you gave the SPN? We have been trying things, but still no success
@keeshuizer We actually did not check this all the way through, since we don't want to give the SPN permissions on AAD for other reasons. But permissions were missing and that's why we thought that was the issue. I would assume read permissions to read roles and write permissions to assign them, but I'm guessing you tried that?
I have a repro of the issue with current cmdlets, it is definitely related to the whitelist for graph api-version used in the call to graph to get friendly names for the users and groups, and not the permissions on the service principal.
Here is a request/response showing the failure
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
POST
Absolute Uri:
https://graph.windows.net/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/getObjectsByObjectIds?api-version=1.6-internal
Headers:
x-ms-client-request-id : 83854599-8e85-4858-95c9-db7eae89ad68
accept-language : en-US
Body:
{
"objectIds": [
-- redacted --
],
"includeDirectoryObjectReferences": true
}
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
Forbidden
Headers:
ocp-aad-diagnostics-server-name: XYNBldSbijB5bKKmRhxq1vFYS8rdTdBj0OJLIY4iTms=
request-id : 6bd997bd-a7f4-4692-ae08-f19f5136157a
client-request-id : 097a0dcb-d072-4a10-a230-cd4e198547e2
x-ms-dirapi-data-contract-version: 1.6-internal
ocp-aad-session-key :
ynVvvPIP2mAgozVdI3czQ2GZgS8yxN9FKz-wyhh3yVii1HCy93ZYZagfW5owHDfYGypn_eXgD9i1O6Wq6utrZj-1dkEXjoPQqXlFrB3Q36sZA2DqTI56p_-
cPXRiM6pN.FJsGF_JL39ZHV7R7XgD0DkGidkT-KaokgM4QPdcOdE0
Strict-Transport-Security : max-age=31536000; includeSubDomains
Access-Control-Allow-Origin : *
Duration : 632811
Cache-Control : private
Server : Microsoft-IIS/8.5
X-AspNet-Version : 4.0.30319
X-Powered-By : ASP.NET,ASP.NET
Date : Thu, 23 Feb 2017 01:32:14 GMT
Body:
{
"odata.error": {
"code": "Authentication_Unauthorized",
"message": {
"lang": "en",
"value": "Access denied to the specified API version."
}
}
}
cmdlet nor working for me, too. A simple Get-AzureRMRoleAssignment ist not working any more and I don't have any idea what changed... Here is the output, pls. help:
PS C:\PublicProjects\PowerShell> Login-AzureRmAccount
Environment : AzureCloud
Account : [email protected]
TenantId : 8dff03-...-312cf7c
SubscriptionId : abcde-730316a2e9e0
SubscriptionName : Visual Studio Ultimate mit MSDN
CurrentStorageAccount :
PS C:\PublicProjects\PowerShell> Get-AzureRmRoleAssignment
Get-AzureRmRoleAssignment : Run Login-AzureRmAccount to login.
In Zeile:1 Zeichen:1
+ Get-AzureRmRoleAssignment
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-AzureRmRoleAssignment], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.Resources.GetAzureRoleAssignmentCommand
@gitralf This looks unrelated to the issue at hand - the issue you are seeing is likely that you have incompatible versions of the cmdlets installed. Normally you can resolve this by:
(1) Installing the latest MSI -or- (2) Updating to the latest AzureRM and Azure modules from the PSGallery.
If you'd like to confirm this is the issue, run
Get-Module -ListAvailable
And send the output - most likely there will be some mismatched moduel versions.
This issue is due to be resolved when the newest version of AAD Graph is released. This is due to heppen in the May release, so moving this to May
@shuagarw We need the fix for azurestack in the stack-dev branch
@shuagarw, any update on this?
@rbacask for FYI @darshanhs90 as he is working on this fix in master branch. @afshins to port the fix in AzureStack once it is completed in master branch.
This should be fixed. Please let us know if you see a recurrence
appears to be working for me, thanks!
Same error when I use the command with my Automation Account (Run As Account created by default with my Automation account) Get-AzureRmRoleAssignment : Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown. My modules have been updated, AzureRM.Resources : version 4.1.0