Skip to content

Commit 21dfbd7

Browse files
authored
Update edit
1 parent 35cdd03 commit 21dfbd7

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

articles/cosmos-db/managed-identity-based-authentication.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ ms.reviewer: sngun
1010

1111
---
1212

13-
# Use managed identities to access Azure Cosmos DB data
13+
# Use system-assigned managed identities to access Azure Cosmos DB data
1414

15-
In this article you'll set up a **robust, key rotation agnostic** solution to access Azure Cosmos DB keys using [managed identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md). The example in this article uses Azure Functions, but you can use any service that supports managed identities.
15+
In this article, you'll set up a *robust, key rotation agnostic* solution to access Azure Cosmos DB keys by using [managed identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md). The example in this article uses Azure Functions, but you can use any service that supports managed identities.
1616

17-
You'll learn how to create a function app that can access Azure Cosmos DB data without needing to copy any Azure Cosmos DB keys. The function app will wake up every minute and record the current temperature of an aquarium fish tank. To learn how to set up a timer-triggered function app see the [Create a function in Azure that is triggered by a timer](../azure-functions/functions-create-scheduled-function.md) article.
17+
You'll learn how to create a function app that can access Azure Cosmos DB data without needing to copy any Azure Cosmos DB keys. The function app will wake up every minute and record the current temperature of an aquarium fish tank. To learn how to set up a timer-triggered function app, see the [Create a function in Azure that is triggered by a timer](../azure-functions/functions-create-scheduled-function.md) article.
1818

19-
To simplify the scenario, clean-up of older temperature documents is handled by a [Time To Live](./time-to-live.md) setting already configured.
19+
To simplify the scenario, a [Time To Live](./time-to-live.md) setting is already configured to clean-up older temperature documents.
2020

2121
## Assign a managed identity to a function app
2222

2323
In this step, you'll assign a system-assigned managed identity to your function app.
2424

25-
1. In the [Azure portal](https://portal.azure.com/), open the **Azure Function** pane and navigate to your function app.
25+
1. In the [Azure portal](https://portal.azure.com/), open the **Azure Function** pane and go to your function app.
2626

2727
1. Open the **Platform features** > **Identity** tab:
2828

29-
![Identity Tab](./media/managed-identity-based-authentication/identity-tab-selection.png)
29+
![Screenshot showing Platform features and Identity options for the function app.](./media/managed-identity-based-authentication/identity-tab-selection.png)
3030

3131
1. On the **Identity** tab, turn **On** the system identity **Status** and select **Save**. The **Identity** pane should look as follows:
3232

33-
![System Identity turned on](./media/managed-identity-based-authentication/identity-tab-system-managed-on.png)
33+
![Screenshot showing system identity Status set to On.](./media/managed-identity-based-authentication/identity-tab-system-managed-on.png)
3434

3535
## Grant access to your Azure Cosmos account
3636

@@ -42,34 +42,34 @@ In this step, you'll assign a role to the function app's system-assigned managed
4242
|[Cosmos DB Account Reader](../role-based-access-control/built-in-roles.md#cosmos-db-account-reader-role)|Can read Azure Cosmos DB account data. Allows retrieval of read keys. |
4343

4444
> [!IMPORTANT]
45-
> Role-based access control support in Azure Cosmos DB applies to control plane operations only. Data plane operations are secured using master keys or resource tokens. To learn more, see the [Secure access to data](secure-access-to-data.md) article.
45+
> Support for role-based access control in Azure Cosmos DB applies to control plane operations only. Data plane operations are secured through master keys or resource tokens. To learn more, see the [Secure access to data](secure-access-to-data.md) article.
4646
4747
> [!TIP]
48-
> When you assign roles, assign only the access needed. If your service need only read data, then assign the **Cosmos DB Account Reader** role to the managed identity. For more information about the importance of least privilege access, see the [Lower exposure of privileged accounts](../security/fundamentals/identity-management-best-practices.md#lower-exposure-of-privileged-accounts) article.
48+
> When you assign roles, assign only the needed access. If your service requires only reading data, then assign the **Cosmos DB Account Reader** role to the managed identity. For more information about the importance of least privilege access, see the [Lower exposure of privileged accounts](../security/fundamentals/identity-management-best-practices.md#lower-exposure-of-privileged-accounts) article.
4949
5050
In this scenario, the function app will read the temperature of the aquarium, then write back that data to a container in Azure Cosmos DB. Because the function app must write the data, you'll need to assign the **DocumentDB Account Contributor** role.
5151

52-
1. Sign in to the Azure portal and navigate to your Azure Cosmos DB account. Open the **Access control (IAM)** pane, and then the **Role assignments** tab:
52+
1. Sign in to the Azure portal and go to your Azure Cosmos DB account. Open the **Access control (IAM)** pane, and then the **Role assignments** tab:
5353

54-
![IAM Pane](./media/managed-identity-based-authentication/cosmos-db-iam-tab.png)
54+
![Screenshot showing the Access control pane and the Role assignments tab.](./media/managed-identity-based-authentication/cosmos-db-iam-tab.png)
5555

5656
1. Select the **+ Add** button, then **Add role assignment**.
5757

5858
1. The **Add role assignment** panel opens to the right:
5959

60-
![Add Role](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane.png)
60+
![Screenshot showing the Add role assignment pane.](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane.png)
6161

62-
* **Role** - Select **DocumentDB Account Contributor**
63-
* **Assign access to** - Under the **Select system-assigned managed identity** subsection, select **Function App**.
64-
* **Select** - The pane will be populated with all the function apps in your subscription that have a **Managed System Identity**. In this case I select the **SummaryService** function app:
62+
* **Role**: Select **DocumentDB Account Contributor**
63+
* **Assign access to**: Under the **Select system-assigned managed identity** subsection, select **Function App**.
64+
* **Select**: The pane will be populated with all the function apps in your subscription that have a **Managed System Identity**. In this case select the **SummaryService** function app:
6565

66-
![Select Assignment](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane-filled.png)
66+
![Screenshot showing the Add role assignment pane populated with examples.](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane-filled.png)
6767

68-
1. After you have selected your function app, click **Save**.
68+
1. After you have selected your function app, select **Save**.
6969

70-
## Access the Azure Cosmos DB keys from the function app
70+
## Programmatically access the Azure Cosmos DB keys
7171

72-
Now we have a function app that has a system-assigned managed identity with the **DocumentDB Account Contributor** role in the Azure Cosmos DB permissions. The following function app code sample will get the Azure Cosmos DB keys, create a CosmosClient object, get the temperature of the aquarium, and then save this to Cosmos DB.
72+
Now we have a function app that has a system-assigned managed identity with the **DocumentDB Account Contributor** role in the Azure Cosmos DB permissions. The following function app code will get the Azure Cosmos DB keys, create a CosmosClient object, get the temperature of the aquarium, and then save this to Azure Cosmos DB.
7373

7474
This sample uses the [List Keys API](https://docs.microsoft.com/rest/api/cosmos-db-resource-provider/DatabaseAccounts/ListKeys) to access your Azure Cosmos DB account keys.
7575

@@ -91,7 +91,7 @@ namespace SummarizationService
9191
}
9292
```
9393

94-
The example also uses a simple document called "TemperatureRecord", which is defined as follows:
94+
The example also uses a simple document called "TemperatureRecord," which is defined as follows:
9595

9696
```csharp
9797
using System;
@@ -145,20 +145,20 @@ namespace Monitor
145145
// AzureServiceTokenProvider will help us to get the Service Managed token.
146146
var azureServiceTokenProvider = new AzureServiceTokenProvider();
147147

148-
// In order to get the Service Managed token we need to authenticate to the Azure Resource Manager.
148+
// Authenticate to the Azure Resource Manager to get the Service Managed token.
149149
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/");
150150

151-
// To get the Azure Cosmos DB keys setup the List Keys API:
151+
// Setup the List Keys API to get the Azure Cosmos DB keys.
152152
string endpoint = $"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/listKeys?api-version=2019-12-12";
153153

154-
// setup an HTTP Client and add the access token.
154+
// Setup an HTTP Client and add the access token.
155155
HttpClient httpClient = new HttpClient();
156156
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
157157

158158
// Post to the endpoint to get the keys result.
159159
var result = await httpClient.PostAsync(endpoint, new StringContent(""));
160160

161-
// Get the Result back as a DatabaseAccountListKeysResult.
161+
// Get the result back as a DatabaseAccountListKeysResult.
162162
DatabaseAccountListKeysResult keys = await result.Content.ReadAsAsync<DatabaseAccountListKeysResult>();
163163

164164
log.LogInformation("Starting to create the client");
@@ -183,7 +183,7 @@ namespace Monitor
183183

184184
private static int GetTemperature()
185185
{
186-
// fake the temperature sensor for this demo
186+
// Fake the temperature sensor for this demo.
187187
Random r = new Random(DateTime.UtcNow.Second);
188188
return r.Next(0, 120);
189189
}

0 commit comments

Comments
 (0)