Skip to content

Commit a678e24

Browse files
committed
Keyless auth quickstart
1 parent 8241956 commit a678e24

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
title: Quickstart RBAC
3+
titleSuffix: Azure AI Search
4+
description: In this quickstart, learn how to switch from API keys to Microsoft Entra identities and role-based access control (RBAC).
5+
author: HeidiSteen
6+
ms.author: heidist
7+
ms.service: azure-ai-search
8+
9+
ms.topic: quickstart
10+
ms.date: 11/26/2024
11+
---
12+
13+
# Quickstart: Connect to Azure AI Search using role-based access control (RBAC)
14+
15+
Here are the comprehensive instructions for configuring Azure AI Search to use Microsoft Entra ID authentication and roles, including steps for connecting from your local system, running Jupyter notebooks, or using a REST client.
16+
17+
If you followed other quickstarts that connect using key-based authentication, these steps to switch to identity-based authentication and avoid hard-coded API keys in your example code.
18+
19+
## Prerequisites
20+
21+
- An Azure subscription. [Create one for free](https://azure.microsoft.com/free/).
22+
23+
- [Azure AI Search](search-create-service-portal.md), any region or tier, but it needs to be Basic or higher to configure a system-assigned managed identity for Azure AI Search.
24+
25+
- A command line tool, such as the [Azure CLI](/cli/azure/install-azure-cli).
26+
27+
## Step 1: Set Up Your Azure Subscription and Tenant
28+
29+
Follow these steps if you have more than one Azure subscription or tenant. The active subscription and tenant must be valid for your search service.
30+
31+
1. Get the Azure subscription and tenant for your search service:
32+
33+
1. Sign into the Azure portal and navigate to your search service.
34+
35+
1. Notice the subscription name and ID in **Overview** > **Essentials**.
36+
37+
1. Select the subscription name to view the parent management group (tenant ID).
38+
39+
1. Identify the active Azure subscription and tenant on your local device:
40+
41+
`az account show`
42+
43+
1. Set your Azure subscription to the subscription and tenant:
44+
45+
`az account set --subscription <your-subscription-id>`
46+
47+
`az login --tenant <your-tenant-id>`
48+
49+
1. Check your tenant ID:
50+
51+
`az account show --query tenantId --output tsv`
52+
53+
## Step 2: Configure Azure AI Search for Microsoft Entra ID Authentication
54+
55+
1. Sign in to the Azure portal and navigate to your Azure AI Search service.
56+
57+
1. Enable role-based access control (RBAC):
58+
59+
1. Go to **Settings** > **Keys**.
60+
61+
1. Choose **Role-based control** or **Both** if you need time to transition clients to role-based access control1.
62+
63+
1. Assign roles in the Azure portal:
64+
65+
1. Navigate to your search service.
66+
67+
1. Select **Access Control (IAM)** in the left navigation pane.
68+
69+
1. Select **+ Add** > **Add role assignment**.
70+
71+
1. Choose a role (e.g., Search Service Contributor, Search Index Data Contributor, Search Index Data Reader) and assign it to the appropriate Microsoft Entra user or group identity2. These three roles provide comprehensive permissions for creating, loading, and querying objects on Azure AI Search.
72+
73+
## Step 3: Connect from Your Local System
74+
75+
### Using Python Notebooks
76+
77+
1. Install the Azure Identity and Azure Search libraries:
78+
79+
```python
80+
pip install azure-identity azure-search-documents
81+
```
82+
83+
1. Authenticate and connect to Azure AI Search:
84+
85+
```python
86+
from azure.identity import DefaultAzureCredential
87+
from azure.search.documents import SearchClient
88+
89+
service_endpoint = "https://<your-search-service-name>.search.windows.net"
90+
index_name = "<your-index-name>"
91+
92+
credential = DefaultAzureCredential()
93+
client = SearchClient(endpoint=service_endpoint, index_name=index_name, credential=credential)
94+
95+
results = client.search("search text")
96+
for result in results:
97+
print(result)
98+
```
99+
100+
### Using a REST Client
101+
102+
Several quickstarts and tutorials use a REST client, such as Visual Studio Code with the REST extension. Here's how you connect to Azure AI Search from Visual Studio Code.
103+
104+
1. Get a personal identity token:
105+
106+
`az account get-access-token --resource https://<your-search-service-name>.search.windows.net`
107+
108+
1. Extract the token from the output:
109+
110+
`TOKEN=$(az account get-access-token --resource https://<your-search-service-name>.search.windows.net --query accessToken --output tsv)`
111+
112+
1. Provide the token in a request header:
113+
114+
`az rest --method get --url "https://<your-search-service-name>.search.windows.net/indexes/<your-index-name>/docs?api-version=2021-04-30-Preview&search=*" --headers "Authorization=Bearer $TOKEN"`
115+
116+
1. Specify the authorization bearer token in a REST call:
117+
118+
```REST
119+
POST https://{{baseUrl}}/indexes/{{index-name}}/docs/search?api-version=2024-07-01 HTTP/1.1
120+
Content-type: application/json
121+
Authorization: Bearer {{token}}
122+
123+
{
124+
"queryType": "simple",
125+
"search": "motel",
126+
"filter": "",
127+
"select": "HotelName,Description,Category,Tags",
128+
"count": true
129+
}
130+
```
131+
132+
## Additional Configuration
133+
134+
Configure a managed identity for outbound connections:
135+
136+
- Assign a system-assigned or user-assigned managed identity to your search service.
137+
- Use role assignments to authorize access to other Azure resources.
138+
139+
Network access configuration:
140+
141+
- Set up inbound rules to accept or reject requests to Azure AI Search based on IP address.

articles/search/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ items:
5656
href: search-get-started-bicep.md
5757
- name: Terraform
5858
href: search-get-started-terraform.md
59+
- name: Keyless authentication
60+
href: search-get-started-rbac.md
5961
- name: Tutorials
6062
items:
6163
- name: Dev tutorials

0 commit comments

Comments
 (0)