Skip to content

Commit b1c5495

Browse files
authored
Update managed-identity-based-authentication.md
1 parent d4eb186 commit b1c5495

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: How to use a system-assigned managed identity to access Azure Cosmos DB data.
2+
title: How to use a system-assigned managed identity to access Azure Cosmos DB data
33
description: Learn how to configure an Azure AD system-assigned managed identity to access keys from Azure Cosmos DB. msi, managed service identity, aad, azure active directory, identity
44
author: j-patrick
55
ms.service: cosmos-db
@@ -10,7 +10,7 @@ ms.reviewer: sngun
1010

1111
---
1212

13-
# How to use a system-assigned managed identity to access Azure Cosmos DB data.
13+
# How to use a system-assigned managed identity to access Azure Cosmos DB data
1414

1515
In this article you will set up a **robust, key rotation agnostic,** solution to access Azure Cosmos DB keys by leveraging [managed identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md). The example in this article uses an Azure Function. However, you can achieve this solution by using any service that supports managed identities.
1616

@@ -25,16 +25,18 @@ In this step, you'll assign a system-assigned managed identity to your Azure Fun
2525
1. In the [Azure portal](https://portal.azure.com/), open the **Azure Function** pane and navigate to your function app.
2626

2727
1. Open the **Platform features** > **Identity** tab:
28-
![Identity Tab](./media/managed-identity-based-authentication/identity-tab-selection.png)
28+
29+
![Identity Tab](./media/managed-identity-based-authentication/identity-tab-selection.png)
2930

3031
1. On the **Identity** tab, turn **On** the **System Identity** status. Be sure to select **Save**, and confirm that you want to turn on the system identity. At the end the **System Identity** pane should look as follows:
31-
![System Identity turned on](./media/managed-identity-based-authentication/identity-tab-system-managed-on.png)
3232

33-
## Grant the managed identity access to your Azure Cosmos account
33+
![System Identity turned on](./media/managed-identity-based-authentication/identity-tab-system-managed-on.png)
34+
35+
## Grant the managed identity access to your Azure Cosmos DB account
3436

3537
In this step, you'll assign a role to the Azure Function's system-assigned managed identity. Azure Cosmos DB has multiple built-in roles that you can assign to the managed identity. For this solution, you will use the following two roles:
3638

37-
|**Built-in role** |**Description** |
39+
|Built-in role |Description |
3840
|---------|---------|
3941
|[DocumentDB Account Contributor](../role-based-access-control/built-in-roles.md#documentdb-account-contributor)|Can manage Azure Cosmos DB accounts. Allows retrieval of read/write keys. |
4042
|[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. |
@@ -47,33 +49,35 @@ In this step, you'll assign a role to the Azure Function's system-assigned manag
4749
4850
For your scenario, you will read the temperature, then write back that data to a container in Azure Cosmos DB. Because you have to write the data, you will use the **DocumentDB Account Contributor** role.
4951

50-
1. Sign in to the Azure portal and navigate to your Azure Cosmos account. Open the **Access Management (IAM) Pane**, and then the **Role Assignments** tab:
51-
![IAM Pane](./media/managed-identity-based-authentication/cosmos-db-iam-tab.png)
52+
1. Sign in to the Azure portal and navigate to your Azure Cosmos DB account. Open the **Access Management (IAM) Pane**, and then the **Role Assignments** tab:
53+
54+
![IAM Pane](./media/managed-identity-based-authentication/cosmos-db-iam-tab.png)
5255

5356
1. Select the **+ Add** button, then **add role assignment**.
5457

5558
1. The **Add Role Assignment** panel opens to the right:
5659

57-
![Add Role](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane.png)
60+
![Add Role](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane.png)
5861

59-
* **Role** - Select **DocumentDB Account Contributor**
60-
* **Assign access to** - Under the Select **System-assigned managed identity** subsection, select **Function App**.
61-
* **Select** - The pane will be populated with all the function apps, in your subscription, that have a **Managed System Identity**. In our 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 our case I select the **SummaryService** function app:
6265

63-
![Select Assignment](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane-filled.png)
66+
![Select Assignment](./media/managed-identity-based-authentication/cosmos-db-iam-tab-add-role-pane-filled.png)
6467

6568
1. After the function app's identity is selected click **Save**.
6669

6770
## Programmatically access the Azure Cosmos DB keys from the Azure Function
6871

6972
Now we have a function app that has a system-assigned managed identity. That identity is given 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, then save this to Cosmos DB.
7073

71-
This sample uses the [List Keys API](https://docs.microsoft.com/rest/api/cosmos-db-resource-provider/DatabaseAccounts/ListKeys) to access your Azure Cosmos account keys.
74+
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.
7275

7376
> [!IMPORTANT]
7477
> If you want to [assign the **Cosmos DB Account Reader**](#grant-the-managed-identity-access-to-your-azure-cosmos-account) role, you will need to use the read only [List Keys api](https://docs.microsoft.com/rest/api/cosmos-db-resource-provider/DatabaseAccounts/ListReadOnlyKeys). This will only populate the read only keys.
7578
7679
The List Keys API returns the `DatabaseAccountListKeysResult` object. This type isn't defined in the C# libraries. The following code shows the implementation of this class:
80+
7781
```csharp
7882
namespace SummarizationService
7983
{
@@ -88,6 +92,7 @@ namespace SummarizationService
8892
```
8993

9094
The example also uses a simple document called "TemperatureRecord", which is defined as follows:
95+
9196
```csharp
9297
using System;
9398

@@ -185,7 +190,8 @@ namespace Monitor
185190
}
186191
}
187192
```
188-
You are now ready to [deploy your Azure Function.](../azure-functions/functions-create-first-function-vs-code.md)
193+
194+
You are now ready to [deploy your Azure Function](../azure-functions/functions-create-first-function-vs-code.md).
189195

190196
## Next steps
191197

0 commit comments

Comments
 (0)