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-security-api-keys.md
+47-23Lines changed: 47 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,17 @@ ms.service: cognitive-search
10
10
ms.custom:
11
11
- ignite-2023
12
12
ms.topic: how-to
13
-
ms.date: 02/15/2024
13
+
ms.date: 04/22/2024
14
14
---
15
15
16
16
# Connect to Azure AI Search using key authentication
17
17
18
18
Azure AI Search offers key-based authentication that you can use on connections to your search service. An API key is a unique string composed of 52 randomly generated numbers and letters. A request made to a search service endpoint is accepted if both the request and the API key are valid.
19
19
20
+
Key-based authentication is the default. You can disable it if you opt in for role-based authentication.
21
+
20
22
> [!NOTE]
21
-
> A quick note about how "key" terminology is used in Azure AI Search. An "API key", which is described in this article, refers to a GUID used for authenticating a request. A separate term, "document key", refers to a unique string in your indexed content that's used to uniquely identify documents in a search index.
23
+
> A quick note about *key* terminology. An *API key*is a GUID used for authentication. A separate term, *document key* is a unique string in your indexed content thatuniquely identifies documents in a search index.
22
24
23
25
## Types of API keys
24
26
@@ -35,25 +37,46 @@ Visually, there's no distinction between an admin key or query key. Both keys ar
35
37
36
38
## Use API keys on connections
37
39
38
-
API keys are used for data plane (content) requests, such as creating or accessing an index or any other request that's represented in the [Search REST APIs](/rest/api/searchservice/). Upon service creation, an API key is the only authentication mechanism for data plane operations, but you can replace or supplement key authentication with [Azure roles](search-security-rbac.md) if you can't use hard-coded keys in your code.
40
+
API keys are used for data plane (content) requests, such as creating or accessing an index or, any other request that's represented in the [Search REST APIs](/rest/api/searchservice/). Upon service creation, an API key is the only authentication mechanism for data plane operations, but you can replace or supplement key authentication with [Azure roles](search-security-rbac.md) if you can't use hard-coded keys in your code.
39
41
40
-
API keys are specified on client requests to a search service. Passing a valid API key on the request is considered proof that the request is from an authorized client. If you're creating, modifying, or deleting objects, you'll need an admin API key. Otherwise, query keys are typically distributed to client applications that issue queries.
42
+
Admin keys are used for creating, modifying, or deleting objects. Admin keys are also used to GET object definitions and system information.
41
43
42
-
You can specify API keys in a request header for REST API calls, or in code that calls the azure.search.documents client libraries in the Azure SDKs. If you're using the Azure portal to perform tasks, your role assignment determines the [level of access](#permissions-to-view-or-manage-api-keys).
44
+
Query keys are typically distributed to client applications that issue queries.
43
45
44
-
Best practices for using hard-coded keys in source files include:
46
+
### [**REST API**](#tab/rest-use)
45
47
46
-
+ Only use API keys if data disclosure isn't a risk (for example, when using sample data) and if you're operating behind a firewall. Exposure of API keys is a risk to both data and to unauthorized use of your search service.
48
+
**How API keys are used in REST calls**:
47
49
48
-
+ Always check code, samples, and training material before publishing to make sure you didn't leave valid API keys behind.
50
+
Set an admin key in the request header. You can't pass admin keys on the URI or in the body of the request. Admin keys are used for create-read-update-delete operation and on requests issued to the search service itself, such as [LIST Indexes](/rest/api/searchservice/indexes/list) or [GET Service Statistics](/rest/api/searchservice/get-service-statistics/get-service-statistics).
49
51
50
-
+ For production workloads, switch to [Microsoft Entra ID and role-based access](search-security-rbac.md). Or, if you want to continue using API keys, be sure to always monitor [who has access to your API keys](#secure-api-keys) and [regenerate API keys](#regenerate-admin-keys)on a regular cadence.
52
+
Here's an example of admin API key usage on a create index request:
51
53
52
-
### [**Portal**](#tab/portal-use)
54
+
```http
55
+
### Create an index
56
+
POST {{baseUrl}}/indexes?api-version=2023-11-01 HTTP/1.1
+ Key authentication is built in. By default, the portal tries API keys first. However, if you [disable API keys](search-security-rbac.md#disable-api-key-authentication) and set up role assignments, the portal uses role assignments instead.
69
+
Set a query key in a request header for POST, or on the URI for GET. Query keys are used for operations that target the `index/docs` collection: [Search Documents](/rest/api/searchservice/documents/search-get), [Autocomplete](/rest/api/searchservice/documents/autocomplete-get), [Suggest](/rest/api/searchservice/documents/suggest-get), or [GET Document](/rest/api/searchservice/documents/get).
70
+
71
+
Here's an example of query API key usage on a Search Documents (GET) request:
72
+
73
+
```http
74
+
### Query an index
75
+
GET /indexes/my-new-index/docs?search=*&api-version=2023-11-01&api-key={{queryApiKey}}
76
+
```
77
+
78
+
> [!NOTE]
79
+
> It's considered a poor security practice to pass sensitive data such as an `api-key` in the request URI. For this reason, Azure AI Search only accepts a query key as an `api-key` in the query string. As a general rule, we recommend passing your `api-key` as a request header.
57
80
58
81
### [**PowerShell**](#tab/azure-ps-use)
59
82
@@ -70,18 +93,11 @@ $headers = @{
70
93
71
94
A script example showing API key usage for various operations can be found at [Quickstart: Create an Azure AI Search index in PowerShell using REST APIs](search-get-started-powershell.md).
72
95
73
-
### [**REST API**](#tab/rest-use)
74
-
75
-
**How API keys are used in REST calls**:
76
-
77
-
Set an admin key in the request header. You can't pass admin keys on the URI or in the body of the request.
78
-
79
-
Admin keys are used for create-read-update-delete operation and on requests issued to the search service itself, such as listing objects or requesting service statistics.
96
+
### [**Portal**](#tab/portal-use)
80
97
81
-
Query keys are used for search, suggestion, or lookup operations that target the `index/docs` collection. For POST, set `api-key`in the request header. Or, put the key on the URI for a GET: `GET /indexes/hotels/docs?search=*&$orderby=lastRenovationDate desc&api-version=2020-06-30&api-key=[query key]`
98
+
**How API keys are used in the Azure portal**:
82
99
83
-
> [!NOTE]
84
-
> It's considered a poor security practice to pass sensitive data such as an `api-key` in the request URI. For this reason, Azure AI Search only accepts a query key as an `api-key` in the query string. As a general rule, we recommend passing your `api-key` as a request header.
100
+
+ Key authentication is built in. By default, the portal tries API keys first. However, if you [disable API keys](search-security-rbac.md#disable-api-key-authentication) and set up role assignments, the portal uses role assignments instead.
85
101
86
102
---
87
103
@@ -214,7 +230,7 @@ After you create new keys via portal or management layer, access is restored to
214
230
215
231
Use role assignments to restrict access to API keys.
216
232
217
-
Note that it's not possible to use [customer-managed key encryption](search-security-manage-encryption-keys.md) to encrypt API keys. Only sensitive data within the search service itself (for example, index content or connection strings in data source object definitions) can be CMK-encrypted.
233
+
It's not possible to use [customer-managed key encryption](search-security-manage-encryption-keys.md) to encrypt API keys. Only sensitive data within the search service itself (for example, index content or connection strings in data source object definitions) can be CMK-encrypted.
218
234
219
235
1. Navigate to your search service page in Azure portal.
220
236
@@ -224,6 +240,14 @@ Note that it's not possible to use [customer-managed key encryption](search-secu
224
240
225
241
1. As a precaution, also check the **Classic administrators** tab to determine whether administrators and co-administrators have access.
226
242
243
+
## Best practices
244
+
245
+
+ Only use API keys if data disclosure isn't a risk (for example, when using sample data) and if you're operating behind a firewall. Exposure of API keys is a risk to both data and to unauthorized use of your search service.
246
+
247
+
+ Always check code, samples, and training material before publishing to make sure you didn't leave valid API keys behind.
248
+
249
+
+ For production workloads, switch to [Microsoft Entra ID and role-based access](search-security-rbac.md). Or, if you want to continue using API keys, be sure to always monitor [who has access to your API keys](#secure-api-keys) and [regenerate API keys](#regenerate-admin-keys) on a regular cadence.
250
+
227
251
## See also
228
252
229
253
+[Security in Azure AI Search](search-security-overview.md)
0 commit comments