Azure AD 应用程序注册秘密操作

Azure AD App Registration secret manipulation

我正在使用定义了机密的应用程序注册。通过 PowerShell,我能够获得凭据,但无法获得秘密值。使用的函数是 Get-AzADAppCredential 这是预期的行为,这里没有问题。

为了更新秘密,我 运行 两个函数 Remove-AzADAppCredentialNew-AzADAppCredential

我 运行 通过 DevOps 管道使用这些 PowerShell cmdlet,并在 Azure 门户中使用具有权限的服务连接。

我注意到,当我们创建从 DevOps 到 Azure 的服务连接时,服务主体会自动分配 云应用程序管理员 角色。 此角色包含权限“microsoft.directory/applications/credentials/update”。

所以上面的 (remove + new) 应该有效,但它不... DevOps returns 一个错误:

Az.MSGraph.internal\Remove-AzADApplicationPassword : Insufficient privileges to complete the operation.

Az.MSGraph.internal\Add-AzADApplicationPassword : Insufficient privileges to complete the operation.

PS。使用 PowerShell 函数时使用 Az.Resources 版本 5.4.0。

有人知道我错过了什么吗?

谢谢。

Insufficient privileges to complete the operation.

当用户在 AAD 中没有足够的权限并且没有对所选 Azure 订阅的写入权限时出现错误。

Note: If you have Cloud application administrator privileges of the user, this role grants the ability to manage application credentials. Users assigned this role can add credentials to an application and use those credentials to impersonate the application’s identity. If the application’s identity has been granted access to a resource, such as the ability to create or update User or other objects, then a user assigned to this role could perform those actions while impersonating the application.

确保检查一次您是否具有全局管理员访问权限。如果您有权限,您可以修改密码。

分配到全局管理员角色的用户可以读取和修改 Azure AD 组织中的每个管理设置。

权限问题可能是由于

  1. 用户在目录中只有来宾权限
  2. 用户无权在目录中添加应用程序

参考here获取详细信息

为了能够通过 DevOps 使用服务主体以最小权限更新应用注册的秘密,首先让服务连接成为该随机应用注册的所有者。

Next, add the Application.ReadWrite.OwnedBy application API permission on the app registration that's linked to the enterprise application. Not on the app registration where the service principal was made owner.

比更新密文更有效。

这仍然是一个问题,但为什么 云应用程序管理员 角色不够,因为 microsoft.directory/applications/credentials/update 包括在内在那个角色中,这也应该足够了。