New-AzRoleAssignment fails when running as a Service Principal account
- Make sure you are able to reproduce this issue on the latest released version of Az
- https://www.powershellgallery.com/packages/Az
- Please search the existing issues to see if there has been a similar issue filed
- For issue related to importing a module, please refer to our troubleshooting guide:
- https://github.com/Azure/azure-powershell/blob/master/documentation/troubleshoot-module-load.md
-->
Description
I am using an Azure DevOps release for organizational users to request access to Azure Resource Groups in a request approval workflow. The script fails when run as a Service Principal account. Debug output shows that the SP is missing an authorization; Body: { "odata.error": { "code": "Authorization_RequestDenied", "message": { "lang": "en", "value": "Insufficient privileges to complete the operation." }, "requestId": "46e72f0f-a308-4742-ab9e-720deb10579b", "date": "2019-05-08T16:53:33" } } The Service Principal is in the Owner role for the subscription This issue (119042924001587) was opened under the DevOps escalation team and I was directed to file the bug here.
Steps to reproduce
Add a service principal as Owner at the subscription scope Add-AzAccount -Credential (New-Object System.Management.Automation.PSCredential ("Service Principal Client Id", (ConvertTo-SecureString "Service Principal Key" -AsPlainText -Force))) -TenantId "Tenant ID" -ServicePrincipal
New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Environment data
Name Value
PSVersion 5.1.17134.590
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.590
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Module versions
Name Version
Az.Accounts 1.3.0
Az.Accounts 1.2.1
Az.Aks 1.0.1
Az.AnalysisServices 1.0.1
Az.AnalysisServices 1.0.0
Az.ApiManagement 1.0.0
Az.ApplicationInsights 1.0.0
Az.Automation 1.1.0
Az.Batch 1.0.0
Az.Billing 1.0.0
Az.Cdn 1.0.1
Az.CognitiveServices 1.0.0
Az.Compute 1.3.0
Az.Compute 1.2.0
Az.ContainerInstance 1.0.0
Az.ContainerRegistry 1.0.1
Az.DataFactory 1.0.1
Az.DataLakeAnalytics 1.0.0
Az.DataLakeStore 1.0.2
Az.DevTestLabs 1.0.0
Az.Dns 1.0.0
Az.EventGrid 1.1.0
Az.EventHub 1.0.0
Az.HDInsight 1.0.0
Az.IotHub 1.0.2
Az.KeyVault 1.0.1
Az.LogicApp 1.1.0
Az.MachineLearning 1.0.0
Az.MarketplaceOrdering 1.0.0
Az.Media 1.0.0
Az.Monitor 1.0.0
Az.Network 1.1.0
Az.NotificationHubs 1.0.0
Az.OperationalInsights 1.0.0
Az.PolicyInsights 1.0.0
Az.PowerBIEmbedded 1.0.0
Az.RecoveryServices 1.0.1
Az.RecoveryServices 1.0.0
Az.RedisCache 1.0.0
Az.Relay 1.0.0
Az.Resources 1.1.2
Az.Resources 1.1.1
Az.ServiceBus 1.0.0
Az.ServiceFabric 1.0.1
Az.SignalR 1.0.2
Az.Sql 1.2.0
Az.Sql 1.1.0
Az.Storage 1.0.2
Az.StreamAnalytics 1.0.0
Az.TrafficManager 1.0.1
Az.Websites 1.1.0
AzureAD 2.0.2.4
Microsoft.PowerShell.Operation.Validation 1.0.1
PackageManagement 1.0.0.1
Pester 3.4.0
PowerShellGet 1.0.0.1
PSReadline 1.2
AppBackgroundTask 1.0.0.0
AppLocker 2.0.0.0
AppvClient 1.0.0.0
Appx 2.0.0.0
AssignedAccess 1.0.0.0
BitLocker 1.0.0.0
BitsTransfer 2.0.0.0
BranchCache 1.0.0.0
CimCmdlets 1.0.0.0
ConfigCI 1.0
Defender 1.0
DeliveryOptimization 1.0.0.0
DirectAccessClientComponents 1.0.0.0
Dism 3.0
DnsClient 1.0.0.0
EventTracingManagement 1.0.0.0
International 2.0.0.0
iSCSI 1.0.0.0
ISE 1.0.0.0
Kds 1.0.0.0
Microsoft.PowerShell.Archive 1.0.1.0
Microsoft.PowerShell.Diagnostics 3.0.0.0
Microsoft.PowerShell.Host 3.0.0.0
Microsoft.PowerShell.LocalAccounts 1.0.0.0
Microsoft.PowerShell.Management 3.1.0.0
Microsoft.PowerShell.ODataUtils 1.0
Microsoft.PowerShell.Security 3.0.0.0
Microsoft.PowerShell.Utility 3.1.0.0
Microsoft.WSMan.Management 3.0.0.0
MMAgent 1.0
MsDtc 1.0.0.0
NetAdapter 2.0.0.0
NetConnection 1.0.0.0
NetEventPacketCapture 1.0.0.0
NetLbfo 2.0.0.0
NetNat 1.0.0.0
NetQos 2.0.0.0
NetSecurity 2.0.0.0
NetSwitchTeam 1.0.0.0
NetTCPIP 1.0.0.0
NetworkConnectivityStatus 1.0.0.0
NetworkSwitchManager 1.0.0.0
NetworkTransition 1.0.0.0
PcsvDevice 1.0.0.0
PersistentMemory 1.0.0.0
PKI 1.0.0.0
PnpDevice 1.0.0.0
PrintManagement 1.1
ProcessMitigations 1.0.11
Provisioning 3.0
PSDesiredStateConfiguration 1.1
PSDiagnostics 1.0.0.0
PSScheduledJob 1.1.0.0
PSWorkflow 2.0.0.0
PSWorkflowUtility 1.0.0.0
ScheduledTasks 1.0.0.0
SecureBoot 2.0.0.0
SmbShare 2.0.0.0
SmbWitness 2.0.0.0
StartLayout 1.0.0.0
Storage 2.0.0.0
TLS 2.0.0.0
TroubleshootingPack 1.0.0.0
TrustedPlatformModule 2.0.0.0
UEV 2.1.639.0
VpnClient 2.0.0.0
Wdac 1.0.0.0
WindowsDeveloperLicense 1.0.0.0
WindowsErrorReporting 1.0
WindowsSearch 1.0.0.0
WindowsUpdate 1.0.0.0
WindowsUpdateProvider 1.0.0.2
ActiveRolesConfiguration 7.1
ActiveRolesManagementShell 7.1
## Debug output
<!-- Set $DebugPreference='Continue' before running the repro and paste the resulting debug stream in the below code block -->
DEBUG: 12:06:46 PM - ConnectAzureRmAccountCommand begin processing with ParameterSet 'ServicePrincipalWithSubscriptionId'.
DEBUG: 12:06:46 PM - using account id '223d1593-34db-4647-9029-ac7d00a19d67'...
DEBUG: 12:06:46 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 12:06:46 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 12:06:46 PM - Using Autosave scope 'CurrentUser'
WARNING: The provided service principal secret will be included in the 'AzureRmContext.json' file found in the user profile ( C:\Users\rnb6138\.Azure ). Please ensure that this directory has appropriate
protections.
DEBUG: 12:06:46 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 12:06:46 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 12:06:46 PM - Using Autosave scope 'CurrentUser'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '335a6d75-c3eb-4b1a-ac08-d49338816ca0', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9
cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions?api-version=2016-06-01
Headers:
x-ms-client-request-id : 9101beea-570e-42b0-bea3-3b6eaf26cf4e
accept-language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Pragma : no-cache
x-ms-ratelimit-remaining-tenant-reads: 11999
x-ms-request-id : 7f1f92b1-57db-4db9-b211-5ffbf4d84185
x-ms-correlation-request-id : 7f1f92b1-57db-4db9-b211-5ffbf4d84185
x-ms-routing-request-id : SOUTHCENTRALUS:20190508T170654Z:7f1f92b1-57db-4db9-b211-5ffbf4d84185
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Cache-Control : no-cache
Date : Wed, 08 May 2019 17:06:54 GMT
Body:
{
"value": [
{
"id": "/subscriptions/9bc700bd-571c-4759-9b11-985b79ee36b3",
"subscriptionId": "9bc700bd-571c-4759-9b11-985b79ee36b3",
"displayName": "HCA - Enterprise",
"state": "Enabled",
"subscriptionPolicies": {
"locationPlacementId": "Public_2014-09-01",
"quotaId": "EnterpriseAgreement_2014-09-01",
"spendingLimit": "Off"
},
"authorizationSource": "RoleBased"
},
{
"id": "/subscriptions/9e6ea445-b44c-4447-b18d-03cc099aa003",
"subscriptionId": "9e6ea445-b44c-4447-b18d-03cc099aa003",
"displayName": "HCA - DevTest",
"state": "Enabled",
"subscriptionPolicies": {
"locationPlacementId": "Public_2014-09-01",
"quotaId": "EnterpriseAgreement_2014-09-01",
"spendingLimit": "Off"
},
"authorizationSource": "RoleBased"
}
]
}
DEBUG: AzureQoSEvent: CommandName - Connect-AzAccount; IsSuccess - True; Duration - 00:00:08.7203437; Exception - ;
DEBUG: Finish sending metric.
DEBUG: 12:06:55 PM - ConnectAzureRmAccountCommand end processing.
DEBUG: 12:06:55 PM - ConnectAzureRmAccountCommand end processing.
Account SubscriptionName TenantId Environment
------- ---------------- -------- -----------
223d1593-34db-4647-9029-ac7d00a19d67 HCA - Enterprise 335a6d75-c3eb-4b1a-ac08-d49338816ca0 AzureCloud
PS U:\> New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
DEBUG: 12:07:04 PM - NewAzureRoleAssignmentCommand begin processing with ParameterSet 'ResourceGroupWithSignInNameParameterSet'.
DEBUG: 12:07:05 PM - using account id '223d1593-34db-4647-9029-ac7d00a19d67'...
DEBUG: [Common.Authentication]: Authenticating using Account: '223d1593-34db-4647-9029-ac7d00a19d67', environment: 'AzureCloud', tenant: '335a6d75-c3eb-4b1a-ac08-d49338816ca0'
DEBUG: [Common.Authentication]: Authenticating using Account: '223d1593-34db-4647-9029-ac7d00a19d67', environment: 'AzureCloud', tenant: '335a6d75-c3eb-4b1a-ac08-d49338816ca0'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://graph.windows.net/335a6d75-c3eb-4b1a-ac08-d49338816ca0/users?$filter=userPrincipalName eq 'rnb6138%40hca.corpad.net'&api-version=1.6
Headers:
x-ms-client-request-id : 0d3fb2d0-82b5-413e-9363-3633a0d14854
accept-language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
Forbidden
Headers:
Pragma : no-cache
ocp-aad-diagnostics-server-name: gKxHTLxqRzyd5BoZh/K02jPjfqm6SFlkXqRCXGmt0wY=
request-id : d8eaad1e-f290-48e7-bf0f-81d13c94b572
client-request-id : cd84c7c8-8b5f-4a2d-a4df-a3f6d4f1f896
x-ms-dirapi-data-contract-version: 1.6
ocp-aad-session-key : 2oi6e6QKnZTbn89ZDYUH_HGdGZEbS-9zMzO1xWEhcZjdKNKwKk57cAMvd0gFhA-ntT4tP9WTKRmIB9viq4wApfCku5I5G9HHhWT15o9-H5QZP7UaV88v9PpqE5pxT15Z.mKxvgOTNsHo5zjR5_onpwK-_Vy5iT9K0yKGk4_04Yl
U
DataServiceVersion : 3.0;
Strict-Transport-Security : max-age=31536000; includeSubDomains
Access-Control-Allow-Origin : *
Duration : 477637
Cache-Control : no-cache
Date : Wed, 08 May 2019 17:07:05 GMT
X-AspNet-Version : 4.0.30319
X-Powered-By : ASP.NET
Body:
{
"odata.error": {
"code": "Authorization_RequestDenied",
"message": {
"lang": "en",
"value": "Insufficient privileges to complete the operation."
},
"requestId": "d8eaad1e-f290-48e7-bf0f-81d13c94b572",
"date": "2019-05-08T17:07:06"
}
}
New-AzRoleAssignment : The provided information does not map to an AD object id.
At line:1 char:1
+ New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzRoleAssignment], KeyNotFoundException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
DEBUG: AzureQoSEvent: CommandName - New-AzRoleAssignment; IsSuccess - False; Duration - 00:00:03.3685153; Exception - System.Collections.Generic.KeyNotFoundException: The provided information does not ma
p to an AD object id.
at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options)
at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId)
at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 12:07:08 PM - NewAzureRoleAssignmentCommand end processing.
DEBUG: 12:07:08 PM - NewAzureRoleAssignmentCommand end processing.
Error output
DEBUG: 12:10:12 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'. DEBUG: 12:10:12 PM - using account id '223d1593-34db-4647-9029-ac7d00a19d67'...
HistoryId: 16
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose Position : At line:1 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 16
HistoryId: 12
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Position : At line:7 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 12
HistoryId: 10
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Position : At line:6 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 10
HistoryId: 9
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Position : At line:6 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 9
HistoryId: 7
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Position : At line:4 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 7
HistoryId: 6
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Position : At line:4 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 6
HistoryId: 5
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'HCAOpsAdmin' -Debug -Verbose
Position : At line:4 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 5
HistoryId: 4
Message : The provided information does not map to an AD object id. StackTrace : at Microsoft.Azure.Commands.ActiveDirectory.ActiveDirectoryClient.GetObjectId(ADObjectFilterOptions options) at Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient.CreateRoleAssignment(FilterRoleAssignmentsOptions parameters, Guid roleAssignmentId) at Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Collections.Generic.KeyNotFoundException InvocationInfo : {New-AzRoleAssignment} Line : New-AzRoleAssignment -SignInName '[email protected]' -ResourceGroupName 'hca-mgt-vms' -RoleDefinitionName 'Owner' -Debug -Verbose Position : At line:1 char:1 + New-AzRoleAssignment -SignInName '[email protected]' -ResourceGr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 4
HistoryId: 1
Message : AADSTS700016: Application with identifier '3512c988-55e1-4f46-a1e6-6949e0b55a16' was not found in the directory '335a6d75-c3eb-4b1a-ac08-d49338816ca0'. This can happen if the
application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
Trace ID: daaec92a-2303-4942-b75b-35c1506faf00
Correlation ID: 420d1ee5-6a41-48ff-9196-0785723f5ef9
Timestamp: 2019-05-08 16:38:17Z
StackTrace : at Microsoft.IdentityModel.Clients.ActiveDirectory.AdalHttpClient.1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AdalHttpClient.<GetResponseAsync>d__201.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.1 promptAction, String userId,
SecureString password, String credentialType)
at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account, IAzureEnvironment environment, String tenant, SecureString
password, String promptBehavior, Action1 promptAction, IAzureTokenCache tokenCache, String resourceId)
at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, String tenantId, SecureString password,
String promptBehavior, Action1 promptAction)
at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantId, String subscriptionId, String
subscriptionName, SecureString password, Boolean skipValidation, Action1 promptAction, String name, Boolean shouldPopulateContextList)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass92_0.2 contextAction)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action3 setContextAction)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException
InvocationInfo : {Connect-AzAccount}
Line : Add-AzAccount -Credential (New-Object System.Management.Automation.PSCredential ("3512c988-55e1-4f46-a1e6-6949e0b55a16", (ConvertTo-SecureString
"74199632C523E6EC8863F0E0866A20D5AB996C475F6D936D3E9A8AEM3F0FCE6B" -AsPlainText -Force))) `
Position : At line:1 char:1 + Add-AzAccount -Credential (New-Object System.Management.Automation.PS ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 1
Message : Response status code does not indicate success: 400 (BadRequest).
StackTrace : at Microsoft.IdentityModel.Clients.ActiveDirectory.HttpClientWrapper.
Position : At line:1 char:1 + Add-AzAccount -Credential (New-Object System.Management.Automation.PS ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 1
Message : {"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier '3512c988-55e1-4f46-a1e6-6949e0b55a16' was not found in the directory '335a6d75-c3eb-4b1a-ac08-d49338816ca0'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.\r\nTrace ID: daaec92a-2303-4942-b75b-35c1506faf00\r\nCorrelation ID: 420d1ee5-6a41-48ff-9196-0785723f5ef9\r\nTimestamp: 2019-05-08 16:38:17Z","error_codes":[700016],"timestamp":"2019-05-08 16:38:17Z","trace_id":"daaec92a-2303-4942-b75b-35c1506faf00","correlation_id":"420d1ee5-6a41-48ff-9196-0785723f5ef9","error_uri":"https://login.microsoftonline.com/error?code=700016"} StackTrace : Exception : System.Exception InvocationInfo : {Connect-AzAccount} Line : Add-AzAccount -Credential (New-Object System.Management.Automation.PSCredential ("3512c988-55e1-4f46-a1e6-6949e0b55a16", (ConvertTo-SecureString "74199632C523E6EC8863F0E0866A20D5AB996C475F6D936D3E9A8AEM3F0FCE6B" -AsPlainText -Force))) `
Position : At line:1 char:1 + Add-AzAccount -Credential (New-Object System.Management.Automation.PS ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 1
DEBUG: AzureQoSEvent: CommandName - Resolve-AzError; IsSuccess - True; Duration - 00:00:00.0901856; Exception - ; DEBUG: Finish sending metric. DEBUG: 12:10:13 PM - ResolveError end processing. DEBUG: 12:10:13 PM - ResolveError end processing.
@1scscott Normally this occurs because your service principal does not have sufficient privileges within your tenant to find the object id for the user principal name provided in your role assignment.
To enable this, you need to give the service principal sufficient permissionsto list and read directory entires in your tenant, see: https://docs.microsoft.com/en-us/azure/active-directory/reports-monitoring/howto-configure-prerequisites-for-reporting-api#grant-permissions (just for the windows azure active directory part).
Makes sense let me get with the AAD guys at work. Thanks for getting back to me.
On Fri, May 10, 2019, 2:30 PM Mark Cowlishaw [email protected] wrote:
@1scscott https://github.com/1scscott Normally this occurs because your service principal does not have sufficient privileges within your tenant to find the object id for the user principal name provided in your role assignment.
To enable this, you need to give the service principal sufficient permissionsto list and read directory entires in your tenant, see: https://docs.microsoft.com/en-us/azure/active-directory/reports-monitoring/howto-configure-prerequisites-for-reporting-api#grant-permissions (just for the windows azure active directory part).
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-powershell/issues/9156#issuecomment-491403964, or mute the thread https://github.com/notifications/unsubscribe-auth/AESO4IPEXDQWC2QZOQC6W63PUXELTANCNFSM4HLTSWIA .
Closing. Please let us know if you see any similar problems in the future.