You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/managed-identity-based-authentication.md
+18-20Lines changed: 18 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: System-Assigned Managed Identity based key access using Azure Active Directory
2
+
title: How to use system assigned managed identities (MSI) to access to Azure Cosmos DB data.
3
3
description: Learn how to configure an Azure AD system-assigned managed identity to access keys from Azure Cosmos DB.
4
4
author: j-patrick
5
5
ms.service: cosmos-db
@@ -10,17 +10,15 @@ ms.reviewer: sngun
10
10
11
11
---
12
12
13
-
# System-Assigned Managed Identity based key access using Azure Active Directory
13
+
# How to use system assigned managed identities (MSI) to access to Azure Cosmos DB data.
14
14
15
-
In this article we'll setup a **robust, key rotation agnostic,** solution for Cosmos DB key management by leveraging [Managed Service Identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md). Though we're using an Azure Function for this example, this solution can be used with any service that [supports managed service identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md).
15
+
In this article we'll setup a **robust, key rotation agnostic,** solution for Azure Cosmos DB key management by leveraging [Managed Service Identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md). Though we're using an Azure Function for this example, this solution can be used with any service that [supports managed service identities](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md).
16
16
17
17
You'll learn how to:
18
18
19
-
* Assign a System-Assigned Managed Identity
20
-
* Grant the System-Assigned Managed Identity access to your Cosmos DB
21
-
* Write the code for robust Cosmos DB key management
19
+
* Create an Azure Function that has robust access to data without copying any Azure Cosmos DB Key.
22
20
23
-
In the solution below, we'll be building an Azure Function that will handle summarizing the last hour of sales. The function will wake up every hour, and will read a set of sale receipts from Cosmos DB. Then the function will create an hourly summary of sales and store it back in the container. To simplify the scenario, cleanup of the already processed receipts will be handled by an already configured [TTL](./time-to-live.md) setting.
21
+
In the solution below, we'll be building an Azure Function that will handle summarizing the last hour of sales. The function will wake up every hour, and will read a set of sale receipts from Azure Cosmos DB. Then the function will create an hourly summary of sales and store it back in the container. To simplify the scenario, cleanup of the already processed receipts will be handled by an already configured [TTL](./time-to-live.md) setting.
24
22
25
23
## Assign a System-Assigned Managed Identity to an Azure Function
26
24
@@ -34,9 +32,9 @@ In this step, you'll assign a system-assigned managed identity to your Azure Fun
34
32
1. On the **Identity tab** switch **System Identity** to the "On" position. Be sure to click **Save**, and confirm you want to turn on System Identity. In the end the **System Identity** pane should look like this:
## Grant the System-Assigned Managed Identity Access to your Cosmos DB
35
+
## Grant the System-Assigned Managed Identity Access to your Azure Cosmos DB
38
36
39
-
In this step, you'll assign a role to the Azure Function's System-Assigned Managed Identity. Cosmos DB has multiple built-in roles you can assign the System Identity too. For this exercise we'll just focus on two:
37
+
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 you can assign the System Identity too. For this exercise we'll just focus on two:
40
38
41
39
|**Built-in role**|**Description**|
42
40
|---------|---------|
@@ -47,11 +45,11 @@ In this step, you'll assign a role to the Azure Function's System-Assigned Manag
47
45
> RBAC 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 [Secure access to data in Azure Cosmos DB](secure-access-to-data.md)
48
46
49
47
> [!TIP]
50
-
> When assigning roles, only assign the needed access. So if your service only need to read, then only assign the Service Managed Identity to **Cosmos DB Account Reader**. For more information about the importance of **least privilege access,** see [lower exposure of privileged accounts](../security/fundamentals/identity-management-best-practices.md#lower-exposure-of-privileged-accounts).
48
+
> When assigning roles, only assign the needed access. If your service only needs to read, then only assign the Service Managed Identity to **Cosmos DB Account Reader**. For more information about the importance of **least privilege access,** see [lower exposure of privileged accounts](../security/fundamentals/identity-management-best-practices.md#lower-exposure-of-privileged-accounts).
51
49
52
-
For our scenario, we'll read the sale receipt documents, summarize them, and then write back that summary to Cosmos DB. Since we need write access, we'll use the **DocumentDB Account Contributor** role.
50
+
For our scenario, we'll read the sale receipt documents, summarize them, and then write back that summary to Azure Cosmos DB. Since we need write access, we'll use the **DocumentDB Account Contributor** role.
53
51
54
-
1. Open your Cosmos DB in the portal, select the **Access Management (IAM) Pane**, and then the **Role Assignments** tab:
52
+
1. Open your Azure Cosmos DB in the portal, select the **Access Management (IAM) Pane**, and then the **Role Assignments** tab:
1. Select the **+ Add** button, then **add role assignment**:
@@ -67,11 +65,11 @@ For our scenario, we'll read the sale receipt documents, summarize them, and the
67
65
68
66
1. Select the function app and click **Save**.
69
67
70
-
## Programmatically access the Cosmos DB keys from the Azure Function
68
+
## Programmatically access the Azure Cosmos DB keys from the Azure Function
71
69
72
-
Now we have a function app that has a system-assigned managed identity. That identity is given the **DocumentDB Account Contributor** role in the Cosmos DB permissions. The **Function App** code below will get the needed Cosmos DB Keys, create a CosmosClient, and run the summarization business logic.
70
+
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 **Function App** code below will get the needed Azure Cosmos DB Keys, create a CosmosClient, and run the summarization business logic.
73
71
74
-
We'll be using to get the Cosmos DB Keys is the [List Keys API](https://docs.microsoft.com/rest/api/cosmos-db-resource-provider/DatabaseAccounts/ListKeys).
72
+
We'll be using to get the Azure Cosmos DB Keys is the [List Keys API](https://docs.microsoft.com/rest/api/cosmos-db-resource-provider/DatabaseAccounts/ListKeys).
75
73
76
74
77
75
The api returns DatabaseAccountListKeysResult. This type isn't defined in the C# libraries. The code below is an implementation for this class. Add it to the solution:
You are now ready to [deploy your Azure Function.](../azure-functions/functions-create-first-function-vs-code.md)
187
185
188
186
> [!IMPORTANT]
189
-
> If you want to [assign the **Cosmos DB Account Reader**](#grant-the-system-assigned-managed-identity-access-to-your-cosmos-db) 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 would only populate the read only keys on the DatabaseAccountListKeysResult class.
187
+
> If you want to [assign the **Cosmos DB Account Reader**](#grant-the-system-assigned-managed-identity-access-to-your-azure-cosmos-db) 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 would only populate the read only keys on the DatabaseAccountListKeysResult class.
0 commit comments