Skip to content

Commit f050cf4

Browse files
committed
updating per feedback
1 parent 2eddf2b commit f050cf4

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

articles/cosmos-db/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@
10101010
href: how-to-configure-cross-origin-resource-sharing.md
10111011
- name: Secure Azure Cosmos keys using Key Vault
10121012
href: access-secrets-from-keyvault.md
1013-
- name: Secure Azure Cosmos Keys using Managed Identity
1013+
- name: Secure Azure Cosmos Keys using a Managed Identity
10141014
href: managed-identity-based-authentication.md
10151015
- name: Certificate-based authentication with Azure AD
10161016
href: certificate-based-authentication.md

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
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.
33
description: Learn how to configure an Azure AD system-assigned managed identity to access keys from Azure Cosmos DB.
44
author: j-patrick
55
ms.service: cosmos-db
@@ -10,17 +10,15 @@ ms.reviewer: sngun
1010

1111
---
1212

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

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

1717
You'll learn how to:
1818

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

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

2523
## Assign a System-Assigned Managed Identity to an Azure Function
2624

@@ -34,9 +32,9 @@ In this step, you'll assign a system-assigned managed identity to your Azure Fun
3432
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:
3533
![System Identity turned on](./media/managed-identity-based-authentication/identity-tab-system-managed-on.png)
3634

37-
## Grant the System-Assigned Managed Identity Access to your Cosmos DB
35+
## Grant the System-Assigned Managed Identity Access to your Azure Cosmos DB
3836

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

4139
|**Built-in role** |**Description** |
4240
|---------|---------|
@@ -47,11 +45,11 @@ In this step, you'll assign a role to the Azure Function's System-Assigned Manag
4745
> 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)
4846
4947
> [!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).
5149
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.
5351

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:
5553
![IAM Pane](./media/managed-identity-based-authentication/cosmos-db-iam-tab.png)
5654

5755
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
6765

6866
1. Select the function app and click **Save**.
6967

70-
## Programmatically access the Cosmos DB keys from the Azure Function
68+
## Programmatically access the Azure Cosmos DB keys from the Azure Function
7169

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

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

7674

7775
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:
@@ -111,11 +109,11 @@ namespace SummarizationService
111109
private static string resourceGroupName = "
112110
<name of your azure resource group>";
113111
private static string accountName =
114-
"<cosmos db account name>";
112+
"<Azure Cosmos DB account name>";
115113
private static string cosmosDbEndpoint =
116-
"<cosmos db endpoint>";
114+
"<Azure Cosmos DB endpoint>";
117115
private static string databaseName =
118-
"<cosmos db name>";
116+
"<Azure Cosmos DB name>";
119117
private static string containerName =
120118
"<container where the sales receipts are>";
121119
private static string indexToQuery =
@@ -132,7 +130,7 @@ namespace SummarizationService
132130
// In order to get the Service Managed token we need to authenticate to the Azure Resource Manager.
133131
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/");
134132

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

138136
// setup an HTTP Client and add the access token.
@@ -186,7 +184,7 @@ namespace SummarizationService
186184
You are now ready to [deploy your Azure Function.](../azure-functions/functions-create-first-function-vs-code.md)
187185

188186
> [!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.
190188
191189
## Next steps
192190

-2.12 KB
Loading
-15.6 KB
Loading

0 commit comments

Comments
 (0)