gpt4 book ai didi

azure - 如何使用自动化帐户 PowerShell Runbook 重置 Azure 服务主体的凭据?

转载 作者:行者123 更新时间:2023-12-03 03:51:56 25 4
gpt4 key购买 nike

我正在尝试通过以下 PowerShell 命令重置服务主体(我们称之为 SP1)的密码凭据:

Remove-AzADSpCredential -ObjectId  <SP1_objectId> -Force
$Password = New-AzADSpCredential -ObjectId <SP1_objectId>

当我通过自己的用户帐户(该帐户已分配给 SP1 的所有者角色)通过 PowerShell 运行它时,效果很好。

我还在具有“运行帐户”服务主体(我们称之为 SP2)的自动化帐户的 Runbook 中包含此代码。

我还通过命令 Add-AzureADServicePrincipalOwner 将 SP1 的所有权分配给 SP2,并通过 Get-AzureADServicePrincipalOwner 确认。

我希望 Runbook 在将其服务主体设为 SP1 的所有者后能够在 SP1 上运行 Remove-AzADSpCredential 命令。但我收到以下错误:

Remove-AzADSpCredential : Insufficient privileges to complete the operation. At line:43 char:9 + Remove-AzADSpCredential -ObjectId $key.Name -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Remove-AzADSpCredential], Exception + FullyQualifiedErrorId : Microsoft.Azure.Commands.ActiveDirectory.RemoveAzureADSpCredentialCommand

New-AzADSpCredential 命令也出现同样的错误。

我认为也许 SP1 的所有权应该分配给运行帐户的应用程序,而不是其服务主体。
所以我还运行了以下命令:

Add-AzureADServicePrincipalOwner -ObjectId <SP1_ObjectId> -RefObjectId <runasaccount_app_ObjectId>

但这不可能,因为我收到了错误:

Code: Request_BadRequestMessage: The reference target 'Application_xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx' of type 'Application' is invalid for the 'owners' reference.

所以我认为所有权应该只分配给 SP2,而不是应用程序。

我查看了here但接受的答案说

If your user accounts are the Owner of the service principal(Enterprise application), the command New-AzADSpCredential will work.

这对我来说是正确的,但是在运行 Runbook 时它不起作用。

我还查看了here看来我需要做OP描述的很容易做的#1。

任何有关如何执行此操作的意见将不胜感激。

最佳答案

如果您想使用一个服务主体添加/删除另一个服务主体的凭据,这与使用用户帐户执行此操作不同。

I assigned the ownership of SP1 to SP2 as well through the command Add-AzureADServicePrincipalOwner and confirmed it through Get-AzureADServicePrincipalOwner.

这种方式是正确的,但不仅仅是Owner ,您还需要给出 Application.ReadWrite.OwnedBy Azure Active Directory Graph 中的应用程序权限 (不是 Microsoft Graph )之后的 API。

导航至API permissions您的自动化帐户对应门户中的AD应用程序 ->添加如下所示的权限,不要忘记单击Grant admin consent for xxx最后按钮。

enter image description here

enter image description here

enter image description here

然后在runbook中测试一下,效果很好。

New-AzADSpCredential -ObjectId xxxxxxxxxxxxx

enter image description here

Owner的组合和Application.ReadWrite.OwnedBy本例中是最低权限,还有其他方式,也可以给Application Administrator如您所见的目录角色 hereApplication.ReadWrite.All Azure Active Directory Graph 中的应用程序权限 ,两者都可以。

关于azure - 如何使用自动化帐户 PowerShell Runbook 重置 Azure 服务主体的凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66324109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com