Skip to content

Commit 024ecb6

Browse files
committed
clarified API key usage
1 parent 7cc15d7 commit 024ecb6

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

articles/search/search-security-api-keys.md

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ ms.service: cognitive-search
1010
ms.custom:
1111
- ignite-2023
1212
ms.topic: how-to
13-
ms.date: 02/15/2024
13+
ms.date: 04/22/2024
1414
---
1515

1616
# Connect to Azure AI Search using key authentication
1717

1818
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.
1919

20+
Key-based authentication is the default. You can disable it if you opt in for role-based authentication.
21+
2022
> [!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*, as 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 uniquely identifies documents in a search index.
2224
2325
## Types of API keys
2426

@@ -35,25 +37,41 @@ Visually, there's no distinction between an admin key or query key. Both keys ar
3537

3638
## Use API keys on connections
3739

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.
39-
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.
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.
4141

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).
42+
Admin keys are used for creating, modifying, or deleting objects. Admin keys are also used to GET object definitions and system information.
4343

44-
Best practices for using hard-coded keys in source files include:
44+
Query keys are typically distributed to client applications that issue queries.
4545

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.
46+
### [**REST API**](#tab/rest-use)
4747

48-
+ Always check code, samples, and training material before publishing to make sure you didn't leave valid API keys behind.
48+
**How API keys are used in REST calls**:
4949

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.
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 or GET Service Statistics.
51+
52+
```http
53+
### Create a new index
54+
POST {{baseUrl}}/indexes?api-version=2023-11-01 HTTP/1.1
55+
Content-Type: application/json
56+
api-key: {{apiKey}}
57+
58+
{
59+
"name": "my-new-index",
60+
"fields": [
61+
{"name": "docId", "type": "Edm.String", "key": true, "filterable": true},
62+
{"name": "Name", "type": "Edm.String", "searchable": true }
63+
]
64+
}
65+
```
5166

52-
### [**Portal**](#tab/portal-use)
67+
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).
5368

54-
**How API keys are used in the Azure portal**:
69+
```http
70+
GET /indexes/my-new-index/docs?search=*&api-version=2020-06-30&api-key={{apiKey}}
71+
```
5572

56-
+ 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.
73+
> [!NOTE]
74+
> 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.
5775
5876
### [**PowerShell**](#tab/azure-ps-use)
5977

@@ -70,18 +88,11 @@ $headers = @{
7088

7189
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).
7290

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.
91+
### [**Portal**](#tab/portal-use)
8092

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]`
93+
**How API keys are used in the Azure portal**:
8294

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.
95+
+ 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.
8596

8697
---
8798

@@ -214,7 +225,7 @@ After you create new keys via portal or management layer, access is restored to
214225

215226
Use role assignments to restrict access to API keys.
216227

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.
228+
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.
218229

219230
1. Navigate to your search service page in Azure portal.
220231

@@ -224,6 +235,14 @@ Note that it's not possible to use [customer-managed key encryption](search-secu
224235

225236
1. As a precaution, also check the **Classic administrators** tab to determine whether administrators and co-administrators have access.
226237

238+
## Best practices
239+
240+
+ 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.
241+
242+
+ Always check code, samples, and training material before publishing to make sure you didn't leave valid API keys behind.
243+
244+
+ 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.
245+
227246
## See also
228247

229248
+ [Security in Azure AI Search](search-security-overview.md)

0 commit comments

Comments
 (0)