0

我正在尝试向我的权限帐户添加一个集合,为此我需要我的服务原则在我的权限帐户中具有“数据源管理员”角色。我已经使用这个 Powershell 脚本部署了我的权限帐户:

function deployPurviewAccount([string]$resourceGroup, [string]$location, [string]$purviewName){
New-AzResourceGroup -Name $resourceGroup -Location $location

New-AzPurviewAccount -Name $purviewName `
-ResourceGroupName $resourceGroup `
-Location $location `
-IdentityType SystemAssigned `
-SkuCapacity 1 `
-SkuName Standard `
}
$location = getLocation
$resourceGroup = getResourceGroupName
$purviewName = getPurviewAccountName
"Deploying Purview Account ${purviewName} in Resource Group ${resourceGroup}"
deployPurviewAccount $resourceGroup $location $purviewName

getLocation, getResourceGroupName,getPurviewAccountName是基本的输入函数,我只是在询问名称。例如,centralindia位置等。

部署成功,现在我想向我正在使用脚本的权限帐户添加一个新集合:

<#-CREATES A SERVICE PRINCIPAL-#>
function createSP([string]$subscriptionId, [string]$resourceGroup, [string]$spName) {
$scope = "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}"
$sp = New-AzADServicePrincipal -DisplayName "${spName}" -Role "Owner" -Scope $scope
return $sp
}
<#-Generates an Access Token#->
function genAccessTok([string]$tenantId, [string]$clientid, [string]$UnsecureSecret) {
$purres = "https://purview.azure.net"
$reqUrl = "https://login.microsoftonline.com/${tenantId}/oauth2/token"
$postmanBody = "grant_type=client_credentials&client_id=${clientId}&client_secret=${UnsecureSecret}&resource=${purres}"
$token = Invoke-RestMethod -Method Post -Uri $reqUrl -Body $postmanBody -ContentType 'application/x-www-form-urlencoded'
$tmpAcsToken = $token.access_token
return "Bearer " + ($tmpAcsToken).ToString()
}

function createSubCollection([string]$accessToken, [string]$endpoint, [string]$collectionName, [string]$parentCollectionName) {
$reqPath = "${endpoint}/account/collections/${purviewName}?api-version=2019-11-01-preview"
$postBody = @{
    "name" = $purviewName
    "parentCollection"= @{
        "type" = "CollectionReference"
        "referenceName" = $parentCollectionName
    }
    "friendlyName" = $collectionName
}
$parameter = @{
    ContentType = "application/json"
    Headers = @{"Authorization"=$accessToken}
    Body = {$postBody | ConvertTo-Json -Depth 10}
    Method = "PUT"
    URI = $reqPath
}

Invoke-RestMethod @parameter <#--- Throws error here ---#>
}

$tenantId = (Get-AzContext).Tenant.Id
$subscriptionId = (Get-AzContext).Subscription.Id
$resourceGroup = getResourceGroupName
$purviewName = getPurviewAccountName

$endpoint = "https://${purviewName}.purview.azure.com"
$spName = getServicePrincipleName

$collectionName = getColName
$parentCollectionName = getParentCol
$sp = createSP $subscriptionid $resourceGroup $spName
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sp.Secret)
$UnsecureSecret = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$clientid = $sp.ApplicationId

$accessToken = genAccessTok $tenantId $clientid $UnsecureSecret


"Adding Collection to the purview account"

createSubCollection $accessToken $atlas_endpoint $collectionName $parentCollectionName

现在要将集合添加到我的权限帐户,我需要在权限帐户中提供在上述脚本“数据源管理员”角色中创建的服务主体。如何通过我的 Powershell 脚本做到这一点?如果我在不提供角色的情况下运行上述脚本,则会引发以下错误。 在此处输入图像描述

4

1 回答 1

0

截至目前,您只能添加向根集合管理员添加权限可用。可以使用 Azure CLI (az purview account add-root-collection-admin) 和 PowerShell (Add-AzPurviewAccountRootCollectionAdmin)

有权访问权限帐户后,您可以根据 Azure Purview Studio 的要求添加权限,例如(集合管理员、数据源管理员、数据管理员、数据读者)。

注意:用于添加权限的 PowerShell/cli 命令(例如(集合管理员、数据源管理员、数据管理员、数据阅读器)即将推出

有关更多详细信息,请参阅Azure Purview 中的访问控制,您可以查看我之前的回答“ azure purview access permission ”,其中介绍了如何授予对 Azure Purview 帐户的访问权限。

于 2021-11-26T04:25:15.433 回答