다음을 통해 공유


역할 기반 액세스 제어 및 Microsoft Entra ID를 사용하여 NoSQL용 Azure Cosmos DB에 연결

역할 기반 액세스 제어는 Azure에서 리소스에 대한 액세스를 관리하는 방법을 나타냅니다. 이 메서드는 하나 이상의 리소스에 대한 액세스 수준을 관리하는 역할이 할당되는 특정 ID를 기반으로 합니다. 역할 기반 액세스 제어는 ID가 작업을 수행하는 데 필요한 최소 권한 수준의 액세스만 갖도록 하는 세분화된 액세스 관리의 유연한 시스템을 제공합니다.

자세한 내용은 역할 기반 액세스 제어를 참조하세요.

필수 조건

  • 활성 구독이 있는 Azure 계정. 무료로 계정을 만듭니다.

  • 기존 Azure Cosmos DB for NoSQL 계정

  • Microsoft Entra ID에 하나 이상의 기존 ID가 있습니다.

키 기반 인증 사용 안 함

키 기반 권한 부여를 사용하지 않도록 설정하면 보다 안전한 Microsoft Entra ID 인증 방법 없이 계정을 사용할 수 없습니다. 이 절차는 보안 워크로드의 새 계정에서 수행해야 하는 단계입니다. 또는 보안 워크로드 패턴으로 마이그레이션되는 기존 계정에서 이 절차를 수행합니다.

먼저 애플리케이션에서 Microsoft Entra ID 인증을 사용하도록 기존 계정에 대한 키 기반 인증을 사용하지 않도록 설정합니다. az resource update를 사용하여 기존 계정의 properties.disableLocalAuth을(를) 수정합니다.

az resource update \
    --resource-group "<name-of-existing-resource-group>" \
    --name "<name-of-existing-account>" \
    --resource-type "Microsoft.DocumentDB/databaseAccounts" \
    --set properties.disableLocalAuth=true

먼저 애플리케이션에서 Microsoft Entra 인증을 사용해야 하므로 키 기반 인증이 비활성화된 새 계정을 만듭니다.

  1. 키 기반 인증을 사용하지 않도록 설정하여 새 계정을 배포하는 새 Bicep 파일을 만듭니다. deploy-new-account.bicep 파일의 이름을 지정합니다.

    metadata description = 'Deploys a new Azure Cosmos DB account with key-based auth disabled.'
    
    @description('Name of the Azure Cosmos DB account.')
    param name string = 'csms-${uniqueString(resourceGroup().id)}'
    
    @description('Primary location for the Azure Cosmos DB account.')
    param location string = resourceGroup().location
    
    resource account 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' = {
      name: name
      location: location
      kind: 'GlobalDocumentDB'
      properties: {
        databaseAccountOfferType: 'Standard'
        locations: [
          {
            locationName: location
          }
        ]
        disableLocalAuth: true
      }
    }
    
  2. 새 계정으로 Bicep 파일을 배포하려면 az deployment group create을 사용하세요.

    az deployment group create \
        --resource-group "<name-of-existing-resource-group>" \
        --template-file deploy-new-account.bicep
    

먼저 애플리케이션에서 Microsoft Entra 인증을 사용해야 하므로 기존 계정에 대한 키 기반 인증을 사용하지 않도록 설정합니다. Get-AzResource을(를) 사용하여 기존 계정을 읽고, Set-AzResource을(를) 사용하여 업데이트합니다.

$parameters = @{
    ResourceGroupName = "<name-of-existing-resource-group>"
    ResourceName = "<name-of-existing-account>"
    ResourceType = "Microsoft.DocumentDB/databaseAccounts"
}
$resource = Get-AzResource @parameters

$resource.Properties.DisableLocalAuth = $true

$resource | Set-AzResource -Force

애플리케이션이 Microsoft Entra 인증만 사용해야 하므로 키 기반 인증이 비활성화된 새 Azure Cosmos DB for NoSQL 계정을 만들려면 다음 단계를 사용합니다.

  1. NoSQL용 새 Azure Cosmos DB 계정을 설정할 때 계정 만들기 프로세스의 보안 섹션으로 이동합니다.

  2. 그런 다음 키 기반 인증 옵션에 대해 사용 안 함을 선택합니다.

    Azure Portal에서 새 계정을 만들 때 키 기반 인증을 사용하지 않도록 설정하는 옵션의 스크린샷

중요합니다

Azure Cosmos DB 계정을 수정하려면 최소한 Microsoft.DocumentDb/databaseAccounts/*/write 권한이 있는 Azure 역할이 필요합니다. 자세한 내용은 Azure Cosmos DB에 대한 권한을 참조하세요.

키 기반 인증이 비활성화되어 있는지 확인합니다.

키 기반 액세스가 비활성화되어 있는지 확인하려면 Azure SDK를 사용하여 리소스 소유자 암호 자격 증명(ROPC)을 사용하여 Azure Cosmos DB for NoSQL에 연결하려고 합니다. 이 시도는 실패해야 합니다. 필요한 경우 일반적인 프로그래밍 언어에 대한 코드 샘플이 여기에 제공됩니다.

using Microsoft.Azure.Cosmos;

string connectionString = "AccountEndpoint=<nosql-endpoint>;AccountKey=<key>;";

CosmosClient client = new(connectionString);
const { CosmosClient } = require('@azure/cosmos');

const connectionString = 'AccountEndpoint=<nosql-endpoint>;AccountKey=<key>;';

const client = new CosmosClient(connectionString);
import { CosmosClient } from '@azure/cosmos'

let connectionString: string = 'AccountEndpoint=<nosql-endpoint>;AccountKey=<key>;';

const client: CosmosClient = new CosmosClient(connectionString);
from azure.cosmos import CosmosClient

connection_string = "AccountEndpoint=<nosql-endpoint>;AccountKey=<key>;"

client = CosmosClient(connection_string)
package main

import (
    "github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos"
)

const connectionString = "AccountEndpoint=<nosql-endpoint>;AccountKey=<key>;"

func main() {
    client, _ := azcosmos.NewClientFromConnectionString(connectionString, nil)
}
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;

public class NoSQL{
    public static void main(String[] args){
        CosmosClient client = new CosmosClientBuilder()
            .endpoint("<nosql-endpoint>")
            .key("<key>")
            .buildClient();
    }
}
use azure_data_cosmos::CosmosClient;

fn main() {
    let client = CosmosClient::new_with_access_key(
        "<account-endpoint>",
        "<account-key>",
        None,
    ).unwrap();

    let container = client.database_client("<database-name>").container_client("<container-name>");

    let response = container.read_item("<partition-key>", "<item-id>", None);
    tokio::runtime::Runtime::new().unwrap().block_on(response).unwrap();
}

컨트롤 플레인 역할 기반 액세스 권한 부여

컨트롤 플레인 액세스는 데이터를 관리하지 않고 Azure 서비스에 대한 리소스를 관리하는 기능을 나타냅니다. 예를 들어 Azure Cosmos DB 컨트롤 플레인 액세스에는 다음 기능이 포함될 수 있습니다.

  • 모든 계정 및 리소스 메타데이터 읽기
  • 계정 키 및 연결 문자열 읽기 및 다시 생성
  • 계정 백업 및 복원 수행
  • 데이터 전송 작업 시작 및 추적
  • 데이터베이스 및 컨테이너 관리
  • 계정 속성 수정

중요합니다

Azure Cosmos DB에서 네이티브 데이터 평면 역할 기반 액세스 제어 정의 및 할당을 관리하려면 컨트롤 플레인 액세스가 필요합니다. Azure Cosmos DB의 데이터 평면 역할 기반 액세스 제어 메커니즘은 기본이므로 정의 및 할당을 만들고 Azure Cosmos DB 계정 내에 리소스로 저장하려면 컨트롤 플레인 액세스가 필요합니다.

먼저 Azure Cosmos DB에서 actions 계정 리소스를 관리하기 위한 액세스 권한을 부여할 목록을 사용하여 역할 정의를 준비해야 합니다. 이 가이드에서는 기본 제공 역할과 사용자 지정 역할을 준비하는 방법을 설명합니다. 그런 다음 애플리케이션이 Azure Cosmos DB의 리소스에 액세스할 수 있도록 ID에 새로 정의된 역할을 할당합니다.

  1. 를 사용하여 az role definition listAzure Cosmos DB 계정과 연결된 모든 역할 정의를 나열합니다.

    az role definition list \
        --name "Cosmos DB Operator"
    
  2. 출력을 검토하고 Cosmos DB 연산자라는 역할 정의를 찾습니다. 출력에는 속성에 있는 역할 정의 id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    [
      {
        "assignableScopes": [
          "/"
        ],
        "description": "Lets you manage Azure Cosmos DB accounts, but not access data in them. Prevents access to account keys and connection strings.",
        "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/providers/Microsoft.Authorization/roleDefinitions/230815da-be43-4aae-9cb4-875f7bd000aa",
        "name": "230815da-be43-4aae-9cb4-875f7bd000aa",
        "permissions": [
          {
            "actions": [
              "Microsoft.DocumentDb/databaseAccounts/*",
              "Microsoft.Insights/alertRules/*",
              "Microsoft.Authorization/*/read",
              "Microsoft.ResourceHealth/availabilityStatuses/read",
              "Microsoft.Resources/deployments/*",
              "Microsoft.Resources/subscriptions/resourceGroups/read",
              "Microsoft.Support/*",
              "Microsoft.Network/virtualNetworks/subnets/joinViaServiceEndpoint/action"
            ],
            "condition": null,
            "conditionVersion": null,
            "dataActions": [],
            "notActions": [
              "Microsoft.DocumentDB/databaseAccounts/dataTransferJobs/*",
              "Microsoft.DocumentDB/databaseAccounts/readonlyKeys/*",
              "Microsoft.DocumentDB/databaseAccounts/regenerateKey/*",
              "Microsoft.DocumentDB/databaseAccounts/listKeys/*",
              "Microsoft.DocumentDB/databaseAccounts/listConnectionStrings/*",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/write",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/delete",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments/write",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments/delete",
              "Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/write",
              "Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/delete",
              "Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/write",
              "Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/delete"
            ],
            "notDataActions": []
          }
        ],
        "roleName": "Cosmos DB Operator",
        "roleType": "BuiltInRole",
        "type": "Microsoft.Authorization/roleDefinitions",
      }
    ]
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/providers/Microsoft.Authorization/roleDefinitions/230815da-be43-4aae-9cb4-875f7bd000aa. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 그러나 식별자(230815da-be43-4aae-9cb4-875f7bd000aa)는 Azure의 모든 역할 정의에서 전역적으로 고유합니다.

  3. 현재 리소스 그룹에 대한 메타데이터를 가져오는 데 사용합니다 az group show .

    az group show \
        --name "<name-of-existing-resource-group>"
    
  4. 이전 명령의 출력을 관찰합니다. 다음 단계에서 사용하는 데 필요하기 때문에 이 리소스 그룹의 속성 값을 id 기록합니다.

    {
      "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example",
      "location": "westus",
      "name": "msdocs-identity-example",
      "type": "Microsoft.Resources/resourceGroups"
    }
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 이 문자열은 출력의 잘린 예입니다.

  5. role-definition.json새 JSON 파일을 만듭니다. 파일에서 여기에 나열된 값을 지정하는 이 리소스 정의를 만듭니다. 목록AssignableScopes에 이전 단계에서 기록된 리소스 그룹의 id 속성을 추가합니다.

    {
      "Name": "Azure Cosmos DB Control Plane Owner",
      "IsCustom": true,
      "Description": "Can perform all control plane actions for an Azure Cosmos DB account.",
      "Actions": [
        "Microsoft.DocumentDb/*"
      ],
      "AssignableScopes": [
        "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example"
      ]
    }
    

    비고

    이 예제에서는 이전 단계에서 기록한 값을 사용합니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example . 실제 리소스 식별자는 다를 수 있습니다.

  6. 를 사용하여 새 역할 정의를 만듭니다 az role definition create. role-definition.json 파일을 인수의 입력 --role-definition 으로 사용합니다.

    az role definition create \
        --role-definition role-definition.json
    
  7. 정의 만들기 명령의 출력을 검토합니다. 출력에는 속성에 있는 역할 정의 id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    {
      "assignableScopes": [
        "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example"
      ],
      "description": "Can perform all control plane actions for an Azure Cosmos DB account.",
      "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
      "name": "e4e4e4e4-ffff-aaaa-bbbb-c5c5c5c5c5c5",
      "permissions": [
        {
          "actions": [
            "Microsoft.DocumentDb/*"
          ]
        }
      ],
      "roleName": "Azure Cosmos DB Control Plane Owner",
      "roleType": "CustomRole"
    }
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 이 예제는 명확성을 위해 배포에서 출력된 일반적인 JSON의 하위 집합입니다.

  8. 현재 리소스 그룹에 대한 메타데이터를 다시 가져오는 데 사용합니다 az group show .

    az group show \
        --name "<name-of-existing-resource-group>"
    
  9. 이전 명령의 출력을 관찰합니다. 다음 단계에서 사용하는 데 필요하기 때문에 이 리소스 그룹의 속성 값을 id 기록합니다.

    {
      "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example",
      "location": "westus",
      "name": "msdocs-identity-example",
      "type": "Microsoft.Resources/resourceGroups"
    }
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 이 문자열은 출력의 잘린 예입니다.

  10. 를 사용하여 새 역할을 할당합니다 az role assignment create. 리소스 그룹의 식별자를 --scope 인수에, 역할의 식별자를 -role 인수에, 그리고 자신의 ID의 고유 식별자를 --assignee 인수에 사용하십시오.

    az role assignment create \
        --assignee "<your-principal-identifier>" \
        --role "subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1" \
        --scope "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example"
    

    비고

    이 예제 명령 scope 에서는 이전 단계의 예제에서 가상의 예제 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example 로 설정되었습니다. 리소스 그룹의 식별자는 이 예제와 구별됩니다. 또한 role은 가상의 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1로 설정되었습니다. 다시 말하지만 역할 식별자는 고유합니다.

  11. 명령의 출력을 관찰합니다. 출력에는 속성의 할당 id 에 대한 고유 식별자가 포함됩니다.

    {
      "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleAssignments/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
      "name": "ffffffff-5555-6666-7777-aaaaaaaaaaaa",
      "principalId": "aaaaaaaa-bbbb-cccc-1111-222222222222",
      "resourceGroup": "msdocs-identity-example",
      "roleDefinitionId": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
      "scope": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example",
      "type": "Microsoft.Authorization/roleAssignments"
    }
    

    비고

    이 예제에서 id 속성은 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleAssignments/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1, 또 다른 가상의 예입니다.

  12. 이 단계를 반복하여 사용하려는 다른 ID에서 계정에 대한 액세스 권한을 부여합니다.

    팁 (조언)

    원하는 만큼 ID에 대해 이러한 단계를 반복할 수 있습니다. 일반적으로 이러한 단계는 개발자가 사용자 ID를 사용하여 계정에 액세스할 수 있도록 허용하고 애플리케이션이 관리 ID를 사용하여 데이터에 액세스할 수 있도록 하기 위해 적어도 반복됩니다.

  1. 를 사용하여 az role definition listAzure Cosmos DB 계정과 연결된 모든 역할 정의를 나열합니다.

    az role definition list \
        --name "Cosmos DB Operator"
    
  2. 출력을 검토하고 Cosmos DB 연산자라는 역할 정의를 찾습니다. 출력에는 속성에 있는 역할 정의 id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    [
      {
        "assignableScopes": [
          "/"
        ],
        "description": "Lets you manage Azure Cosmos DB accounts, but not access data in them. Prevents access to account keys and connection strings.",
        "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/providers/Microsoft.Authorization/roleDefinitions/230815da-be43-4aae-9cb4-875f7bd000aa",
        "name": "230815da-be43-4aae-9cb4-875f7bd000aa",
        "permissions": [
          {
            "actions": [
              "Microsoft.DocumentDb/databaseAccounts/*",
              "Microsoft.Insights/alertRules/*",
              "Microsoft.Authorization/*/read",
              "Microsoft.ResourceHealth/availabilityStatuses/read",
              "Microsoft.Resources/deployments/*",
              "Microsoft.Resources/subscriptions/resourceGroups/read",
              "Microsoft.Support/*",
              "Microsoft.Network/virtualNetworks/subnets/joinViaServiceEndpoint/action"
            ],
            "condition": null,
            "conditionVersion": null,
            "dataActions": [],
            "notActions": [
              "Microsoft.DocumentDB/databaseAccounts/dataTransferJobs/*",
              "Microsoft.DocumentDB/databaseAccounts/readonlyKeys/*",
              "Microsoft.DocumentDB/databaseAccounts/regenerateKey/*",
              "Microsoft.DocumentDB/databaseAccounts/listKeys/*",
              "Microsoft.DocumentDB/databaseAccounts/listConnectionStrings/*",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/write",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/delete",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments/write",
              "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments/delete",
              "Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/write",
              "Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/delete",
              "Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/write",
              "Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/delete"
            ],
            "notDataActions": []
          }
        ],
        "roleName": "Cosmos DB Operator",
        "roleType": "BuiltInRole",
        "type": "Microsoft.Authorization/roleDefinitions",
      }
    ]
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/providers/Microsoft.Authorization/roleDefinitions/230815da-be43-4aae-9cb4-875f7bd000aa. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 그러나 식별자(230815da-be43-4aae-9cb4-875f7bd000aa)는 Azure의 모든 역할 정의에서 전역적으로 고유합니다.

  3. 역할 정의를 정의하는 새 Bicep 파일을 만듭니다. 파일 이름을 control-plane-role-definition.bicep(으)로 지정하십시오. 정의에 다음 actions 을 추가합니다.

    Description
    Microsoft.DocumentDb/* 가능한 모든 작업을 사용하도록 설정합니다.
    metadata description = 'Create RBAC definition for control plane access to Azure Cosmos DB.'
    
    @description('Name of the role definition.')
    param roleDefinitionName string = 'Azure Cosmos DB Control Plane Owner'
    
    @description('Description of the role definition.')
    param roleDefinitionDescription string = 'Can perform all control plane actions for an Azure Cosmos DB account.'
    
    resource definition 'Microsoft.Authorization/roleDefinitions@2022-04-01' = {
      name: guid(subscription().id, resourceGroup().id, roleDefinitionName)
      scope: resourceGroup()
      properties: {
        roleName: roleDefinitionName
        description: roleDefinitionDescription
        type: 'CustomRole'
        permissions: [
          {
            actions: [
              'Microsoft.DocumentDb/*'
            ]
          }
        ]
        assignableScopes: [
          resourceGroup().id
        ]
      }
    }
    
    output definitionId string = definition.id
    
  4. az deployment group create를 사용하여 Bicep 템플릿을 배포합니다. Bicep 템플릿 및 Azure 리소스 그룹의 이름을 지정합니다.

    az deployment group create \
        --resource-group "<name-of-existing-resource-group>" \
        --template-file control-plane-role-definition.bicep
    
  5. 배포의 출력을 검토합니다. 출력에는 속성에 있는 역할 정의 properties.outputs.definitionId.value 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    {
      "properties": {
        "outputs": {
          "definitionId": {
            "type": "String",
            "value": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1"
          }
        }
      }
    }
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleDefinitions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 이 예제는 명확성을 위해 배포에서 출력된 일반적인 JSON의 하위 집합입니다.

  6. 새 Bicep 파일을 만들어 역할 할당을 정의합니다. 파일의 이름을 control-plane-role-assignment.bicep로 지정하십시오.

    metadata description = 'Assign RBAC role for control plane access to Azure Cosmos DB.'
    
    @description('Id of the role definition to assign to the targeted principal in the context of the account.')
    param roleDefinitionId string
    
    @description('Id of the identity/principal to assign this role in the context of the account.')
    param identityId string
    
    resource assignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
      name: guid(subscription().id, resourceGroup().id, roleDefinitionId, identityId)
      scope: resourceGroup()
      properties: {
        roleDefinitionId: roleDefinitionId
        principalId: identityId
      }
    }
    
  7. control-plane-role-assignmentbicepparam라는 새 Bicep 매개 변수 파일을 만듭니다. 이 매개 변수 파일에서; 이전에 기록된 역할 정의 식별자를 매개 변수에 roleDefinitionId 할당하고 ID의 고유 식별자를 매개 변수에 identityId 할당합니다.

    using './control-plane-role-assignment.bicep'
    
    param roleDefinitionId = '<id-of-new-role-definition>'
    param identityId = '<id-of-existing-identity>'
    
  8. 이 Bicep 템플릿을 az deployment group create를 사용하여 배포하십시오.

    az deployment group create \
        --resource-group "<name-of-existing-resource-group>" \
        --parameters control-plane-role-assignment.bicepparam \
        --template-file control-plane-role-assignment.bicep
    
  9. 이 단계를 반복하여 사용하려는 다른 ID에서 계정에 대한 액세스 권한을 부여합니다.

    팁 (조언)

    원하는 만큼 ID에 대해 이러한 단계를 반복할 수 있습니다. 일반적으로 이러한 단계는 개발자가 사용자 ID를 사용하여 계정에 액세스할 수 있도록 허용하고 애플리케이션이 관리 ID를 사용하여 데이터에 액세스할 수 있도록 하기 위해 적어도 반복됩니다.

  1. Azure Portal에 로그인합니다(https://portal.azure.com).

  2. 전역 검색 창에 리소스 그룹을 입력합니다.

    Azure Portal의 전역 검색 창 스크린샷

  3. 서비스 내에서 리소스 그룹을 선택합니다.

    검색 메뉴에서 선택한 '리소스 그룹' 옵션의 스크린샷.

  4. 리소스 그룹 창에서 기존 리소스 그룹을 선택합니다.

    구독에 대한 리소스 그룹 목록에 있는 기존 리소스 그룹의 스크린샷

    비고

    이 예제 스크린샷에는 msdocs-identity-example 리소스 그룹이 포함되어 있습니다. 실제 리소스 그룹 이름은 다를 수 있습니다.

  5. 리소스 그룹의 창 내에서 서비스 메뉴에서 액세스 제어(IAM) 를 선택합니다.

    리소스 그룹에 대한 서비스 메뉴의 '액세스 제어(IAM)' 옵션 스크린샷

  6. 액세스 제어(IAM) 창에서 역할을 선택합니다.

    '액세스 제어(IAM)' 창의 '역할' 옵션 스크린샷

  7. 역할 섹션에서 검색어 Cosmos DB를 사용하고 Cosmos DB 운영자 역할 정의를 찾습니다. 그런 다음 해당 정의와 연결된 보기 옵션을 선택합니다.

    타이틀에 'Cosmos DB'가 있는 정의만 포함하도록 필터링된 현재 할당 가능한 범위의 역할 정의 목록 스크린샷

  8. Cosmos DB 운영자 역할 정의 대화 상자에서 이 역할 정의의 일부로 할당된 작업을 관찰합니다.

    기본 제공 역할 정의에 대한 세부 정보가 포함된 'Cosmos DB 연산자' 대화 상자의 스크린샷

  9. Cosmos DB 연산자 역할 정의 대화 상자를 닫습니다.

  10. 액세스 제어(IAM) 창으로 돌아가서 추가를 선택합니다. 그런 다음 사용자 지정 역할 추가를 선택합니다.

    '추가' 옵션의 '액세스 제어(IAM)' 메뉴에 있는 '사용자 지정 역할 추가' 옵션의 스크린샷

  11. 기본 창에서 다음 옵션을 구성한 다음, 다음을 선택합니다.

    가치
    사용자 지정 역할 이름 Azure Cosmos DB Control Plane Owner
    설명 Can perform all control plane actions for an Azure Cosmos DB account.
    기준 사용 권한 처음부터 시작

    사용자 지정 역할을 추가하기 위한 '기본' 창의 스크린샷.

  12. 사용 권한 창에서 사용 권한 추가를 선택합니다. 그런 다음 권한 대화 상자에서 DocumentDB을(를) 검색하십시오. 마지막으로 Microsoft.DocumentDB 옵션을 선택합니다.

    사용자 지정 역할을 추가하기 위한 '사용 권한' 창의 스크린샷

    사용자 지정 역할을 추가하기 위해 'DocumentDB'에 관련된 사용 권한으로 필터링된 '사용 권한 추가' 대화 상자의 스크린샷

  13. 사용 권한 대화 상자에서 모든 작업Microsoft.DocumentDB에 대해 선택합니다. 그런 다음 추가 를 선택하여 *사용 권한 창으로 돌아갑니다.

    사용자 지정 역할에 대한 대화 상자에서 'DocumentDB'에 대해 선택된 모든 권한의 스크린샷

  14. 사용 권한 창으로 돌아가서 사용 권한 목록을 확인합니다. 그런 다음 검토 + 만들기를 선택합니다.

    사용자 지정 역할에 대한 목록에 여러 권한이 추가된 '사용 권한' 창의 스크린샷

  15. 검토 + 만들기 창에서 새 역할 정의에 대해 지정된 옵션을 검토합니다. 마지막으로 만들기를 선택합니다.

    사용자 지정 역할을 추가하기 위한 '검토 + 만들기' 창의 스크린샷

  16. 포털이 역할 정의 만들기를 완료할 때까지 기다립니다.

  17. 액세스 제어(IAM) 창에서 추가역할 할당 추가를 선택합니다.

    '추가' 옵션에 대한 '액세스 제어(IAM)' 메뉴의 '역할 할당 추가' 옵션 스크린샷

  18. 역할 창에서 이 가이드의 앞부분에서 만든 Azure Cosmos DB 역할을 검색 한 다음 선택합니다. 그런 후에 다음을 선택합니다.

    역할 할당을 추가하기 위한 '역할' 창의 스크린샷

    팁 (조언)

    필요에 따라 사용자 지정 역할만 포함하도록 역할 목록을 필터링할 수 있습니다.

  19. 구성원 창에서 구성원 선택 옵션을 선택합니다. 멤버 대화 상자에서 Azure Cosmos DB 계정에 대해 이 수준의 액세스 권한을 부여하려는 ID를 선택한 다음 선택 옵션을 사용하여 선택을 확인합니다.

    역할 할당을 추가하기 위한 '멤버' 창의 스크린샷.

    역할 할당을 추가하기 위한 ID 선택 대화 상자의 스크린샷

    비고

    이 스크린샷은 의 주체를 가진 kai@adventure-works.com라는 이름의 사용자 예를 보여 줍니다.

  20. 구성원 창으로 돌아가서 선택한 멤버를 검토한 다음 검토 + 할당을 선택합니다.

    역할 할당에 대해 선택한 ID가 있는 '멤버' 창의 스크린샷

  21. 검토 + 할당 창에서 새 역할 할당에 대해 지정된 옵션을 검토합니다. 마지막으로 검토 + 할당을 선택합니다.

    역할 할당에 대한 '검토 + 만들기' 창의 스크린샷

  22. 포털이 역할 할당 만들기를 완료할 때까지 기다립니다.

  1. Azure Cosmos DB 계정과 연결된 모든 역할 정의를 나열하는 데 사용합니다 Get-AzRoleDefinition .

    $parameters = @{
        Name = "Cosmos DB Operator"
    }
    Get-AzRoleDefinition @parameters
    
  2. 출력을 검토하고 Cosmos DB 기본 제공 데이터 기여자라는 역할 정의를 찾습니다. 출력에는 속성에 있는 역할 정의 Id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    Name             : Cosmos DB Operator
    Id               : 230815da-be43-4aae-9cb4-875f7bd000aa
    IsCustom         : False
    Description      : Lets you manage Azure Cosmos DB accounts, but not access data in them. Prevents access to account keys and connection strings.
    Actions          : {Microsoft.DocumentDb/databaseAccounts/*, Microsoft.Insights/alertRules/*, Microsoft.Authorization/*/read, Microsoft.ResourceHealth/availabilityStatuses/read…}
    NotActions       : {Microsoft.DocumentDB/databaseAccounts/dataTransferJobs/*, Microsoft.DocumentDB/databaseAccounts/readonlyKeys/*, Microsoft.DocumentDB/databaseAccounts/regenerateKey/*, Microsoft.DocumentDB/databaseAccounts/listKeys/*…}
    DataActions      : {}
    NotDataActions   : {}
    AssignableScopes : {/}
    

    비고

    이 예제에서 값은 Id .입니다 230815da-be43-4aae-9cb4-875f7bd000aa. 식별자는 Azure의 모든 역할 정의에서 전역적으로 고유합니다.

  3. 현재 리소스 그룹에 대한 메타데이터를 가져오는 데 사용합니다 Get-AzResourceGroup .

    $parameters = @{
        Name = "<name-of-existing-resource-group>"
    }
    Get-AzResourceGroup @parameters
    
  4. 이전 명령의 출력을 관찰합니다. 다음 단계에서 사용하는 데 필요하기 때문에 이 리소스 그룹의 속성 값을 ResourceId 기록합니다.

    ResourceGroupName : msdocs-identity-example
    Location          : westus
    ProvisioningState : Succeeded
    ResourceId        : /subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourcegroups/msdocs-identity-example
    

    비고

    이 예제에서 값은 ResourceId .입니다 /subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourcegroups/msdocs-identity-example. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 이 문자열은 일반적인 출력의 잘린 예입니다.

  5. 먼저 모듈을 Az.Resources 가져옵니다. 그런 다음 새 Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition 개체를 만듭니다. 개체에서 여기에 나열된 값을 지정하는 이 리소스 정의를 만듭니다. 목록AssignableScopes에 이전 단계에서 기록된 리소스 그룹의 ResourceId 속성을 추가합니다. 마지막으로 역할 정의 개체를 -RoleNew-AzRoleDefinition 매개 변수 입력으로 사용합니다.

    Import-Module Az.Resources
    
    $parameters = @{
        TypeName = "Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition"
        Property = @{
            Name = "Azure Cosmos DB Control Plane Owner"
            Description = "Can perform all control plane actions for an Azure Cosmos DB account."
            IsCustom = $true
            Actions = @(
                "Microsoft.DocumentDb/*"
            )
            AssignableScopes = @(
                "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example"
            )
        }
    }
    $role = New-Object @parameters
    
    New-AzRoleDefinition -Role $role
    

    비고

    이 예제에서는 이전 단계에서 기록한 값을 사용합니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example . 실제 리소스 식별자는 다를 수 있습니다.

  6. 정의 만들기 명령의 출력을 검토합니다. 출력에는 속성에 있는 역할 정의 Name 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    Name             : Azure Cosmos DB Control Plane Owner
    Id               : e4e4e4e4-ffff-aaaa-bbbb-c5c5c5c5c5c5
    IsCustom         : True
    Description      : Can perform all control plane actions for an Azure Cosmos DB account.
    Actions          : {Microsoft.DocumentDb/*}
    AssignableScopes : {/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example}
    

    비고

    이 예제에서 값은 Name .입니다 Azure Cosmos DB Control Plane Owner. 이 예제는 명확성을 위해 배포의 일반적인 출력의 하위 집합입니다.

  7. 를 사용하여 새 역할을 할당합니다 New-AzRoleAssignment. RoleDefinitionName 매개 변수에는 역할 이름을, ObjectId 매개 변수에는 ID의 고유 식별자를 사용합니다.

    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        ObjectId = "<your-principal-identifier>"
        RoleDefinitionName = "Azure Cosmos DB Control Plane Owner"
    }
    New-AzRoleAssignment @parameters
    
  8. 명령의 출력을 관찰합니다. 출력에는 속성의 할당 RoleAssignmentId 에 대한 고유 식별자가 포함됩니다.

    RoleAssignmentName : ffffffff-5555-6666-7777-aaaaaaaaaaaa
    RoleAssignmentId   : /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleAssignments/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1
    Scope              : /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example
    DisplayName        : Kai Carter
    SignInName         : <kai@adventure-works.com>
    RoleDefinitionName : Azure Cosmos DB Control Plane Owner
    RoleDefinitionId   : e4e4e4e4-ffff-aaaa-bbbb-c5c5c5c5c5c5
    

    비고

    이 예제에서 RoleAssignmentId 속성은 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.Authorization/roleAssignments/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1, 또 다른 가상의 예입니다. 이 예제는 명확성을 위해 배포의 일반적인 출력의 하위 집합입니다.

  9. 이 단계를 반복하여 사용하려는 다른 ID에서 계정에 대한 액세스 권한을 부여합니다.

    팁 (조언)

    원하는 만큼 ID에 대해 이러한 단계를 반복할 수 있습니다. 일반적으로 이러한 단계는 개발자가 사용자 ID를 사용하여 계정에 액세스할 수 있도록 허용하고 애플리케이션이 관리 ID를 사용하여 데이터에 액세스할 수 있도록 하기 위해 적어도 반복됩니다.

중요합니다

역할 정의를 할당하려면 역할 기반 액세스 제어 권한을 부여하려는 ID의 고유 식별자가 이미 있어야 합니다.

코드에서 컨트롤 플레인 역할 기반 액세스 유효성 검사

애플리케이션 코드 및 Azure Management SDK를 사용하여 액세스 권한을 올바르게 부여했는지 확인합니다.

using Azure.Identity;
using Azure.ResourceManager;

DefaultAzureCredential credential = new();

ArmClient client = new(credential);
const { CosmosDBManagementClient } = require('@azure/arm-cosmosdb');
const { DefaultAzureCredential } = require('@azure/identity');

const subscriptionId = "<subscription-id>";

const credential = new DefaultAzureCredential();

const client = new CosmosDBManagementClient(credential, subscriptionId);
import { CosmosDBManagementClient } from '@azure/arm-cosmosdb';
import { TokenCredential, DefaultAzureCredential } from '@azure/identity';

let subscriptionId: string = "<subscription-id>";

let credential: TokenCredential = new DefaultAzureCredential();

const client: CosmosDBManagementClient = new CosmosDBManagementClient(credential, subscriptionId);
from azure.mgmt.cosmosdb import CosmosDBManagementClient
from azure.identity import DefaultAzureCredential

subscription_id = "<subscription-id>"

credential = DefaultAzureCredential()

client = CosmosDBManagementClient(credential=credential, subscription=subscription_id)
package main

import (
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos"
)

const subscriptionId = "<subscription-id>"

func main() {
    credential, _ := azidentity.NewDefaultAzureCredential(nil)
    
    client, _ := armcosmos.NewDatabaseClient(subscriptionId, credential, nil)
}
package com.example;

import com.azure.core.management.profile.AzureProfile;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DefaultAzureCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.cosmos.CosmosManager;

public class CosmosDB {
    public static void main(String[] args) {
        AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
        DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
          .build();

        CosmosManager manager = CosmosManager.authenticate(credential, profile);
    }
}

데이터 평면 역할 기반 액세스 권한 부여

데이터 평면 액세스는 계정의 리소스를 관리할 수 없는 Azure 서비스 내에서 데이터를 읽고 쓰는 기능을 의미합니다. 예를 들어 Azure Cosmos DB 데이터 평면 액세스에는 다음 기능이 포함될 수 있습니다.

  • 일부 계정 및 리소스 메타데이터 읽기
  • 항목 만들기, 읽기, 업데이트, 패치 및 삭제
  • NoSQL 쿼리 실행
  • 컨테이너의 변경 피드에서 읽기
  • 저장 프로시저 실행
  • 충돌 피드에서 충돌 관리

먼저 NoSQL용 Azure Cosmos DB에서 dataActions 데이터를 읽고, 쿼리하고, 관리할 수 있는 액세스 권한을 부여하는 목록을 사용하여 역할 정의를 준비해야 합니다. 이 가이드에서는 사용자 지정 역할을 준비합니다. 그런 다음 애플리케이션이 NoSQL용 Azure Cosmos DB의 데이터에 액세스할 수 있도록 ID에 새로 정의된 역할을 할당합니다.

중요합니다

기존 데이터 평면 역할 정의를 가져오려면 다음 컨트롤 플레인 권한이 필요합니다.

  • Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/read

새 데이터 평면 역할 정의를 만들려면 다음 컨트롤 플레인 권한이 필요합니다.

  • Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/read
  • Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/write

새 데이터 평면 역할 할당을 만들려면 다음 컨트롤 플레인 권한이 필요합니다.

  • Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions/read
  • Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments/read
  • Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments/write

경고

NoSQL용 Azure Cosmos DB의 네이티브 역할 기반 액세스 제어는 이 속성을 지원하지 notDataActions 않습니다. 허용되는 dataAction 동작으로 지정되지 않은 작업은 자동으로 제외됩니다.

  1. 를 사용하여 az cosmosdb sql role definition listAzure Cosmos DB for NoSQL 계정과 연결된 모든 역할 정의를 나열합니다.

    az cosmosdb sql role definition list \
        --resource-group "<name-of-existing-resource-group>" \
        --account-name "<name-of-existing-nosql-account>"
    
  2. 사용자 지정 역할을 만드는 데 사용되는 role-definition.json이라는 새 JSON 파일을 만듭니다. 이 파일에서 여기에 나열된 데이터 작업을 지정하는 리소스 정의를 만듭니다.

    Description
    Microsoft.DocumentDB/databaseAccounts/readMetadata 계정 수준 메타데이터를 읽을 수 있습니다.
    Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/* 컨테이너 수준 데이터 작업을 수행할 수 있습니다.
    Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/* 컨테이너가 있는 항목에 대해 모든 작업을 수행할 수 있음
    {
      "RoleName": "Azure Cosmos DB for NoSQL Data Plane Owner",
      "Type": "CustomRole",
      "AssignableScopes": [
        "/"
      ],
      "Permissions": [
        {
          "DataActions": [
            "Microsoft.DocumentDB/databaseAccounts/readMetadata",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*"
          ]
        }
      ]
    }
    
  3. 다음으로 역할 정의를 만드는 데 사용합니다 az cosmosdb sql role definition create . role-definition.json--body 인수의 입력으로 사용합니다.

    az cosmosdb sql role definition create \
        --resource-group "<name-of-existing-resource-group>" \
        --account-name "<name-of-existing-nosql-account>" \
        --body "@role-definition.json"
    
  4. 이전 명령의 출력을 검토합니다. NOSQL 데이터 평면 소유자용 Azure Cosmos DB라는 역할 정의를 방금 만들었습니다. 출력에는 속성에 있는 역할 정의 id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 다음과 같이 기록합니다. --role-definition-id

    {
      "assignableScopes": [
        "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql"
      ],
      "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/bbbbbbbb-1111-2222-3333-cccccccccccc",
      "name": "bbbbbbbb-1111-2222-3333-cccccccccccc",
      "permissions": [
        {
          "dataActions": [
            "Microsoft.DocumentDB/databaseAccounts/readMetadata",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*"
          ],
          "notDataActions": []
        }
      ],
      "resourceGroup": "msdocs-identity-example",
      "roleName": "Azure Cosmos DB for NoSQL Data Plane Owner",
      "type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions",
      "typePropertiesType": "CustomRole"
    }
    

    비고

    이 예제에서 값은 --role-definition-id .입니다 bbbbbbbb-1111-2222-3333-cccccccccccc. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다.

  5. id 이전 단계에서 얻은 것을 사용하고 계정 이름 뒤의 --scope 모든 항목을 제거하여 확인합니다.

    비고

    이 예제에서 값은 --scope .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다.

  6. 를 사용하여 새 역할을 할당합니다 az cosmosdb sql role assignment create.
    이전에 기록된 역할 정의 식별자를 --role-definition-id 인수에 사용하고,
    인수에는 ID에 대한 고유 식별자를 사용하며, --principal-id 마지막으로,
    계정의 식별자를 --scope 인수에 사용합니다.

    az cosmosdb sql role assignment create \
        --resource-group "<name-of-existing-resource-group>" \
        --account-name "<name-of-existing-nosql-account>" \
        --role-definition-id "<id-of-new-role-definition>" \ 
        --principal-id "<id-of-existing-identity>" \
        --scope "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql"
    

    팁 (조언)

    사용자 고유의 ID에 데이터 평면 역할 기반 액세스 제어를 부여하려는 경우 이 명령을 사용하여 ID를 가져올 수 있습니다.

    az ad signed-in-user show
    

    자세한 내용은 az ad signed-in-user를 참조하세요.

    팁 (조언)

    Azure Cosmos DB의 역할 기반 액세스 제어 네이티브 구현에서 범위 는 사용 권한을 적용하려는 계정 내에서 리소스의 세분성을 나타냅니다. 가장 높은 수준에서 가장 큰 범위를 사용하여 데이터 평면 역할 기반 액세스 제어 할당의 범위를 전체 계정으로 지정할 수 있습니다. 이 범위에는 계정 내의 모든 데이터베이스 및 컨테이너가 포함됩니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/
    

    또는 데이터 평면 역할 할당의 범위를 특정 데이터베이스로 지정할 수 있습니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/dbs/<database-name>
    

    마지막으로 할당 범위를 가장 세분화된 단일 컨테이너로 지정할 수 있습니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/dbs/<database-name>/colls/<container-name>
    

    대부분의 경우 정규화된 범위 대신 상대 범위를 사용할 수 있습니다. 예를 들어 이 상대 범위를 사용하여 Azure CLI 명령에서 특정 데이터베이스 및 컨테이너에 데이터 평면 역할 기반 액세스 제어 권한을 부여할 수 있습니다.

    /dbs/<database-name>/colls/<container-name>
    

    상대 범위를 사용하여 모든 데이터베이스 및 컨테이너에 대한 범용 액세스 권한을 부여할 수도 있습니다.

    /
    
  7. Azure Cosmos DB for NoSQL 계정에 대한 모든 역할 할당을 나열하는 데 사용합니다 az cosmosdb sql role assignment list . 출력을 검토하여 역할 할당이 생성되었는지 확인합니다.

    az cosmosdb sql role assignment list \
        --resource-group "<name-of-existing-resource-group>" \
        --account-name "<name-of-existing-nosql-account>"
    
  1. 를 사용하여 az cosmosdb sql role definition listAzure Cosmos DB for NoSQL 계정과 연결된 모든 역할 정의를 나열합니다.

    az cosmosdb sql role definition list \
        --resource-group "<name-of-existing-resource-group>" \
        --account-name "<name-of-existing-nosql-account>"
    
  2. 출력을 검토하고 Cosmos DB 기본 제공 데이터 기여자라는 역할 정의를 찾습니다. 출력에는 속성에 있는 역할 정의 id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    [
      ...,
      {
        "assignableScopes": [
          "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql"
        ],
        "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002",
        "name": "00000000-0000-0000-0000-000000000002",
        "permissions": [
          {
            "dataActions": [
              "Microsoft.DocumentDB/databaseAccounts/readMetadata",
              "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*",
              "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*"
            ],
            "notDataActions": []
          }
        ],
        "resourceGroup": "msdocs-identity-example",
        "roleName": "Cosmos DB Built-in Data Contributor",
        "type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions",
        "typePropertiesType": "BuiltInRole"
      }
      ...
    ]
    

    비고

    이 예제에서 값은 id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다.

  3. 역할 정의를 정의하는 새 Bicep 파일을 만듭니다. 파일의 이름을 data-plane-role-definition.bicep으로 지정합니다. 정의에 다음 dataActions 을 추가합니다.

    Description
    Microsoft.DocumentDB/databaseAccounts/readMetadata 계정 수준 메타데이터를 읽을 수 있습니다.
    Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/* 컨테이너 수준 데이터 작업을 수행할 수 있습니다.
    Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/* 컨테이너가 있는 항목에 대해 모든 작업을 수행할 수 있음
    metadata description = 'Create RBAC definition for data plane access to Azure Cosmos DB for NoSQL.'
    
    @description('Name of the Azure Cosmos DB for NoSQL account.')
    param accountName string
    
    @description('Name of the role definition.')
    param roleDefinitionName string = 'Azure Cosmos DB for NoSQL Data Plane Owner'
    
    resource account 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' existing = {
      name: accountName
    }
    
    resource definition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2024-05-15' = {
      name: guid(account.id, roleDefinitionName)
      parent: account
      properties: {
        roleName: roleDefinitionName
        type: 'CustomRole'
        assignableScopes: [
          account.id
        ]
        permissions: [
          {
            dataActions: [
              'Microsoft.DocumentDB/databaseAccounts/readMetadata'
              'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*'
              'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
            ]
          }
        ]
      }
    }
    
    output definitionId string = definition.id
    

    팁 (조언)

    Azure Cosmos DB의 역할 기반 액세스 제어 네이티브 구현에서 범위 는 사용 권한을 적용하려는 계정 내에서 리소스의 세분성을 나타냅니다. 가장 높은 수준에서 가장 큰 범위를 사용하여 데이터 평면 역할 기반 액세스 제어 할당의 범위를 전체 계정으로 지정할 수 있습니다. 이 범위에는 계정 내의 모든 데이터베이스 및 컨테이너가 포함됩니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/
    

    또는 데이터 평면 역할 할당의 범위를 특정 데이터베이스로 지정할 수 있습니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/dbs/<database-name>
    

    마지막으로 할당 범위를 가장 세분화된 단일 컨테이너로 지정할 수 있습니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/dbs/<database-name>/colls/<container-name>
    

    대부분의 경우 정규화된 범위 대신 상대 범위를 사용할 수 있습니다. 예를 들어 이 상대 범위를 사용하여 Azure CLI 명령에서 특정 데이터베이스 및 컨테이너에 데이터 평면 역할 기반 액세스 제어 권한을 부여할 수 있습니다.

    /dbs/<database-name>/colls/<container-name>
    

    상대 범위를 사용하여 모든 데이터베이스 및 컨테이너에 대한 범용 액세스 권한을 부여할 수도 있습니다.

    /
    
  4. data-plane-role-definitionbicepparam이라는 새 Bicep 매개 변수 파일을 만듭니다. 이 매개 변수 파일에서 기존 Azure Cosmos DB for NoSQL 계정의 이름을 매개 변수에 accountName 할당합니다.

    using './data-plane-role-definition.bicep'
    
    param accountName = '<name-of-existing-nosql-account>'
    
  5. az deployment group create를 사용하여 Bicep 템플릿을 배포합니다.

    az deployment group create \
        --resource-group "<name-of-existing-resource-group>" \
        --parameters data-plane-role-definition.bicepparam \
        --template-file data-plane-role-definition.bicep
    
  6. 새 Bicep 파일을 만들어 역할 할당을 정의합니다. 파일의 이름을 data-plane-role-assignment.bicep으로 지정합니다.

    metadata description = 'Assign RBAC role for data plane access to Azure Cosmos DB for NoSQL.'
    
    @description('Name of the Azure Cosmos DB for NoSQL account.')
    param accountName string
    
    @description('Id of the role definition to assign to the targeted principal in the context of the account.')
    param roleDefinitionId string
    
    @description('Id of the identity/principal to assign this role in the context of the account.')
    param identityId string = deployer().objectId
    
    resource account 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' existing = {
      name: accountName
    }
    
    resource assignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2024-05-15' = {
      name: guid(roleDefinitionId, identityId, account.id)
      parent: account
      properties: {
        principalId: identityId
        roleDefinitionId: roleDefinitionId
        scope: account.id
      }
    }
    
    output assignmentId string = assignment.id
    
  7. data-plane-role-assignmentbicepparam라는 새 Bicep 매개 변수 파일을 만듭니다. 이 매개 변수 파일에서 기존 Azure Cosmos DB for NoSQL 계정 accountName 의 이름을 매개 변수에 할당하고, 이전에 기록된 역할 정의 식별자를 roleDefinitionId 매개 변수에 할당하고, ID의 고유 식별자를 매개 변수에 identityId 할당합니다.

    using './data-plane-role-assignment.bicep'
    
    param accountName = '<name-of-existing-nosql-account>'
    param roleDefinitionId = '<id-of-new-role-definition>'
    param identityId = '<id-of-existing-identity>'
    

    팁 (조언)

    사용자 고유의 ID에 데이터 평면 역할 기반 액세스 제어를 부여하려는 경우 매개 변수를 생략할 identityId 수 있습니다. 그런 다음 Bicep 템플릿을 사용하여 deployer().objectId 템플릿을 배포한 주체의 ID를 가져옵니다. 자세한 내용은 deployer를 참조하세요.

  8. az deployment group create를 사용하여 Bicep 템플릿을 배포합니다.

    az deployment group create \
        --resource-group "<name-of-existing-resource-group>" \
        --parameters data-plane-role-assignment.bicepparam \
        --template-file data-plane-role-assignment.bicep
    
  9. 이 단계를 반복하여 사용하려는 다른 ID에서 계정에 대한 액세스 권한을 부여합니다.

    팁 (조언)

    원하는 만큼 ID에 대해 이러한 단계를 반복할 수 있습니다. 일반적으로 이러한 단계는 개발자가 사용자 ID를 사용하여 계정에 액세스할 수 있도록 하기 위해 적어도 반복됩니다. 애플리케이션이 관리 ID를 사용하여 리소스에 액세스할 수 있도록 이러한 단계를 반복할 수도 있습니다.

  1. NoSQL용 Azure Cosmos DB 계정과 연결된 모든 역할 정의를 나열하는 데 사용합니다 Get-AzCosmosDBSqlRoleDefinition .

    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        AccountName = "<name-of-existing-nosql-account>"
    }
    Get-AzCosmosDBSqlRoleDefinition @parameters
    
  2. 출력을 검토하고 Cosmos DB 기본 제공 데이터 기여자라는 역할 정의를 찾습니다. 출력에는 속성에 있는 역할 정의 Id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    Id                         : /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002
    RoleName                   : Cosmos DB Built-in Data Contributor
    Type                       : BuiltInRole
    AssignableScopes           : {/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccountsmsdocs-identity-example-nosql}
    Permissions.DataActions    : {Microsoft.DocumentDB/databaseAccounts/readMetadata, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*}
    Permissions.NotDataActions : 
    

    비고

    이 예제에서 값은 Id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다. 그러나 식별자(00000000-0000-0000-0000-000000000002)는 계정의 모든 역할 정의에서 고유합니다.

  3. 를 사용하여 새 역할 정의를 만듭니다 New-AzCosmosDBSqlRoleDefinition. 매개 변수의 DataAction 경우 여기에 나열된 데이터 작업을 지정합니다.

    Description
    Microsoft.DocumentDB/databaseAccounts/readMetadata 계정 수준 메타데이터를 읽을 수 있습니다.
    Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/* 컨테이너 수준 데이터 작업을 수행할 수 있습니다.
    Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/* 컨테이너가 있는 항목에 대해 모든 작업을 수행할 수 있음
    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        AccountName = "<name-of-existing-nosql-account>"
        RoleName = "Azure Cosmos DB for NoSQL Data Plane Owner"
        Type = "CustomRole"
        AssignableScope = @(
            "/"
        )
        DataAction = @(
            "Microsoft.DocumentDB/databaseAccounts/readMetadata",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*",
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*"
        )
    }
    New-AzCosmosDBSqlRoleDefinition @parameters
    

    팁 (조언)

    Azure Cosmos DB의 역할 기반 액세스 제어 네이티브 구현에서 범위 는 사용 권한을 적용하려는 계정 내에서 리소스의 세분성을 나타냅니다. 가장 높은 수준에서 가장 큰 범위를 사용하여 데이터 평면 역할 기반 액세스 제어 할당의 범위를 전체 계정으로 지정할 수 있습니다. 이 범위에는 계정 내의 모든 데이터베이스 및 컨테이너가 포함됩니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/
    

    또는 데이터 평면 역할 할당의 범위를 특정 데이터베이스로 지정할 수 있습니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/dbs/<database-name>
    

    마지막으로 할당 범위를 가장 세분화된 단일 컨테이너로 지정할 수 있습니다.

    /subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<account-name>/dbs/<database-name>/colls/<container-name>
    

    대부분의 경우 정규화된 범위 대신 상대 범위를 사용할 수 있습니다. 예를 들어 이 상대 범위를 사용하여 Azure CLI 명령에서 특정 데이터베이스 및 컨테이너에 데이터 평면 역할 기반 액세스 제어 권한을 부여할 수 있습니다.

    /dbs/<database-name>/colls/<container-name>
    

    상대 범위를 사용하여 모든 데이터베이스 및 컨테이너에 대한 범용 액세스 권한을 부여할 수도 있습니다.

    /
    
  4. NoSQL용 Azure Cosmos DB 계정과 연결된 모든 역할 정의를 나열하는 데 사용합니다 Get-AzCosmosDBSqlRoleDefinition .

    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        AccountName = "<name-of-existing-nosql-account>"
    }
    Get-AzCosmosDBSqlRoleDefinition @parameters    
    
  5. 이전 명령의 출력을 검토합니다. NOSQL 데이터 평면 소유자용 Azure Cosmos DB라는 역할 정의를 방금 만들었습니다. 출력에는 속성에 있는 역할 정의 Id 의 고유 식별자가 포함됩니다. 이 가이드의 뒷부분에 있는 할당 단계에서 사용하는 데 필요하기 때문에 이 값을 기록합니다.

    Id                         : /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/bbbbbbbb-1111-2222-3333-cccccccccccc
    RoleName                   : Azure Cosmos DB for NoSQL Data Plane Owner
    Type                       : CustomRole
    AssignableScopes           : {/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql}
    Permissions.DataActions    : {Microsoft.DocumentDB/databaseAccounts/readMetadata, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*}
    Permissions.NotDataActions :
    

    비고

    이 예제에서 값은 Id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql/sqlRoleDefinitions/bbbbbbbb-1111-2222-3333-cccccccccccc. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다.

  6. 현재 계정에 대한 메타데이터를 가져오는 데 사용합니다 Get-AzCosmosDBAccount .

    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        Name = "<name-of-existing-nosql-account>"
    }    
    Get-AzCosmosDBAccount @parameters | Select -Property Id
    
  7. 이전 명령의 출력을 관찰합니다. 다음 단계에서 사용해야 하며 이 계정의 Id 속성 값을 기록합니다.

    Id
    --    
    /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql
    

    비고

    이 예제에서 값은 Id .입니다 /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql. 이 예제에서는 가상 데이터를 사용하며 식별자는 이 예제와 다릅니다.

  8. 새 역할을 할당하는 데 사용합니다 New-AzCosmosDBSqlRoleAssignment . 이전에 기록된 역할 정의 식별자를 매개 변수에 RoleDefinitionId 사용하고 ID의 고유 식별자를 매개 변수에 PrincipalId 사용합니다. 마지막으로 매개 변수에 계정의 식별자를 Scope 사용합니다.

    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        AccountName = "<name-of-existing-nosql-account>"
        RoleDefinitionId = "<id-of-new-role-definition>"
        PrincipalId = "<id-of-existing-identity>"
        Scope = "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/msdocs-identity-example/providers/Microsoft.DocumentDB/databaseAccounts/msdocs-identity-example-nosql"
    }    
    New-AzCosmosDBSqlRoleAssignment @parameters
    

    팁 (조언)

    사용자 고유의 ID에 데이터 평면 역할 기반 액세스 제어를 부여하려는 경우 이 명령을 사용하여 ID를 가져올 수 있습니다.

    Get-AzADUser -SignedIn | Format-List `
        -Property Id, DisplayName, Mail, UserPrincipalName
    

    자세한 내용은 Get-AzADUser를 참조하세요.

  9. 를 사용하여 Get-AzCosmosDBSqlRoleAssignmentAzure Cosmos DB for NoSQL 계정에 대한 모든 역할 할당을 나열합니다. 출력을 검토하여 역할 할당이 생성되었는지 확인합니다.

    $parameters = @{
        ResourceGroupName = "<name-of-existing-resource-group>"
        AccountName = "<name-of-existing-nosql-account>"
    }
    Get-AzCosmosDBSqlRoleAssignment @parameters
    

경고

데이터 평면 역할 기반 액세스 제어 관리는 Azure Portal에서 지원되지 않습니다.

코드에서 데이터 평면 역할 기반 액세스 유효성 검사

애플리케이션 코드 및 Azure SDK를 사용하여 액세스 권한을 올바르게 부여했는지 확인합니다.

using Azure.Core;
using Azure.Identity;
using Microsoft.Azure.Cosmos;

string endpoint = "<account-endpoint>";

TokenCredential credential = new DefaultAzureCredential();

CosmosClient client = new(endpoint, credential);

Container container = client.GetContainer("<database-name>", "<container-name>");

await container.ReadItemAsync<dynamic>("<item-id>", new PartitionKey("<partition-key>"));
const { CosmosClient } = require('@azure/cosmos');
const { DefaultAzureCredential } = require('@azure/identity');

const endpoint = '<account-endpoint>';

const credential = new DefaultAzureCredential();

const client = new CosmosClient({ endpoint, aadCredentials:credential});

const container = client.database('<database-name>').container('<container-name>');

await container.item('<item-id>', '<partition-key>').read<String>();
import { Container, CosmosClient, CosmosClientOptions } from '@azure/cosmos'
import { TokenCredential, DefaultAzureCredential } from '@azure/identity'

let endpoint: string = '<account-endpoint>';

let credential: TokenCredential = new DefaultAzureCredential();

let options: CosmosClientOptions = {
  endpoint: endpoint,
  aadCredentials: credential
};

const client: CosmosClient = new CosmosClient(options);

const container: Container = client.database('<database-name>').container('<container-name>');

await container.item('<item-id>', '<partition-key>').read<String>();
from azure.cosmos import CosmosClient
from azure.identity import DefaultAzureCredential

endpoint = "<account-endpoint>"

credential = DefaultAzureCredential()

client = CosmosClient(endpoint, credential=credential)

container = client.get_database_client("<database-name>").get_container_client("<container-name>")

container.read_item(
    item="<item-id>",
    partition_key="<partition-key>",
)
import (
    "context"
    
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos"
)

const endpoint = "<account-endpoint>"

func main() {
    credential, _ := azidentity.NewDefaultAzureCredential(nil)
    client, _ := azcosmos.NewClient(endpoint, credential, nil)
    
    database, _ := client.NewDatabase("<database-name>")
    container, _ := database.NewContainer("<container-name>")
    
    _, err := container.ReadItem(context.TODO(), azcosmos.NewPartitionKeyString("<partition-key>"), "<item-id>", nil)
    if err != nil {
        panic(err)
    }
}
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.models.PartitionKey;
import com.azure.identity.DefaultAzureCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class NoSQL {
    public static void main(String[] args) {   
        DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
            .build();
            
        CosmosClient client = new CosmosClientBuilder()
            .endpoint("<account-endpoint>")
            .credential(credential)
            .buildClient();

        CosmosContainer container = client.getDatabase("<database-name>").getContainer("<container-name>");

        container.readItem("<item-id>", new PartitionKey("<partition-key>"), Object.class);
    }
}
use azure_data_cosmos::CosmosClient;
use azure_identity::DefaultAzureCredential;

fn main() {
    let credential = DefaultAzureCredential::new().unwrap();
    let client = CosmosClient::new("<account-endpoint>", credential, None).unwrap();

    let container = client.database_client("<database-name>").container_client("<container-name>");

    let response = container.read_item("<partition-key>", "<item-id>", None);
    tokio::runtime::Runtime::new().unwrap().block_on(response).unwrap();
}