繁体   English   中英

检索 Synapse 服务主体的应用程序 ID,并使用 Bicep 作为管理员添加到 AAS

[英]Retrieve app id of Synapse service principal and add as administrator to AAS using Bicep

我正在使用 Bicep 部署 Azure 服务。 属性“分配的身份类型系统”创建具有名称、对象 ID 和应用 ID 的企业应用程序/服务主体。 这是能够从 Synapse 管道处理 Azure 分析服务所必需的。

//Create Synapse Analytics
resource synapseAnalytics 'Microsoft.Synapse/workspaces@2021-06-01' = {
  name: synapse_name
  location: region
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    defaultDataLakeStorage: {
      filesystem: storage_account_fileshare_name
      resourceId: storageAccount.id
      accountUrl: storage_account_url
      createManagedPrivateEndpoint: true
    }
    managedVirtualNetwork: 'default'
    publicNetworkAccess: 'Enabled'
    managedResourceGroupName: synapse_workspace_name
    azureADOnlyAuthentication: false
    cspWorkspaceAdminProperties: {
      initialWorkspaceAdminObjectId: xxxx
    }
  }
  dependsOn: [
    storageAccountFileshare
  ]
}

我需要检索已创建资源的应用 ID,以以管理员身份添加到 Azure 分析服务。

resource analysisServices 'Microsoft.AnalysisServices/servers@2017-08-01' = {
  name: anaylsis_services_name
  location: region
  sku: {
    name: 'B1'
    tier: 'Basic'
    capacity: 1
  }
  properties: {
    asAdministrators: {
      members: [
        'obj:xxxxxx-xxxxxx-xxxxx-xxxxx@xxxxx-xxx-xxxxx-xxxxx'
        'app:{GET APP ID OF SYNAPSE}' <------------------
      ]
    }
    managedMode: 1
  }
}

如何在我的 Bicep 代码中访问应用程序 ID?

我可以使用 powershell 命令检索应用程序 ID。 不幸的是,此命令需要一个我无法使用 powershell 命令检索的对象 ID。

az ad sp show --id {object-id} --query appId

使用系统分配的身份,您无法直接从二头肌获取 appId。 但是你可以输出principalId

//Create Synapse Analytics
resource synapseAnalytics 'Microsoft.Synapse/workspaces@2021-06-01' = {
  name: synapse_name
  ...
}

// return the principalId to query the appId
output principalId string = synapseAnalytics.identity.principalId

然后您可以使用 principalId 来获取 appId

az ad sp show --id <principalId from bicep> --query appId

使用用户分配的身份,您将能够在二头肌中完成所有操作:

// Create a user identity for synapse
resource userAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
  name: userAssignedIdentityName
  location: region
}

//Create Synapse Analytics
resource synapseAnalytics 'Microsoft.Synapse/workspaces@2021-06-01' = {
  name: synapse_name
  identity: {
    type: 'SystemAssigned,UserAssigned'
    userAssignedIdentities: {
      // assign the managed identity
      '${userAssignedIdentity.id}': {}
    }
  }
  ...
}

// Create the analysis service
resource analysisServices 'Microsoft.AnalysisServices/servers@2017-08-01' = {
  name: anaylsis_services_name
  ...
  properties: {
    asAdministrators: {
      members: [
        ...
        // Set app id and tenantid as per documentation
        'app:${userAssignedIdentity.properties.clientId}@${userAssignedIdentity.properties.tenantId}' 
      ]
    }
    ...
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM