Skip to content

Commit 48d8f00

Browse files
Merge pull request #1729 from HeidiSteen/heidist-uuf
[azure search] Keyless auth quickstart
2 parents 57f4901 + 18e820e commit 48d8f00

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

articles/search/keyless-connections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Use keyless connections with Azure AI Search
2+
title: Use keyless connections in search apps
33
description: Use keyless connections with an Azure Identity library for Microsoft Entra ID authentication and authorization with Azure AI Search.
44
ms.topic: how-to
55
ms.date: 10/30/2024
@@ -9,7 +9,7 @@ ms.custom: devx-track-dotnet, devx-track-extended-java, devx-track-js, devx-trac
99
#customer intent: As a developer, I want to use keyless connections so that I don't leak secrets.
1010
---
1111

12-
# Use Azure AI Search without keys
12+
# Connect your app to Azure AI Search using identities
1313

1414
In your application code, you can set up a keyless connection to Azure AI Search that uses Microsoft Entra ID and roles for authentication and authorization. Application requests to most Azure services must be authenticated with keys or keyless connections. Developers must be diligent to never expose the keys in an unsecure location. Anyone who gains access to the key is able to authenticate to the service. Keyless authentication offers improved management and security benefits over the account key because there's no key (or connection string) to store.
1515

126 KB
Loading
32.9 KB
Loading
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title: Quickstart keyless connection
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 without keys
14+
15+
Configure Azure AI Search to use Microsoft Entra ID authentication and roles. Connect from your local system, running Jupyter notebooks, or using a REST client.
16+
17+
If you stepped through other quickstarts that connect using API keys, this quickstart shows you how to switch to identity-based authentication so that you can 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 you need 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+
This step is necessary if you have more than one subscription or tenant.
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+
:::image type="content" source="media/search-get-started-rbac/select-subscription-name.png" lightbox="media/search-get-started-rbac/select-subscription-name.png" alt-text="Screenshot of the portal page providing the subscription name":::
40+
41+
1. Identify the active Azure subscription and tenant on your local device:
42+
43+
`az account show`
44+
45+
1. Set your Azure subscription to the subscription and tenant:
46+
47+
`az account set --subscription <your-subscription-id>`
48+
49+
`az login --tenant <your-tenant-id>`
50+
51+
1. Check your tenant ID:
52+
53+
`az account show --query tenantId --output tsv`
54+
55+
## Step 2: Configure Azure AI Search for Microsoft Entra ID authentication
56+
57+
1. Sign in to the Azure portal and navigate to your Azure AI Search service.
58+
59+
1. Enable role-based access control (RBAC):
60+
61+
1. Go to **Settings** > **Keys**.
62+
63+
1. Choose **Role-based control** or **Both** if you need time to transition clients to role-based access control1.
64+
65+
1. Assign roles in the Azure portal:
66+
67+
1. Navigate to your search service.
68+
69+
1. Select **Access Control (IAM)** in the left navigation pane.
70+
71+
1. Select **+ Add** > **Add role assignment**.
72+
73+
1. Choose a role (Search Service Contributor, Search Index Data Contributor, Search Index Data Reader) and assign it to your Microsoft Entra user or group identity. These three roles provide the full set of permissions for creating, loading, and querying objects on Azure AI Search. For more information, see [Connect using roles](search-security-rbac.md).
74+
75+
## Step 3: Connect from your local system
76+
77+
### Using Python and Jupyter notebooks
78+
79+
1. Install the Azure Identity and Azure Search libraries:
80+
81+
```python
82+
pip install azure-identity azure-search-documents
83+
```
84+
85+
1. Authenticate and connect to Azure AI Search:
86+
87+
```python
88+
from azure.identity import DefaultAzureCredential
89+
from azure.search.documents import SearchClient
90+
91+
service_endpoint = "https://<your-search-service-name>.search.windows.net"
92+
index_name = "<your-index-name>"
93+
94+
credential = DefaultAzureCredential()
95+
client = SearchClient(endpoint=service_endpoint, index_name=index_name, credential=credential)
96+
97+
results = client.search("search text")
98+
for result in results:
99+
print(result)
100+
```
101+
102+
### Using a REST client
103+
104+
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.
105+
106+
1. Get a personal identity token:
107+
108+
`az account get-access-token --resource https://<your-search-service-name>.search.windows.net`
109+
110+
1. Extract the token from the output:
111+
112+
`TOKEN=$(az account get-access-token --resource https://<your-search-service-name>.search.windows.net --query accessToken --output tsv)`
113+
114+
1. Provide the token in a request header:
115+
116+
`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"`
117+
118+
1. Specify the authorization bearer token in a REST call:
119+
120+
```REST
121+
POST https://{{baseUrl}}/indexes/{{index-name}}/docs/search?api-version=2024-07-01 HTTP/1.1
122+
Content-type: application/json
123+
Authorization: Bearer {{token}}
124+
125+
{
126+
"queryType": "simple",
127+
"search": "motel",
128+
"filter": "",
129+
"select": "HotelName,Description,Category,Tags",
130+
"count": true
131+
}
132+
```
133+
134+
## Additional configuration
135+
136+
Configure a managed identity for outbound connections:
137+
138+
- [Configure a system-assigned or user-assigned managed identity](search-howto-managed-identities-data-sources.md) for your search service.
139+
- [Use role assignments](keyless-connections.md) to authorize access to other Azure resources.
140+
141+
Network access configuration:
142+
143+
- [Set inbound rules](service-configure-firewall.md) 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
@@ -26,6 +26,8 @@ items:
2626
href: search-get-started-semantic.md
2727
- name: Chat with your data
2828
href: /azure/ai-services/openai/use-your-data-quickstart?context=/azure/search/context/context
29+
- name: Keyless authentication
30+
href: search-get-started-rbac.md
2931
- name: Portal
3032
items:
3133
- name: Keyword search wizard

0 commit comments

Comments
 (0)