Skip to content

Commit 7aa88f2

Browse files
committed
Moved a couple sections, added some task-tabs for better language parity
1 parent ede0bcb commit 7aa88f2

File tree

1 file changed

+57
-31
lines changed

1 file changed

+57
-31
lines changed

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

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,48 +39,79 @@ API keys are specified on client requests to a search service. Passing a valid A
3939

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

42-
Best practices for using hard-coded in source files include:
42+
Best practices for using hard-coded keys in source files include:
4343

4444
+ During early development and proof-of-concept testing when security is looser, use sample or public data.
4545

46-
+ After advancing into deeper development or production scenarios, switch to [Azure Active Directory and role-based access](search-security-rbac.md) to eliminate the need for having hard-coded keys. Or, if you want to continue using API keys, be sure to always monitor who has access to your API keys and regenerate API keys on a regular cadence.
46+
+ For mature solutions or production scenarios, switch to [Azure Active Directory and role-based access](search-security-rbac.md) to eliminate the need for having hard-coded keys. Or, if you want to continue using API keys, be sure to always monitor [who has access to your API keys](#secure-api-key-access) and [regenerate API keys](#regenerate-admin-keys) on a regular cadence.
4747

48-
### [**REST**](#tab/rest-use)
48+
### [**Portal**](#tab/portal-use)
49+
50+
In Cognitive Search, most tasks can be performed in Azure portal, including object creation, indexing through the Import data wizard, and queries through Search explorer.
51+
52+
No action is required. By default, the portal uses API keys to authenticate the request automatically. 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.
53+
54+
### [**PowerShell**](#tab/azure-ps-use)
55+
56+
A script example showing API key usage can be found at [Quickstart: Create an Azure Cognitive Search index in PowerShell using REST APIs](search-get-started-powershell.md).
57+
58+
### [**REST API**](#tab/rest-use)
4959

5060
+ Admin keys are only specified in HTTP request headers. You can't place an admin API key in a URL. See [Connect to Azure Cognitive Search using REST APIs](search-get-started-rest.md#connect-to-azure-cognitive-search) for an example that specifies an admin API key on a REST call.
5161

5262
+ Query keys are also specified in an HTTP request header for search, suggestion, or lookup operation that use POST.
5363

5464
Alternatively, you can pass a query key as a parameter on a URL if you're using GET: `GET /indexes/hotels/docs?search=*&$orderby=lastRenovationDate desc&api-version=2020-06-30&api-key=[query key]`
5565

56-
### [**Azure PowerShell**](#tab/azure-ps-use)
57-
58-
A script example showing API key usage can be found at [Quickstart: Create an Azure Cognitive Search index in PowerShell using REST APIs](search-get-started-powershell.md).
59-
60-
### [**.NET**](#tab/dotnet-use)
66+
### [**C#**](#tab/dotnet-use)
6167

6268
In search solutions, a key is often specified as a configuration setting and then passed as an [AzureKeyCredential](/dotnet/api/azure.azurekeycredential). See [How to use Azure.Search.Documents in a C# .NET Application](search-howto-dotnet-sdk.md) for an example.
6369

6470
---
6571

6672
> [!NOTE]
67-
> It's considered a poor security practice to pass sensitive data such as an `api-key` in the request URI. For this reason, Azure Cognitive 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.
73+
> It's considered a poor security practice to pass sensitive data such as an `api-key` in the request URI. For this reason, Azure Cognitive 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.
74+
75+
## Permissions to view or manage API keys
76+
77+
Permissions for viewing and managing API keys is conveyed through [role assignments](search-security-rbac.md). Members of the following roles can view and regenerate keys:
78+
79+
+ Owner
80+
+ Contributor
81+
+ [Search Service Contributor](../role-based-access-control/built-in-roles.md#search-service-contributor)
82+
+ Administrator and co-administrator (classic)
83+
84+
The following roles don't have access to API keys:
85+
86+
+ Reader
87+
+ Search Index Data Contributor
88+
+ Search Index Data Reader
6889

6990
## Find existing keys
7091

7192
You can view and manage API keys in the [Azure portal](https://portal.azure.com), or through [PowerShell](/powershell/module/az.search), [Azure CLI](/cli/azure/search), or [REST API](/rest/api/searchmanagement/).
7293

73-
### [**Azure portal**](#tab/portal-find)
94+
### [**Portal**](#tab/portal-find)
7495

7596
1. Sign in to the [Azure portal](https://portal.azure.com) and [find your search service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices).
7697

7798
1. Under **Settings**, select **Keys** to view admin and query keys.
7899

79100
:::image type="content" source="media/search-manage/azure-search-view-keys.png" alt-text="Screenshot of a portal page showing API keys." border="true":::
80101

81-
### [**REST**](#tab/rest-find)
102+
### [**Azure CLI**](#tab/azure-cli-find)
103+
104+
Use the following commands to return admin and query API keys, respectively:
82105

83-
Use [ListAdminKeys](/rest/api/searchmanagement/2020-08-01/admin-keys) or [ListQueryKeys](/rest/api/searchmanagement/2020-08-01/query-keys/list-by-search-service) in the Management REST API to return API keys.
106+
```azurecli
107+
az search admin-key show --resource-group <myresourcegroup> --service-name <myservice>
108+
109+
az search query-key list --resource-group <myresourcegroup> --service-name <myservice>
110+
```
111+
112+
### [**REST API**](#tab/rest-find)
113+
114+
Use [List Admin Keys](/rest/api/searchmanagement/2020-08-01/admin-keys) or [List Query Keys](/rest/api/searchmanagement/2020-08-01/query-keys/list-by-search-service) in the Management REST API to return API keys.
84115

85116
You must have a [valid role assignment](#permissions-to-view-or-manage-api-keys) to return or update API keys. See [Manage your Azure Cognitive Search service with REST APIs](search-manage-rest.md) for guidance on meeting role requirements using the REST APIs.
86117

@@ -96,7 +127,7 @@ Query keys are used for read-only access to documents within an index for operat
96127

97128
Restricting access and operations in client apps is essential to safeguarding the search assets on your service. Always use a query key rather than an admin key for any query originating from a client app.
98129

99-
### [**Azure portal**](#tab/portal-query)
130+
### [**Portal**](#tab/portal-query)
100131

101132
1. Sign in to the [Azure portal](https://portal.azure.com) and [find your search service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices).
102133

@@ -106,13 +137,23 @@ Restricting access and operations in client apps is essential to safeguarding th
106137

107138
:::image type="content" source="media/search-security-overview/create-query-key.png" alt-text="Screenshot of the query key management options." border="true":::
108139

140+
### [**PowerShell**](#tab/azure-ps-query)
141+
142+
A script example showing API key usage can be found at [Create or delete query keys]](search-manage-powershell.md#create-or-delete-query-keys).
143+
109144
### [**Azure CLI**](#tab/azure-cli-query)
110145

111146
A script example showing query key usage can be found at [Create or delete query keys](search-manage-azure-cli.md#create-or-delete-query-keys).
112147

113-
### [**.NET**](#tab/dotnet-query)
148+
### [**REST API**](#tab/rest-query)
114149

115-
A code example showing query key usage can be found in [DotNetHowTo](https://github.com/Azure-Samples/search-dotnet-getting-started/tree/master/DotNetHowTo).
150+
Use [Create Query Keys](/rest/api/searchmanagement/2020-08-01/query-keys/create) in the Management REST API.
151+
152+
You must have a [valid role assignment](#permissions-to-view-or-manage-api-keys) to create or manage API keys. See [Manage your Azure Cognitive Search service with REST APIs](search-manage-rest.md) for guidance on meeting role requirements using the REST APIs.
153+
154+
```rest
155+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/createQueryKey/{name}?api-version=2020-08-01
156+
```
116157

117158
---
118159

@@ -122,7 +163,7 @@ A code example showing query key usage can be found in [DotNetHowTo](https://git
122163

123164
Two admin keys are created for each service so that you can rotate a primary key while using the secondary key for business continuity.
124165

125-
1. In the **Settings** > **Keys** page, copy the secondary key.
166+
1. Under **Settings**, select **Keys**, then copy the secondary key.
126167

127168
1. For all applications, update the API key settings to use the secondary key.
128169

@@ -136,21 +177,6 @@ You can still access the service through the portal or programmatically. Managem
136177

137178
After you create new keys via portal or management layer, access is restored to your content (indexes, indexers, data sources, synonym maps) once you provide those keys on requests.
138179

139-
## Permissions to view or manage API keys
140-
141-
Permissions for viewing and managing API keys is conveyed through [role assignments](search-security-rbac.md). Members of the following roles can view and regenerate keys:
142-
143-
+ Administrator and co-administrator (classic)
144-
+ Owner
145-
+ Contributor
146-
+ [Search Service Contributors](../role-based-access-control/built-in-roles.md#search-service-contributor)
147-
148-
The following roles don't have access to API keys:
149-
150-
+ Reader
151-
+ Search Index Data Contributor
152-
+ Search Index Data Reader
153-
154180
## Secure API key access
155181

156182
Use role assignments to restrict access to API keys.

0 commit comments

Comments
 (0)