具有托管身份的 Azure SQL - Bicep

标签 azure azure-sql-database azure-resource-manager azure-managed-identity azure-bicep

我正在使用二头肌创建以下资源

  • 具有多个数据库的 SQL Server
  • 需要访问这些 Azure SQL 数据库的多个应用服务

我已创建一个用户分配的托管身份资源并分配给所有应用服务。

我想在 Sql Server 中添加管理员身份(门户 -> 选择 Sql Server 资源 -> 在设置下选择 Azure Active Directory -> 设置管理员),但我收到以下错误:

Invalid value given for parameter ExternalAdministraorLoginSid. Specify a valid parameter value.

这是 SQL Server 二头肌:

resource sqlserver 'Microsoft.Sql/servers@2021-11-01-preview' = {
  name: 'sqlserver${uniqueString(resourceGroup().id)}'
  location: location
  properties: {
    administratorLogin: sqlAdministratorLogin
    administratorLoginPassword: sqlAdministratorPassword
    version: '12.0'
    administrators: {
     administraorType: 'ActiveDirectory'
     principalType: 'Group'
     azureADOOnlyAuthentication: true
     login: 'userAssignedManagedIdName'
     sid: 'UserAssignedManagedID-Client-ID' // not actual value
     tenantId: 'UserAssignedManagedID-Tenant-ID ' // not actual value
   }
  }
}

我从“设置”下的托管身份属性选项卡中获取了这两个值。

最佳答案

您需要使用托管标识资源的 principalId(服务主体的 objectId)属性。此外,principalType 需要是 Application:

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2022-01-31-preview' = {
  name: '<userAssignedManagedIdName>'
  location: location
}

resource sqlserver 'Microsoft.Sql/servers@2021-11-01-preview' = {
  name: 'sqlserver${uniqueString(resourceGroup().id)}'
  location: location
  properties: {
    administratorLogin: sqlAdministratorLogin
    administratorLoginPassword: sqlAdministratorPassword
    version: '12.0'
    administrators: {
      administratorType: 'ActiveDirectory'
      azureADOnlyAuthentication: true
      principalType: 'Application'
      login: managedIdentity.name
      sid: managedIdentity.properties.principalId
      tenantId: managedIdentity.properties.tenantId
    }
  }
}

关于具有托管身份的 Azure SQL - Bicep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75868231/

相关文章:

c# - 该请求无权执行该操作。 Azure blob客户端

visual-studio - 如何启用 Azure MFA 来部署 Web 服务?

azure - Azure 中 ASP.MVC 的最佳计划是什么?

Azure 删除取消(已禁用)订阅

azure - 部署azure函数应用程序时出现ARM模板错误

azure - TF14045 : The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' could not be found

azure - 如何将第二行设置为标题? (Azure 数据工厂)

azure - ASP.NET Core Web API HTTP POST 在 Azure 中返回 404

apache-spark - 截断数据 block 上的表

azure - 在 Azure 中聚合多个数据库