다음을 통해 공유


Azure Event Hubs의 대상에 이벤트를 캡처하기 위한 모드 인증

Azure Event Hubs를 사용하면 선택한 Azure Blob Storage 또는 Azure Data Lake Storage Gen 1 또는 Gen 2 계정과 같은 대상에 이벤트를 캡처할 때 다른 인증 모드를 선택할 수 있습니다. 인증 모드는 Event Hubs에서 실행되는 캡처 에이전트가 캡처 대상으로 인증하는 방법을 결정합니다.

SAS 기반 인증

기본 인증 방법은 SAS(공유 액세스 서명)를 사용하여 Event Hubs 서비스에서 캡처 대상에 액세스하는 것입니다.

기본 SAS 인증 모드를 사용하여 Event Hubs 데이터를 Azure Storage 또는 Azure Data Lake Storage로 캡처하는 것을 보여주는 이미지

이 방법을 사용하면 동일한 구독에만 있는 대상 리소스에 데이터를 캡처할 수 있습니다.

관리 ID 사용

관리 ID를 사용하면 사용자는 Microsoft Entra ID 기반 인증 및 권한 부여를 사용하여 원하는 대상으로 데이터를 원활하게 캡처할 수 있습니다.

관리 ID를 사용하여 Event Hubs 데이터를 Azure Storage 또는 Azure Data Lake Storage로 캡처하는 것을 보여주는 이미지

Event Hubs 캡처 대상에서 시스템 할당 또는 사용자 할당 관리 ID를 사용할 수 있습니다.

시스템이 할당한 관리 ID를 사용하여 이벤트 캡처

시스템이 할당한 관리 ID는 자동으로 만들어지고 이 경우 Event Hubs 네임스페이스인 Azure 리소스와 연결됩니다.

시스템 할당 ID를 사용하려면 캡처 대상에 해당 시스템 할당 ID에 대해 필요한 역할 할당을 사용하도록 설정해야 합니다. 그런 다음, 이벤트 허브에서 캡처 기능을 사용하도록 설정할 때 System Assigned 관리 ID 옵션을 선택할 수 있습니다.

시스템 할당 관리 ID를 사용하여 Event Hubs 데이터를 Azure Storage 또는 Azure Data Lake Storage로 캡처하는 것을 보여주는 이미지.

그런 다음, 캡처 에이전트는 캡처 대상을 사용하여 인증 및 권한 부여에 네임스페이스의 ID를 사용합니다.

Azure Resource Manager 템플릿

다음은 시스템 할당 관리 ID를 사용하여 데이터 캡처를 구성하는 Azure Resource Manager 템플릿 예제입니다.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "namespaces_eventhubcapture_name": {
            "defaultValue": "eventhubcapturens",
            "type": "String"
        },
        "captureEnabled": {
            "defaultValue": true,
            "type": "Bool",
            "metadata": {
                "description": "Enable or disable the Capture feature for your event hub."
            }
        },
        "captureEncodingFormat": {
            "defaultValue": "Avro",
            "allowedValues": [
                "Avro"
            ],
            "type": "String",
            "metadata": {
                "description": "The encoding format that Event Hubs Capture uses to serialize the event data when archiving to your storage."
            }
        },
        "captureTime": {
            "defaultValue": 300,
            "minValue": 60,
            "maxValue": 900,
            "type": "Int",
            "metadata": {
                "description": "the time window in seconds for the archival."
            }
        },
        "captureSize": {
            "defaultValue": 314572800,
            "minValue": 10485760,
            "maxValue": 524288000,
            "type": "Int",
            "metadata": {
                "description": "the size window in bytes for the capture."
            }
        },
        "blobContainerName": {
            "type": "String",
            "metadata": {
                "description": "Your existing storage container that you want the blobs archived in."
            }
        },
        "captureNameFormat": {
            "defaultValue": "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}",
            "type": "String",
            "metadata": {
                "description": "A Capture Name Format must contain {Namespace}, {EventHub}, {PartitionId}, {Year}, {Month}, {Day}, {Hour}, {Minute} and {Second} fields. These can be arranged in any order with or without delimiters. E.g.  Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}"
            }
        },
		"existingStgSubId": {
            "type": "String",
            "metadata": {
                "description": "The ID of the Azure subscription that has your existing storage account."
            }
        },
		"existingStgAccRG": {
            "type": "String",
            "metadata": {
                "description": "The resource group that has the storage account."
            }
        },
        "existingStgAcctName": {
            "type": "String",
            "metadata": {
                "description": "The name of the storage account."
            }
        }
    },
    "variables": 
	{
		"roleAssignmentId": "[guid(resourceId('Microsoft.EventHub/namespaces/',parameters('namespaces_eventhubcapture_name')))]",
		"storageBlobDataOwnerId": "[concat(subscription().Id, '/providers/Microsoft.Authorization/roleDefinitions/', 'b7e6dc6d-f1e8-4753-8033-0f276bb0955b')]",
		"ehId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/', 'Microsoft.EventHub/namespaces/',parameters('namespaces_eventhubcapture_name')) ]",
		"existingStorageAcctResourceId" : "[concat('/subscriptions/', parameters('existingStgSubId'), '/resourceGroups/', parameters('existingStgAccRG'), '/providers/', 'Microsoft.Storage/storageAccounts/',parameters('existingStgAcctName')) ]"
	},
    "resources": [
        {
            "type": "Microsoft.EventHub/namespaces",
            "apiVersion": "2023-01-01-preview",
            "name": "[parameters('namespaces_eventhubcapture_name')]",
            "location": "eastus",
            "sku": {
                "name": "Standard",
                "tier": "Standard",
                "capacity": 1
            },
            "identity": {
                "type": "SystemAssigned"
            },
            "properties": {
                "minimumTlsVersion": "1.2",
                "publicNetworkAccess": "Enabled",
                "disableLocalAuth": false,
                "zoneRedundant": true,
                "isAutoInflateEnabled": false,
                "maximumThroughputUnits": 0,
                "kafkaEnabled": true
            }
        },
        {
            "type": "Microsoft.EventHub/namespaces/authorizationrules",
            "apiVersion": "2023-01-01-preview",
            "name": "[concat(parameters('namespaces_eventhubcapture_name'), '/RootManageSharedAccessKey')]",
            "location": "eastus",
            "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces', parameters('namespaces_eventhubcapture_name'))]"
            ],
            "properties": {
                "rights": [
                    "Listen",
                    "Manage",
                    "Send"
                ]
            }
        },
		{
			"type": "Microsoft.Resources/deployments",
			"apiVersion": "2022-09-01",
			"name": "nestedStgTemplate",
			"subscriptionId": "[parameters('existingStgSubId')]",
			"resourceGroup": "[parameters('existingStgAccRG')]",
			"properties": {
				"expressionEvaluationOptions": {
					"scope": "outer"
				},
				"mode": "Incremental",
				"template": {
					"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
					"contentVersion": "1.0.0.0",
					"resources": [
						{
							"type": "Microsoft.Authorization/roleAssignments",
							"name": "C0F7F914-0FF9-47B2-9960-1D64D97FF594",
							"apiVersion": "2018-01-01-preview",
							"scope": "[variables('existingStorageAcctResourceId')]",
							"properties": {
								"roleDefinitionId": "[variables('storageBlobDataOwnerId')]",
								"principalId": "[reference(variables('ehId'), '2021-11-01', 'Full').identity.principalId]"
							}
						}
					]
				}
			}
		},
        {
            "type": "Microsoft.EventHub/namespaces/eventhubs",
            "apiVersion": "2023-01-01-preview",
            "name": "[concat(parameters('namespaces_eventhubcapture_name'), '/capture')]",
            "location": "eastus",
            "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces', parameters('namespaces_eventhubcapture_name'))]",
				"nestedStgTemplate"
            ],
            "properties": {
                "retentionDescription": {
                    "cleanupPolicy": "Delete",
                    "retentionTimeInHours": 24
                },
                "messageRetentionInDays": 1,
                "partitionCount": 1,
                "status": "Active",
                "captureDescription": {
                    "enabled": "[parameters('captureEnabled')]",
                    "skipEmptyArchives": false,
                    "encoding": "[parameters('captureEncodingFormat')]",
                    "intervalInSeconds": "[parameters('captureTime')]",
                    "sizeLimitInBytes": "[parameters('captureSize')]",
                    "destination": {
                        "name": "EventHubArchive.AzureBlockBlob",
                        "properties": {
                            "storageAccountResourceId": "[variables('existingStorageAcctResourceId')]",
                            "blobContainer": "[parameters('blobContainerName')]",
                            "archiveNameFormat": "[parameters('captureNameFormat')]"
                        },
						"identity": {
							"type": "SystemAssigned"
						}
                    }
                }
            }
        },
        {
            "type": "Microsoft.EventHub/namespaces/networkRuleSets",
            "apiVersion": "2023-01-01-preview",
            "name": "[concat(parameters('namespaces_eventhubcapture_name'), '/default')]",
            "location": "eastus",
            "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces', parameters('namespaces_eventhubcapture_name'))]"
            ],
            "properties": {
                "publicNetworkAccess": "Enabled",
                "defaultAction": "Allow",
                "virtualNetworkRules": [],
                "ipRules": []
            }
        },
        {
            "type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
            "apiVersion": "2023-01-01-preview",
            "name": "[concat(parameters('namespaces_eventhubcapture_name'), '/capture/$Default')]",
            "location": "eastus",
            "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('namespaces_eventhubcapture_name'), 'capture')]",
                "[resourceId('Microsoft.EventHub/namespaces', parameters('namespaces_eventhubcapture_name'))]"
            ],
            "properties": {}
        }
    ]
}

Parameters.json:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "namespaces_eventhubcapture_name": {
            "value": "NAMESPACENAME"
        },
        "captureEnabled": {
            "value": true
        },
        "captureEncodingFormat": {
            "value": "Avro"
        },
        "captureTime": {
            "value": 300
        },
        "captureSize": {
            "value": 314572800
        },
        "blobContainerName": {
            "value": "BLOBCONTAINERNAME"
        },
        "captureNameFormat": {
            "value": "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}"
        },
		"existingStgSubId": {
            "value": "00000000-0000-0000-0000-00000000000000"
        },
		"existingStgAccRG": {
            "value": "STORAGERESOURCEGROUPNAME"
        },
		"existingStgAcctName": {
            "value": "STORAGEACCOUNTNAME"
        }
    }
}

사용자가 할당한 관리 ID를 사용하여 이벤트 캡처

사용자가 할당한 관리 ID를 만들고 이를 사용하여 Event Hubs의 캡처 대상을 인증하고 권한을 부여할 수 있습니다. 관리 ID가 만들어지면 Event Hubs 네임스페이스에 할당하고 캡처 대상에 해당 사용자 할당 ID에 대해 필요한 역할 할당이 사용하도록 설정되어 있는지 확인할 수 있습니다.

그런 다음, 이벤트 허브에서 캡처 기능을 사용하도록 설정할 때 User Assigned 관리 ID 옵션을 선택하고 캡처 기능을 사용하도록 설정하면 필요한 사용자 할당 ID를 할당할 수 있습니다.

Azure Storage 또는 Azure Data Lake Storage로 Event Hubs 데이터 캡처를 보여주는 이미지 그런 다음, 캡처 에이전트는 캡처 대상에 대한 인증 및 권한 부여를 위해 구성된 사용자 할당 ID를 사용합니다.

다른 구독의 캡처 대상으로 이벤트 캡처

Event Hubs 캡처 기능은 관리 ID를 사용하여 다른 구독의 캡처 대상으로 데이터 캡처를 지원합니다.

Important

다른 구독에서 캡처 대상을 선택하는 것은 Azure Portal에서 지원되지 않습니다. 해당 목적을 위해 ARM 템플릿을 사용해야 합니다.

이를 위해 해당 관리 ID를 통해 ARM 템플릿 가이드를 사용하여 캡처를 사용하도록 설정하는 데 지정된 것과 동일한 ARM 템플릿을 사용할 수 있습니다.

예를 들어 다음 ARM 템플릿을 사용하여 캡처를 사용하도록 설정된 이벤트 허브를 만들 수 있습니다. Azure Storage 또는 Azure Data Lake Storage Gen 2는 캡처 대상으로 사용할 수 있으며 사용자 할당 ID는 인증 방법으로 사용됩니다. 대상의 리소스 ID는 다른 구독의 리소스를 가리킬 수 있습니다.

"resources":[
      {
         "apiVersion":"[variables('ehVersion')]",
         "name":"[parameters('eventHubNamespaceName')]",
         "type":"Microsoft.EventHub/Namespaces",
         "location":"[variables('location')]",
         "sku":{
            "name":"Standard",
            "tier":"Standard"
         },
         "resources": [
    {
      "apiVersion": "2017-04-01",
      "name": "[parameters('eventHubNamespaceName')]",
      "type": "Microsoft.EventHub/Namespaces",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "isAutoInflateEnabled": "true",
        "maximumThroughputUnits": "7"
      },
      "resources": [
        {
          "apiVersion": "2017-04-01",
          "name": "[parameters('eventHubName')]",
          "type": "EventHubs",
          "dependsOn": [
            "[concat('Microsoft.EventHub/namespaces/', parameters('eventHubNamespaceName'))]"
          ],
          "properties": {
            "messageRetentionInDays": "[parameters('messageRetentionInDays')]",
            "partitionCount": "[parameters('partitionCount')]",
            "captureDescription": {
              "enabled": "true",
              "skipEmptyArchives": false,
              "encoding": "[parameters('captureEncodingFormat')]",
              "intervalInSeconds": "[parameters('captureTime')]",
              "sizeLimitInBytes": "[parameters('captureSize')]",
              "destination": {
                "name": "EventHubArchive.AzureBlockBlob",
                "properties": {
                  "storageAccountResourceId": "[parameters('destinationStorageAccountResourceId')]",
                  "blobContainer": "[parameters('blobContainerName')]",
                  "archiveNameFormat": "[parameters('captureNameFormat')]"
                },
               "identity": {
                 "type": "UserAssigned",
                 "userAssignedIdentities": {
                   "xxxxxxxx": {}
                  }
          						}
              }
            }
          }
        }
      ]
    }
  ]