我可以使用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 : Insufficient privileges to complete the operation.
这适用于我的标准用户登录。
我的目标是创建一个自动化,用户可以在MSDN订阅中使用jenkins通过ARM模板部署完整的环境。由于PowerShell不支持某些登录,我想让我的用户使用服务主体。我的自动化需要创建一个SP,它将使用需要读取资源组机器属性的jenkins从linux机器上使用。
我在这里缺少什么?如何分配服务主体用户权限来管理其他服务主体帐户?
您似乎需要使用Add-AzureADDirectoryRoleMember
将目录角色分配给您的服务主体。
您可以选择所需的特定目录角色,请参阅此link。
注意:你需要先install azure ad powershell module。
在这种情况下,您可以尝试将Application Administrator
角色分配给您的服务主体。 (如有必要,您可以指定Company Administrator
角色。)
样品:
# 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。