Skip to content

Commit cc88443

Browse files
Merge pull request #2542 from MicrosoftDocs/main638747431764765616sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 1ee6e4b + dc07270 commit cc88443

File tree

3 files changed

+138
-32
lines changed

3 files changed

+138
-32
lines changed

data-explorer/ingest-data-cross-tenant.md

Lines changed: 138 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,77 @@ title: Create a cross-tenant data connection for Azure Data Explorer
33
description: Learn how to create a cross-tenant data connection for an Azure Event Hubs or Azure Event Grid service in a different tenant
44
ms.reviewer: vilauzon
55
ms.topic: reference
6-
ms.date: 11/13/2023
6+
ms.date: 02/06/2025
77
---
88
# Cross-tenant data connection
99

10-
When you need to create a data connection for an Azure Event Hubs or Azure Event Grid service in a different tenant, use our [API](/rest/api/azurerekusto/dataconnections/createorupdate) to build the connection.
10+
When you need to create a data connection for an Azure Event Hubs or Azure Event Grid service in a different tenant, use the [Create Data Connections API](/rest/api/azurerekusto/dataconnections/createorupdate) to build the connection.
1111

12-
In the following example, you'll use PowerShell to create a cross-tenant Event Hubs data connection and [auxiliary tokens](/azure/azure-resource-manager/management/authenticate-multi-tenant) to authenticate.
12+
In this article, you learn how to use PowerShell to create a cross-tenant Event Hubs data connection and [auxiliary tokens](/azure/azure-resource-manager/management/authenticate-multi-tenant) to authenticate.
1313

1414
## Prerequisites
1515

1616
* If you don't have an Azure subscription, create a [free Azure account](https://azure.microsoft.com/free/) before you begin.
17-
* Create an [event hub with data for ingestion](ingest-data-event-hub-overview.md) with an account in *Tenant1*, [email protected].
18-
* Create [a test cluster and database](create-cluster-and-database.md), with an account in *Tenant2*, [email protected].
17+
* Create an Event Hub in *Tenant1*. This is the tenant that hosts the source Event Hubs.
18+
* Create [a test cluster and database](create-cluster-and-database.md) in *Tenant2*. This is the tenant that hosts the destination cluster.
19+
* A single Entra account with access to both tenants or a [multitenant service principal](/entra/identity-platform/howto-convert-app-to-be-multi-tenant).
1920

20-
## Assign role to Tenant2 in Event Hubs
21+
## Permissions
2122

22-
1. In the Azure portal, browse to your Event Hubs namespace.
23-
1. In the left menu, select **Access control (IAM)** > **Add role assignments**
23+
The Entra account or multitenant service principal must have at least the following permissions:
24+
25+
- Data Explorer: Contributor
26+
- Event Hubs Namespace: [Azure Event Hubs Data Owner](/azure/role-based-access-control/built-in-roles#azure-event-hubs-data-owner)
2427

25-
:::image type="content" source="media/cross-tenant-ingestion/access-control.png" alt-text="Screenshot of Event Hubs namespace.":::
28+
> [!NOTE]
29+
> The account can be local or guest to Tenant1 or Tenant2, as long as it has the prerequisite permissions.
30+
> Permissions must be at the Namespace level, and not at the Event Hubs level.
2631
27-
1. In the **Add role assignment** window, fill out the following information, and then select **Save**.
32+
## Assign role to the Entra Account or Service Principal in Event Hubs for Tenant1
33+
34+
1. In the Azure portal, browse to your Event Hubs namespace.
2835

29-
:::image type="content" source="media/cross-tenant-ingestion/add-role-assignment.png" alt-text="Screenshot of Add role assignment window in the Azure portal.":::
36+
1. In the left menu, select **Access control (IAM)** > **Add role assignments**.
3037

31-
|**Setting** | **Suggested value** |
32-
|---|---|
38+
1. In the **Add role assignment** window, enter the settings in the table, and then select **Save**.
39+
40+
| **Setting** | **Suggested value** |
41+
|--|--|
3342
| Role | [Azure Event Hubs Data Owner](/azure/role-based-access-control/built-in-roles#azure-event-hubs-data-owner) |
3443
| Assign access to | User, group, or service principal |
35-
| Select | The email address of the user in *Tenant2* |
44+
| Select | The email address of the Entra user or Service Principal ID |
45+
46+
## Assign role to the Entra Account or Service Principal in the cluster for Tenant2
47+
48+
1. In the Azure portal, browse to your Data Explorer cluster.
49+
50+
1. In the left menu, select **Access control (IAM)** > **Add role assignments**.
51+
52+
1. In the **Add role assignment** window, enter the settings in the table and then select **Save**.
53+
54+
| **Setting** | **Suggested value** |
55+
|--|--|
56+
| Role | [Contributor](/azure/role-based-access-control/built-in-roles/privileged#contributor)|
57+
| Assign access to | User, group, or service principal |
58+
| Select | The email address of the Entra user or Service Principal ID |
59+
60+
## Set up the cross-tenant data connection
61+
62+
Set up a cross-tenant data connection between the cluster and Event Hubs using PowerShell.
3663

37-
1. When you receive an email invite on the selected address (`[email protected] account`), accept the invitation.
64+
**Before you begin**
3865

39-
## Get an access token for Tenant1
66+
Create the `Get-AzCachedAccessToken` function to get the access token for *Tenant1*. The source code for the function can be found in the [PowerShell gallery](https://www.powershellgallery.com/packages/AzureSimpleREST/0.2.64/Content/internal%5Cfunctions%5CGet-AzCachedAccessToken.ps1). You can include this code in your personal PowerShell profile to make it easier to call, or you can run it and then use it in these steps.
4067

41-
Before you begin, you'll need the `Get-AzCachedAccessToken` function to get the access token for *Tenant1*. The source code for the function can be found in the [PowerShell gallery](https://www.powershellgallery.com/packages/AzureSimpleREST/0.2.64/Content/internal%5Cfunctions%5CGet-AzCachedAccessToken.ps1). You can include this code in your personal PowerShell profile to make it easier to call, or you can run it and then use it in these steps.
68+
# [Entra account](#tab/entra)
4269

43-
1. Run the following command to connect to *Tenant1*:
70+
1. Run the following command to connect to the Event Hubs subscription in *Tenant1*:
4471

4572
```PowerShell
46-
Connect-AzAccount
73+
Connect-AzAccount -TenantId <Tenant ID> -Subscription "<SubscriptionName>"
4774
```
4875
49-
1. Add a variable with the token for *Tenant1*:
76+
1. Add a variable to store the access token for *Tenant1*:
5077
5178
```PowerShell
5279
$tokenfromtenant1 = Get-AzCachedAccessToken
@@ -58,11 +85,10 @@ Before you begin, you'll need the `Get-AzCachedAccessToken` function to get the
5885
$auxpat="Bearer $tokenfromtenant1"
5986
```
6087
61-
1. Grant `[email protected]` access to the cluster.
62-
1. Set the cluster's subscription ID:
88+
1. Run the following command to connect to the cluster subscription in *Tenant2*:
6389
6490
```PowerShell
65-
Set-AzContext -SubscriptionId "<subscription ID>"
91+
Connect-AzAccount -TenantId <Tenant ID> -SubscriptionId "<SubscriptionName>"
6692
```
6793
6894
1. Add a variable with the token for *Tenant2*:
@@ -77,30 +103,110 @@ Before you begin, you'll need the `Get-AzCachedAccessToken` function to get the
77103
$pat="Bearer $tokenfromtenant2"
78104
```
79105
80-
1. Add an HTTP body request variable to use when invoking the web request:
106+
1. Add an HTTP body request variable to use as an Event Hub resource, when invoking the web request:
81107
82108
```PowerShell
83-
$requestbody ='{"location": "Australia East","kind": "EventHub","properties": { "eventHubResourceId": "/subscriptions/<subscription ID>/resourceGroups/<resource group name>/providers/Microsoft.EventHub/namespaces/<event hub namespace name>/eventhubs/<event hub name>","consumerGroup": "$Default","dataFormat": "JSON", "tableName": "<ADX table name>", "mappingRuleName": "<ADX table mapping name>"}}'
109+
$requestbody ='{"location": "Australia East","kind": "EventHub","properties": { "eventHubResourceId": "/subscriptions/<subscription ID>/resourceGroups/<ResourceGroupName>/providers/Microsoft.EventHub/namespaces/<EventHubNamespaceName>/eventhubs/<EventHubName>","consumerGroup": "$Default","dataFormat": "JSON", "tableName": "<ADXTableName>", "mappingRuleName": "<ADXTableMappingName>"}}'
84110
```
85111
86-
1. Add a URI variable to use when invoking the web request:
112+
1. Add a URI variable to use as a cluster resource, when invoking the web request:
87113
88114
```PowerShell
89-
$adxdcuri="https://management.azure.com/subscriptions/<subscription ID>/resourceGroups/<resource group name>/providers/Microsoft.Kusto/clusters/<adx cluster name>/databases/<adx db name>/dataconnections/<adx data connection name>?api-version=2020-02-15"
115+
$adxdcuri="https://management.azure.com/subscriptions/<subscriptionID>/resourceGroups/<resource group name>/providers/Microsoft.Kusto/clusters/<ADXClusterName>/databases/<ADXdbName>/dataconnections/<ADXDataConnectionName>?api-version=2020-02-15"
90116
```
91117
92-
1. Add `[email protected]` as a contributor in the cluster.
93-
1. Invoke the following web request that uses the previously defined variables.
118+
1. Invoke the following web request, that uses the previously defined variables, to create the data connection:
94119
95120
```PowerShell
96121
Invoke-WebRequest -Headers @{Authorization = $pat; 'x-ms-authorization-auxiliary' = $auxpat} -Uri $adxdcuri -Body $requestbody -Method PUT -ContentType 'application/json'
97122
```
98123
99-
You should now be able to see the newly created data connection in the Azure portal.
124+
# [Service Principal account](#tab/spa)
100125
101-
> [!NOTE]
102-
> If the access used to build the data connection is revoked on Event Hubs, make sure you delete the data connection. Otherwise, Azure Data Explorer will continue to ingest data even if access on Event Hubs is revoked.
126+
1. Define the Service Principal ID:
127+
128+
```PowerShell
129+
$ServicePrincipalID = "<Application(Client)ID>"
130+
```
131+
132+
1. Set the Service Principal secret:
133+
134+
```PowerShell
135+
$Password = ConvertTo-SecureString -String "<Secret>" -AsPlainText -Force
136+
```
137+
138+
1. Create a new PSCredential object to securely store and pass credentials:
139+
140+
```PowerShell
141+
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $ServicePrincipalID, $Password
142+
```
143+
144+
1. Connect to the Event Hub subscription in *Tenant1*:
145+
146+
```PowerShell
147+
Connect-AzAccount -TenantId <Tenant ID> -Subscription "<SubscriptionName>" -ServicePrincipal -Credential $Credential
148+
```
149+
150+
1. Store the cached access token in the $tokenfromtenant1 variable:
151+
152+
```PowerShell
153+
$tokenfromtenant1 = Get-AzCachedAccessToken
154+
```
155+
156+
1. Create a string that includes the cached access token in the format required for authorization headers:
157+
158+
```PowerShell
159+
$auxpat="Bearer $tokenfromtenant1"
160+
```
161+
162+
1. Connect to the cluster subscription in *Tenant2*:
163+
164+
```PowerShell
165+
Connect-AzAccount -TenantId <Tenant ID> -Subscription "<SubscriptionName>" -ServicePrincipal -Credential $Credential
166+
```
167+
168+
1. Store the cached access token in the $tokenfromtenant2 variable.
169+
170+
```powershell
171+
$tokenfromtenant2 = Get-AzCachedAccessToken
172+
```
173+
174+
1. Create a string that includes the cached access token in the format required for authorization headers:
175+
176+
```powershell
177+
$pat="Bearer $tokenfromtenant2"
178+
```
179+
180+
1. Add Event hub resource details to a variable:
181+
182+
```PowerShell
183+
$requestbody = '{"location": "East US", "kind": "EventHub", "properties": { "eventHubResourceId": "/subscriptions/<subscriptionID>/resourceGroups/<ResourceGroupName>/providers/Microsoft.EventHub/namespaces/<EventHubNamespaceName>/eventhubs/<EventHubName>", "consumerGroup": "$Default", "dataFormat": "MultiJSON", "tableName": "<ADXTableName>", "mappingRuleName": "<ADXTableMappingName>"}}'
184+
```
185+
186+
1. Add cluster details to a variable:
187+
188+
```PowerShell
189+
$adxdcuri="https://management.azure.com/subscriptions/<subscriptionID>/resourceGroups/<ResourceGroupName>/providers/Microsoft.Kusto/clusters/<ADXClusterName>/databases/<ADXdbName>/dataconnections/<ADXDataConnectionName>?api-version=2020-02-15"
190+
```
191+
192+
1. Send the request to create the data connection:
193+
194+
```PowerShell
195+
Invoke-WebRequest -Headers @{Authorization = $pat; 'x-ms-authorization-auxiliary' = $auxpat} -Uri $adxdcuri -Body $requestbody -Method PUT -ContentType 'application/json'
196+
```
197+
198+
---
199+
200+
**After you finish**
201+
202+
1. Verify that you can now see the newly created data connection in the Azure portal.
203+
204+
1. *Optional*: After establishing the data connection, you can revoke or delete the previously granted permissions for the Entra Account or Service Principal. Since the cluster ingestion uses the Event Hubs keys, these permissions are no longer required.
205+
206+
> [!IMPORTANT]
207+
> If the primary or secondary Event Hubs keys are rotated, data ingestion might stop working. In that case, you need to drop and recreate the data connection.
103208
104209
## Related content
105210
106211
* [Query data in Azure Data Explorer](web-query-data.md)
212+
* [Convert to multitenant](/entra/identity-platform/howto-convert-app-to-be-multi-tenant)
-129 KB
Binary file not shown.
-74.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)