Skip to content

Commit eccdb5c

Browse files
Merge pull request #272921 from HeidiSteen/heidist-vectors
[azure search] clarified API key usage
2 parents 5b797e8 + e89657e commit eccdb5c

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

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

Lines changed: 47 additions & 23 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* is a GUID used for authentication. A separate term, *document key* is 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,46 @@ 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.
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.
3941

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.
4143

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.
4345

44-
Best practices for using hard-coded keys in source files include:
46+
### [**REST API**](#tab/rest-use)
4547

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**:
4749

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).
4951

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:
5153

52-
### [**Portal**](#tab/portal-use)
54+
```http
55+
### Create an index
56+
POST {{baseUrl}}/indexes?api-version=2023-11-01 HTTP/1.1
57+
Content-Type: application/json
58+
api-key: {{adminApiKey}}
5359
54-
**How API keys are used in the Azure portal**:
60+
{
61+
"name": "my-new-index",
62+
"fields": [
63+
{"name": "docId", "type": "Edm.String", "key": true, "filterable": true},
64+
{"name": "Name", "type": "Edm.String", "searchable": true }
65+
]
66+
}
67+
```
5568

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.
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.
5780
5881
### [**PowerShell**](#tab/azure-ps-use)
5982

@@ -70,18 +93,11 @@ $headers = @{
7093

7194
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).
7295

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)
8097

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**:
8299

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.
85101

86102
---
87103

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

215231
Use role assignments to restrict access to API keys.
216232

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.
218234

219235
1. Navigate to your search service page in Azure portal.
220236

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

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

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+
227251
## See also
228252

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

0 commit comments

Comments
 (0)