1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

BicepでマネージドIDに「Cosmos DB組み込みデータ共同作成者」ロールを付与する

Posted at

マネージドIDにCosmosDBへのアクセス権限を付与する方法です。
CosmosDBの管理プレーンへのアクセス権限はAzureポータルからRBACで付与できますが、データプレーンへのアクセス権限はCLIやPowerShellを利用する必要があります。
マネージド ID を使用して Azure 仮想マシンから Azure Cosmos DB に接続する方法

今回はBicepで付与する方法を残します。

  • 例としてAzure Container AppsのマネージドIDに付与します
  • まずは以下のようにACAのシステムマネージドIDを有効にします
ACAのマネージドID設定(一部抜粋)
resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
  name: appName
  location: location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    managedEnvironmentId: environment.id
    configuration: {
      ingress: {
        targetPort: 80
        external: true
        ipSecurityRestrictions: [ for list in ipAllowList : {
          name: list.name
          action: list.action
          ipAddressRange: list.ipAddressRange
        }]
      }
    }
    template: {
      containers: [
        {
          image: 'nginx:latest'
          name: 'sample-apps'
          resources: {
            cpu: json('${cappDedicatedCpu}')
            memory: '${cappDedicatedMemory}Gi'
          }
        }
      ]
      scale: {
        minReplicas: 1
      }
    }
    workloadProfileName: 'Consumption'
  }
}

output acaPrincipalId string = containerApp.identity.principalId
  • ACAのマネージドIDプリンシパルIDに「Cosmos DB 組み込みデータ共同作成者」ロールを付与します
resource cosmosdbRoleDefinition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2023-04-15' existing = {
  parent: cosmosDb
  name: '00000000-0000-0000-0000-000000000002'
}

resource roleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2023-04-15' = {
  parent: cosmosDb
  name: guid(cosmosDb.id, acaPrincipalId, cosmosdbRoleDefinition.id)
  properties: {
    roleDefinitionId: cosmosdbRoleDefinition.id
    principalId: acaPrincipalId
    scope: cosmosDb.id
  }
}

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?