【问题标题】:New-AzRoleAssignment : Cannot validate argument on parameter 'ObjectId'New-AzRoleAssignment:无法验证参数“ObjectId”上的参数
【发布时间】:2019-12-03 08:39:05
【问题描述】:

下面是前面的代码,它与 AzureRm 一起工作

$registry = Get-AzureRmContainerRegistry -ResourceGroupName $resourceGroupName -Name $acrName
# Get the existing service principal; need its 'ObjectId' value
# when assigning the role to the principal in a subsequent command.
$sp = Get-AzureRmADServicePrincipal -ServicePrincipalName $appId
$role = New-AzureRmRoleAssignment -ObjectId $sp.Id -RoleDefinitionName $role -Scope $registry.Id    

现在使用最新的 Azure 模块 Az 无法正常工作。

$registry = Get-AzContainerRegistry -ResourceGroupName "somenamee" -Name "acrcontainername"
$sp = Get-AzADServicePrincipal -ServicePrincipalName "............."
$role = New-AzRoleAssignment -ObjectId $sp.Id -RoleDefinitionName 'acrpull' -Scope $registry.Id  

错误:

New-AzRoleAssignment : Cannot validate argument on parameter 'ObjectId'. The     argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:1 char:40
+ $role = New-AzRoleAssignment -ObjectId $sp.Id -RoleDefinitionName $ro ...
+                                        ~~~~~~
+ CategoryInfo          : InvalidData: (:) [New-AzRoleAssignment],     ParameterBindingValidationException
    + FullyQualifiedErrorId :         ParameterArgumentValidationError,Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand

【问题讨论】:

  • 当我尝试下面的代码时,“$sp = Get-AzADServicePrincipal -ApplicationId 9719c54e-15ca-4911-a6fb-......”我得到以下错误 PS C: \windows\system32> $sp = Get-AzADServicePrincipal -ApplicationId 9719c54e-15ca-4911-a6fb-a23653284ed1 Get-AzADServicePrincipal :权限不足,无法完成操作。在 line:1 char:7 + $sp = Get-AzADServicePrincipal -ApplicationId 9719c54e-15ca-4911-a6fb ... + ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Get -AzADServicePrincipal],异常+FullyQual
  • 我有服务主体“acr............”那个 appid 和密钥,现在想将 azure 容器注册表的“AcrImageSigner”角色分配给这个服务主体“ acr...........”我该怎么做。
  • 您是否在同一个服务主体上使用AzureRmAz 命令?
  • AzureRm 我使用了用户名和密码,对于 Az,我使用的是服务主体
  • 如何使用应用名称将角色分配给容器注册表。我可以在 Azure 门户中执行此操作。但我需要 Powershell 的帮助才能做到这一点

标签: azure azure-active-directory azure-container-registry


【解决方案1】:

AzureRm 我使用了用户名和密码,Az 我使用的是服务主体

如果将 Azure powershell 与服务主体一起使用,则需要向服务主体授予权限。

有两个选项(您需要在您的 AAD 租户中以 Global administrator 身份登录 azure 门户,我建议您使用选项 2):

1.导航到Azure Active Directory -> Roles and administrators -> 点击Global administrator -> Add assignments -> 添加您的服务主体。

2.导航到Azure Active Directory -> App registrations -> 找到您的服务主体的AD App并添加Azure Active Directory GraphApplication.ReadWrite.All权限,如下所示。


在 AAD 中授予权限后,Get-AzADServicePrincipal -ApplicationId xxxxx 命令将起作用。要使用New-AzRoleAssignment,您的服务主体应该是订阅或ContainerRegistry 中的Owner。如果您不给Owner 角色,它将无法分配角色分配。

Owner 的身份导航到门户中的订阅或ContainerRegistry -> Access control (IAM) -> Add-> Add role assignment -> 将您的服务主体添加为Owner,详细信息here

【讨论】:

    【解决方案2】:

    1.导航到 Azure Active Directory -> 角色和管理员 -> 单击全局管理员 -> 添加分配 -> 添加您的服务主体。

    您不能将服务主体添加到全局管理员。

    2.导航到 Azure Active Directory -> 应用注册 -> 找到您的服务主体的 AD 应用并添加 Azure Active Directory Graph 的 Application.ReadWrite.All 权限 如下所示。

    我尝试添加以下权限:

    Azure 活动目录图

    • Application.ReadWrite.All
    • Directory.ReadWrite.All

    微软图形

    • Application.ReadWrite.All
    • Directory.ReadWrite.All

    Az 模块 4.7 在 Powershell 7 下仍然存在 Get-AzADServicePrincipal 错误。

    【讨论】:

      猜你喜欢
      • 2023-02-23
      • 2019-06-01
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 2019-08-26
      • 1970-01-01
      相关资源
      最近更新 更多