Skip to content

Commit ec26a81

Browse files
authored
Merge pull request #5928 from haileytap/quickstarts
[Azure Search] Update search-get-started-rbac.md
2 parents 05cc80d + 7795c3e commit ec26a81

File tree

10 files changed

+263
-158
lines changed

10 files changed

+263
-158
lines changed

articles/search/includes/quickstarts/full-text-rest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ To set up your request file:
8989
@token = PUT-YOUR-PERSONAL-IDENTITY-TOKEN-HERE
9090
9191
### List existing indexes by name
92-
GET {{baseUrl}}/indexes?api-version=2024-07-01
92+
GET {{baseUrl}}/indexes?api-version=2024-07-01 HTTP/1.1
9393
Authorization: Bearer {{token}}
9494
```
9595
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
manager: nitinme
3+
author: haileytap
4+
ms.author: haileytapia
5+
ms.service: azure-ai-search
6+
ms.topic: include
7+
ms.date: 07/09/2025
8+
---
9+
10+
In this quickstart, you use role-based access control (RBAC) and Microsoft Entra ID to establish a keyless connection to your Azure AI Search service. You then use Python in Visual Studio Code to interact with your service.
11+
12+
Keyless connections provide enhanced security through granular permissions and identity-based authentication. We don't recommend hard-coded API keys, but if you prefer them, see [Connect to Azure AI Search using keys](../../search-security-api-keys.md).
13+
14+
<!-- This quickstart is a prerequisite for other quickstarts that use Microsoft Entra ID with role assignments. -->
15+
16+
## Prerequisites
17+
18+
+ An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
19+
20+
+ An [Azure AI Search service](../../search-create-service-portal.md) in any region or tier.
21+
22+
+ The [Azure CLI](/cli/azure/install-azure-cli) for keyless authentication with Microsoft Entra ID.
23+
24+
+ [Visual Studio Code](https://code.visualstudio.com/) with the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) and [Jupyter package](https://jupyter.org/install).
25+
26+
[!INCLUDE [Setup](./search-get-started-rbac-setup.md)]
27+
28+
## Sign in to Azure
29+
30+
Before you connect to your Azure AI Search service, use the Azure CLI to sign in to the subscription that contains your service. This step establishes your Microsoft Entra identity, which `DefaultAzureCredential` uses to authenticate requests in the next section.
31+
32+
To sign in:
33+
34+
1. On your local system, open a command-line tool.
35+
36+
1. Sign in to Azure. If you have multiple subscriptions, select the one whose ID you obtained in [Get service information](#get-service-information).
37+
38+
```azurecli
39+
az login
40+
```
41+
42+
## Connect to Azure AI Search
43+
44+
> [!NOTE]
45+
> This section illustrates the basic Python pattern for keyless connections. For comprehensive guidance, see a specific quickstart or tutorial, such as [Quickstart: Run agentic retrieval in Azure AI Search](../../search-get-started-agentic-retrieval.md).
46+
47+
You can use Python notebooks in Visual Studio Code to send requests to your Azure AI Search service. For request authentication, use the `DefaultAzureCredential` class from the Azure Identity library.
48+
49+
To connect using Python:
50+
51+
1. On your local system, open Visual Studio Code.
52+
53+
1. Create a `.ipynb` file.
54+
55+
1. Create a code cell to install the `azure-identity` and `azure-search-documents` libraries.
56+
57+
```python
58+
pip install azure-identity azure-search-documents
59+
```
60+
61+
1. Create another code cell to authenticate and connect to your search service.
62+
63+
```python
64+
from azure.identity import DefaultAzureCredential
65+
from azure.search.documents.indexes import SearchIndexClient
66+
67+
service_endpoint = "PUT-YOUR-SEARCH-SERVICE-ENDPOINT-HERE"
68+
credential = DefaultAzureCredential()
69+
client = SearchIndexClient(endpoint=service_endpoint, credential=credential)
70+
71+
# List existing indexes
72+
indexes = client.list_indexes()
73+
74+
for index in indexes:
75+
index_dict = index.as_dict()
76+
print(json.dumps(index_dict, indent=2))
77+
```
78+
79+
1. Set `service_endpoint` to the value you obtained in [Get service information](#get-service-information).
80+
81+
1. Select **Run All** to run both code cells.
82+
83+
The output should list the existing indexes (if any) on your search service, indicating a successful connection.
84+
85+
### Troubleshoot 401 errors
86+
87+
If you encounter a 401 error, follow these troubleshooting steps:
88+
89+
+ Revisit [Configure role-based access](#configure-role-based-access). Your search service must have **Role-based access control** or **Both** enabled. Policies at the subscription or resource group level might also override your role assignments.
90+
91+
+ Revisit [Sign in to Azure](#sign-in-to-azure). You must sign in to the subscription that contains your search service.
92+
93+
+ Make sure your endpoint variable has surrounding quotes.
94+
95+
+ If all else fails, restart your device to remove cached tokens and then repeat the steps in this quickstart, starting with [Sign in to Azure](#sign-in-to-azure).
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
manager: nitinme
3+
author: haileytap
4+
ms.author: haileytapia
5+
ms.service: azure-ai-search
6+
ms.topic: include
7+
ms.date: 07/09/2025
8+
---
9+
10+
In this quickstart, you use role-based access control (RBAC) and Microsoft Entra ID to establish a keyless connection to your Azure AI Search service. You then use REST in Visual Studio Code to interact with your service.
11+
12+
Keyless connections provide enhanced security through granular permissions and identity-based authentication. We don't recommend hard-coded API keys, but if you prefer them, see [Connect to Azure AI Search using keys](../../search-security-api-keys.md).
13+
14+
<!-- This quickstart is a prerequisite for other quickstarts that use Microsoft Entra ID with role assignments. -->
15+
16+
## Prerequisites
17+
18+
+ An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
19+
20+
+ An [Azure AI Search service](../../search-create-service-portal.md) in any region or tier.
21+
22+
+ The [Azure CLI](/cli/azure/install-azure-cli) for keyless authentication with Microsoft Entra ID.
23+
24+
+ [Visual Studio Code](https://code.visualstudio.com/) with the [REST Client extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client).
25+
26+
[!INCLUDE [Setup](./search-get-started-rbac-setup.md)]
27+
28+
## Get token
29+
30+
Before you connect to your Azure AI Search service, use the Azure CLI to sign in to the subscription that contains your service and generate a Microsoft Entra ID token. You use this token to authenticate requests in the next section.
31+
32+
To get your token:
33+
34+
1. On your local system, open a command-line tool.
35+
36+
1. Sign in to Azure. If you have multiple subscriptions, select the one whose ID you obtained in [Get service information](#get-service-information).
37+
38+
```azurecli
39+
az login
40+
```
41+
42+
1. Generate an access token.
43+
44+
```azurecli
45+
az account get-access-token --scope https://search.azure.com/.default --query accessToken --output tsv
46+
```
47+
48+
1. Make a note of the token output.
49+
50+
## Connect to Azure AI Search
51+
52+
> [!NOTE]
53+
> This section illustrates the basic REST pattern for keyless connections. For comprehensive guidance, see a specific quickstart or tutorial, such as [Quickstart: Run agentic retrieval in Azure AI Search](../../search-get-started-agentic-retrieval.md).
54+
55+
You can use the REST Client extension in Visual Studio Code to send requests to your Azure AI Search service. For request authentication, include an `Authorization` header with the Microsoft Entra ID token you previously generated.
56+
57+
To connect using REST:
58+
59+
1. On your local system, open Visual Studio Code.
60+
61+
1. Create a `.rest` or `.http` file.
62+
63+
1. Paste the following placeholders and request into the file.
64+
65+
```http
66+
@baseUrl = PUT-YOUR-SEARCH-SERVICE-ENDPOINT-HERE
67+
@token = PUT-YOUR-PERSONAL-IDENTITY-TOKEN-HERE
68+
69+
### List existing indexes
70+
GET {{baseUrl}}/indexes?api-version=2024-07-01 HTTP/1.1
71+
Content-Type: application/json
72+
Authorization: Bearer {{token}}
73+
```
74+
75+
1. Replace `@baseUrl` with the value you obtained in [Get service information](#get-service-information).
76+
77+
1. Replace `@token` with the value you obtained in [Get token](#get-token).
78+
79+
1. Under `### List existing indexes`, select **Send Request**.
80+
81+
You should receive an `HTTP/1.1 200 OK` response, indicating a successful connection to your search service.
82+
83+
### Troubleshoot 401 errors
84+
85+
If you encounter a 401 error, follow these troubleshooting steps:
86+
87+
+ Revisit [Configure role-based access](#configure-role-based-access). Your search service must have **Role-based access control** or **Both** enabled. Policies at the subscription or resource group level might also override your role assignments.
88+
89+
+ Revisit [Get token](#get-token). You must sign in to the subscription that contains your search service.
90+
91+
+ Make sure your endpoint and token variables don't have surrounding quotes or extra spaces.
92+
93+
+ Make sure your token doesn't have the `@` symbol in the request header. For example, if the variable is `@token`, the reference in the request should be `{{token}}`.
94+
95+
+ If all else fails, restart your device to remove cached tokens and then repeat the steps in this quickstart, starting with [Get token](#get-token).
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
manager: nitinme
3+
author: haileytap
4+
ms.author: haileytapia
5+
ms.service: azure-ai-search
6+
ms.topic: include
7+
ms.date: 07/08/2025
8+
---
9+
10+
## Configure role-based access
11+
12+
In this section, you enable RBAC on your Azure AI Search service and assign the necessary roles for creating, loading, and querying search objects. For more information about these steps, see [Connect to Azure AI Search using roles](../../search-security-rbac.md).
13+
14+
To configure access:
15+
16+
1. Sign in to the [Azure portal](https://portal.azure.com) and select your search service.
17+
18+
1. From the left pane, select **Settings > Keys**.
19+
20+
1. Select **Role-based access control** or **Both** if you need time to transition clients to RBAC.
21+
22+
:::image type="content" source="../../media/search-get-started-rbac/access-control-options.png" lightbox="../../media/search-get-started-rbac/access-control-options.png" alt-text="Screenshot of the access control options in the Azure portal.":::
23+
24+
1. From the left pane, select **Access control (IAM)**.
25+
26+
1. Select **Add** > **Add role assignment**.
27+
28+
:::image type="content" source="../../media/search-get-started-rbac/add-role-assignment.png" lightbox="../../media/search-get-started-rbac/add-role-assignment.png" alt-text="Screenshot of the dropdown menu for adding a role assignment in the Azure portal.":::
29+
30+
1. Assign the **Search Service Contributor** role to your user account or managed identity.
31+
32+
1. Repeat the role assignment for **Search Index Data Contributor**.
33+
34+
## Get service information
35+
36+
In this section, you retrieve the subscription ID and endpoint of your Azure AI Search service. If you only have one subscription, skip the subscription ID and only retrieve the endpoint. You use these values in the remaining sections of this quickstart.
37+
38+
To get your service information:
39+
40+
1. Sign in to the [Azure portal](https://portal.azure.com) and select your search service.
41+
42+
1. From the left pane, select **Overview**.
43+
44+
1. Make a note of the subscription ID and endpoint.
45+
46+
:::image type="content" source="../../media/search-get-started-rbac/subscription-and-endpoint.png" lightbox="../../media/search-get-started-rbac/subscription-and-endpoint.png" alt-text="Screenshot of the subscription ID and endpoint in the Azure portal.":::
123 KB
Loading
147 KB
Loading
156 KB
Loading

0 commit comments

Comments
 (0)