我可以使用 Azure 或使用 az
cli 从门户控制台创建服务主体。
az ad sp create-for-rbac --name "myspuser" --password "adfhrrreeuwrgwejdfgds"
然后,我在订阅级别分配所有者角色并在 powershell 控制台中登录。
Login-AzureRmAccount -Credential (New-Object System.Management.Automation.PSCredential ('a92b2ea2-aaaa-0000-0a0a-1238ec953226', $(ConvertTo-SecureString 'abcewior23h23ius' -AsPlainText -Force))) -ServicePrincipal -TenantId 0cedca99-00f4-40d1-aa41-80d67ece2de8;
在这里我几乎可以做任何事情,比如部署机器,除了检查其他用户之外。
当我执行时
Get-AzureRmADServicePrincipal
我得到的只是Get-AzureRmADServicePrincipal:没有足够的权限来完成操作。
这适用于我的标准用户登录。
我的目标是创建一个自动化系统,用户可以在其 MSDN 订阅中使用 jenkins 通过 ARM 模板部署完整的环境。由于 powershell 不支持某些登录,我想让我的用户为此使用服务主体。我的自动化需要创建一个 SP,该 SP 将使用需要读取资源组计算机属性的 jenkins 从 Linux 计算机上使用。
我在这里缺少什么?如何分配服务主体用户权限来管理其他服务主体帐户?
最佳答案
看来你需要使用Add-AzureADDirectoryRoleMember
将目录角色分配给您的服务主体。
您可以选择您需要的具体目录角色,引用此link .
注意:您需要install azure ad powershell module首先。
在这种情况下,您可以尝试将应用程序管理员
角色分配给您的服务主体。 (如有必要,您可以分配公司管理员
角色。)
示例:
# Fetch role instance
$role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'Application Administrator'}
# If role instance does not exist, instantiate it based on the role template
if ($role -eq $null) {
# Instantiate an instance of the role template
$roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object {$_.displayName -eq 'Application Administrator'}
Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId
# Fetch role
$role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'Application Administrator'}
}
# Add the SP to role
Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId <your SP ObjectID>
这里有一个类似的问题供大家引用,看这个link .
关于Azure 服务主体没有足够的权限来管理其他服务主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52285608/