다음을 통해 공유


NoSQL용 Azure Cosmos DB를 사용하여 키 기반 인증 사용 안 함

이 문서에서는 Azure Cosmos DB for NoSQL 계정에 대한 키 기반 권한 부여(또는 리소스 소유자 암호 자격 증명 인증)를 사용하지 않도록 설정하는 프로세스를 설명합니다.

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

필수 조건

  • 활성 구독이 있는 Azure 계정. 무료로계정을 만드세요.

키 기반 인증 사용 안 함

먼저 애플리케이션에서 Microsoft Entra 인증을 사용해야 하므로 기존 계정에 대한 키 기반 인증을 사용하지 않도록 설정합니다. 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-AzResourceSet-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);

중요합니다

이 코드 샘플에서는 NuGet의 Microsoft.Azure.Cosmos 라이브러리를 사용합니다.