You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-howto-managed-identities-cosmos-db.md
+64-32Lines changed: 64 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,12 @@
2
2
title: Set up an indexer connection to Azure Cosmos DB using a managed identity
3
3
titleSuffix: Azure AI Search
4
4
description: Learn how to set up an indexer connection to an Azure Cosmos DB account using a managed identity.
5
-
author: gmndrg
6
-
ms.author: gimondra
5
+
author: arv100kri
6
+
ms.author: arjagann
7
7
8
8
ms.service: azure-ai-search
9
9
ms.topic: how-to
10
-
ms.date: 06/10/2024
10
+
ms.date: 12/23/2024
11
11
ms.custom:
12
12
- subject-rbac-steps
13
13
- ignite-2023
@@ -19,17 +19,27 @@ This article explains how to set up an indexer connection to an Azure Cosmos DB
19
19
20
20
You can use a system-assigned managed identity or a user-assigned managed identity. Managed identities are Microsoft Entra logins and require Azure role assignments to access data in Azure Cosmos DB.
21
21
22
-
## Prerequisites
22
+
## Background
23
23
24
-
*[Create a managed identity](search-howto-managed-identities-data-sources.md) for your search service.
24
+
Azure AI Search supports two mechanisms to connect using managed identity.
25
+
26
+
1. The _legacy_ aproach requires configuring the managed identity to have reader permissions on the management plane of the target Azure Cosmos DB account. Azure AI Search will then utilize that identity to fetch the account keys of Cosmos DB account in the background to access the data. This approach will not work if the Cosmos DB account has `"disableLocalAuth": true`. This approach is no longer recommended when connecting to Azure Cosmos DB accounts for NoSQL accounts.
27
+
28
+
1. The _recommended_ approach requires configuring the managed identity appropriatte roles on the management and data plane of the target Azure Cosmos DB account. Azure AI Search will then request an access token to access the data in the Cosmos DB account. This approach will work if the Cosmos DB account has `"disableLocalAuth": true`, and is therefore recommended as the more secure option when connecting to Azure Cosmos DB accounts for NoSQL accounts.
25
29
26
-
* Azure Cosmos DB for NoSQL. You can optionally [enforce role-based access as the only authentication method](/azure/cosmos-db/how-to-setup-rbac#disable-local-auth)for data connections by setting `disableLocalAuth` to `true` for your Cosmos DB account.
30
+
The rest of this document will walk through the steps for the _recommended_ approach, with callouts as needed comparing it with the _legacy_ approach.
27
31
28
-
## Limitations
32
+
###Limitations
29
33
30
-
Indexer support for Azure Cosmos DB for Gremlin and MongoDB Collections is currently in preview. At this time, a preview limitation requires Azure AI Search to connect using keys. You can still set up a managed identity and role assignment, but Azure AI Search will only use the role assignment to get keys for the connection. This limitation means that you can't configure a [role-based approach](/azure/cosmos-db/how-to-setup-rbac#disable-local-auth) if your indexers are connecting to Gremlin or MongoDB.
34
+
Indexer support for Azure Cosmos DB for Gremlin and MongoDB Collections is currently in preview and only supports the _legacy_ approach. The _recommended_ approach only works with Azure Cosmos DB for NoSQL.
35
+
36
+
## Prerequisites
37
+
38
+
*[Create a managed identity](search-howto-managed-identities-data-sources.md) for your search service.
31
39
32
-
## Create a role assignment in Azure Cosmos DB
40
+
* You can optionally [enforce role-based access as the only authentication method](/azure/cosmos-db/how-to-setup-rbac#disable-local-auth) for data connections by setting `disableLocalAuth` to `true` for your Azure Cosmos DB for NoSQL account.
41
+
42
+
## Step 1: Configure role assignments on Azure Cosmos DB control plane
33
43
34
44
### [**Azure portal**](#tab/portal)
35
45
@@ -49,32 +59,36 @@ Indexer support for Azure Cosmos DB for Gremlin and MongoDB Collections is curre
49
59
50
60
1. Select the identity and save the role assignment.
51
61
52
-
For more information, see [Configure role-based access control with Microsoft Entra ID for your Azure Cosmos DB account](/azure/cosmos-db/how-to-setup-rbac).
62
+
For more information, see [Use control plane role-based access control with Azure Cosmos DB for NoSQL](/azure/cosmos-db/nosql/security/how-to-grant-control-plane-role-based-access).
63
+
64
+
## Step 2: Configure role assignments on Azure Cosmos DB data plane
53
65
54
-
### [**PowerShell**](#tab/powershell)
66
+
The managed identity needs to assigned a role to read from the Cosmos DB account's data plane. This step can only be performed via Azure CLI at the moment. The Object (principal) ID for the search service's system/user assigned identity can be found from the search service's "Identity" tab.
67
+
68
+
### [**Azure CLI**](#tab/azcli)
55
69
56
70
Set variables:
57
71
58
-
```azurepowershell
72
+
```azurecli
59
73
$cosmosdb_acc_name = <cosmos db account name>
60
74
$resource_group = <resource group name>
61
75
$subsciption = <subscription ID>
62
-
$system_assigned_principal = <principal ID for the search service's system assigned identity>
76
+
$system_assigned_principal = <Object (principal) ID for the search service's system/user assigned identity>
$scope=$(az cosmosdb show --name $cosmosdbname --resource-group $resourcegroup --query id --output tsv)
65
79
```
66
80
67
81
Define a role assignment for the system-assigned identity:
68
82
69
-
```azurepowershell
83
+
```azurecli
70
84
az cosmosdb sql role assignment create --account-name $cosmosdbname --resource-group $resourcegroup --role-definition-id $readOnlyRoleDefinitionId --principal-id $sys_principal --scope $scope
71
85
```
72
86
73
-
---
87
+
For more information, see [Use data plane role-based access control with Azure Cosmos DB for NoSQL](/azure/cosmos-db/nosql/security/how-to-grant-data-plane-role-based-access)
74
88
75
-
## Specify a managed identity in a connection string
89
+
## Step 3: Configure Azure AI Search data source with managed identity connection string
76
90
77
-
Once you have a role assignment, you can set up a connection to Azure Cosmos DB for NoSQL that operates under that role.
91
+
Once you have configured **both** control plane and data plane role assignments on the Azure Cosmos DB for NoSQL account, you can set up a connection to it that operates under that role.
78
92
79
93
Indexers use a data source object for connections to an external data source. This section explains how to specify a system-assigned managed identity or a user-assigned managed identity on a data source connection string. You can find more [connection string examples](search-howto-managed-identities-data-sources.md#connection-string-examples) in the managed identity article.
80
94
@@ -88,19 +102,22 @@ The [REST API](/rest/api/searchservice/data-sources/create), Azure portal, and t
88
102
When you're connecting with a system-assigned managed identity, the only change to the data source definition is the format of the "credentials" property. Provide a database name and a ResourceId that has no account key or password. The ResourceId must include the subscription ID of Azure Cosmos DB, the resource group, and the Azure Cosmos DB account name.
89
103
90
104
* For SQL collections, the connection string doesn't require "ApiKind".
91
-
* For SQL collections, add "IdentityAuthType=AccessToken" if role-based access is enforced as the only authentication method. It isn't applicable for MongoDB and Gremlin collections.
105
+
* For SQL collections, add "IdentityAuthType=AccessToken" to go through the _recommended_ approach, that is more secure and will work even if the account is configured to enforce role-based access as the only authentication method (i.e., `"disableLocalAuth": true`)
106
+
* When using the REST API or the SDK, if this property is not specified on the connection string, Azure AI Search will default to using the _legacy_ approach. Azure portal will append this property to the connection string as the default.
92
107
* For MongoDB collections, add "ApiKind=MongoDb" to the connection string and use a preview REST API.
93
108
* For Gremlin graphs, add "ApiKind=Gremlin" to the connection string and use a preview REST API.
94
109
95
-
Here's an example of how to create a data source to index data from a Cosmos DB account using the [Create Data Source](/rest/api/searchservice/data-sources/create) REST API and a managed identity connection string. The managed identity connection string format is the same for the REST API, .NET SDK, and the Azure portal.
110
+
MongoDB and Gremlin do not yet support the _recommended_ approach.
111
+
112
+
Here's an example of how to create a data source to index data from a Cosmos DB account using the [Create Data Source](/rest/api/searchservice/data-sources/create) REST API and a managed identity connection string that exercises the _recommended_ approach.
96
113
97
114
```http
98
115
POST https://[service name].search.windows.net/datasources?api-version=2024-07-01
* First, the format of the "credentials" property is the database name and a ResourceId that has no account key or password. The ResourceId must include the subscription ID of Azure Cosmos DB, the resource group, and the Azure Cosmos DB account name.
144
+
>[!NOTE]
145
+
> If the `IdentityAuthType` property is not specified at all, then Azure AI Search defaults to the _legacy_ approach to ensure backward compatibility.
117
146
118
-
* For SQL collections, the connection string doesn't require "ApiKind".
119
-
* For SQL collections, add "IdentityAuthType=AccessToken" if role-based access is enforced as the only authentication method. It isn't applicable for MongoDB and Gremlin collections.
120
-
* For MongoDB collections, add "ApiKind=MongoDb" to the connection string
121
-
* For Gremlin graphs, add "ApiKind=Gremlin" to the connection string.
147
+
### User-assigned managed identity
122
148
123
-
* Second, you add an "identity" property that contains the collection of user-assigned managed identities. Only one user-assigned managed identity should be provided when creating the data source. Set it to type "userAssignedIdentities".
149
+
When you're connecting with a user-assigned managed identity, the connection string definition remains the same as before.
124
150
125
-
Here's an example of how to create an indexer data source object using the REST API.
151
+
You will need to add an "identity" property to the data source definition, where you'll specify the specific identity (out of several that can be assigned to the search service), that'll be used to connect to the Azure Cosmos DB account.
152
+
153
+
Here's an example of how to configure the data source definition, for an Azure Cosmos DB for NOSQL account, using user-assigned identity via the _recommended_ approach.
126
154
127
155
```http
128
156
POST https://[service name].search.windows.net/datasources?api-version=2024-07-01
@@ -131,7 +159,7 @@ POST https://[service name].search.windows.net/datasources?api-version=2024-07-0
@@ -144,13 +172,17 @@ POST https://[service name].search.windows.net/datasources?api-version=2024-07-0
144
172
}
145
173
```
146
174
175
+
## Step 4: Run the indexer and validate the outcome
176
+
147
177
Connection information and permissions on the remote service are validated at run time during indexer execution. If the indexer is successful, the connection syntax and role assignments are valid. For more information, see [Run or reset indexers, skills, or documents](search-howto-run-reset-indexers.md).
148
178
149
179
## Troubleshooting
150
180
151
-
For Azure Cosmos DB for NoSQL, check whether the account has its access restricted to select networks. You can rule out any firewall issues by trying the connection without restrictions in place.
181
+
* For Azure Cosmos DB for NoSQL, check whether the account has its access restricted to select networks. You can rule out any firewall issues by trying the connection without restrictions in place. Refer to [Indexer access to content protected by Azure network security](search-indexer-securing-resources) for more information
182
+
183
+
* For Azure Cosmos DB for NoSQL, if the indexer fails due to authentication issues, ensure that the role assignments have been done **both** on the control plane as well as data plane of the Cosmos DB account.
152
184
153
-
For Gremlin or MongoDB, if you recently rotated your Azure Cosmos DB account keys, you need to wait up to 15 minutes for the managed identity connection string to work.
185
+
*For Gremlin or MongoDB, if you recently rotated your Azure Cosmos DB account keys, you need to wait up to 15 minutes for the managed identity connection string to work.
0 commit comments