Skip to content

Commit c54b874

Browse files
Merge pull request #279171 from seesharprun/cosmos-rbac-function-local
Cosmos DB | Add steps to RBAC tutorial for local access
2 parents 1796087 + 621c198 commit c54b874

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
author: seesharprun
88
ms.author: sidandrews
99
ms.reviewer: justipat
10-
ms.date: 10/20/2022
10+
ms.date: 06/25/2024
1111
ms.service: cosmos-db
1212
ms.subservice: nosql
1313
ms.topic: how-to
@@ -16,7 +16,7 @@ metadata:
1616
- devx-track-azurecli
1717
- subject-rbac-steps
1818
- ge-structured-content-pilot
19-
19+
ai-usage: ai-assisted
2020
title: |
2121
Use system-assigned managed identities to access Azure Cosmos DB data
2222
introduction: |
@@ -50,7 +50,7 @@ prerequisites:
5050
```
5151
5252
> [!NOTE]
53-
> These variables will be re-used in later steps. This example assumes your Azure Cosmos DB account name is ``msdocs-cosmos-app``, your function app name is ``msdocs-function-app`` and your resource group name is ``msdocs-cosmos-functions-dotnet-identity``.
53+
> These variables are reused in later steps. This example assumes your Azure Cosmos DB account name is ``msdocs-cosmos-app``, your function app name is ``msdocs-function-app`` and your resource group name is ``msdocs-cosmos-functions-dotnet-identity``.
5454
5555
2. View the function app's properties using the [``az functionapp show``](/cli/azure/functionapp#az-functionapp-show) command.
5656
@@ -79,7 +79,7 @@ procedureSection:
7979
- title: |
8080
Create Azure Cosmos DB API for NoSQL databases
8181
summary: |
82-
In this step, you'll create two databases.
82+
In this step, you create two databases.
8383
steps:
8484
- |
8585
In a terminal or command window, create a new ``products`` database using [``az cosmosdb sql database create``](/cli/azure/cosmosdb/sql/database#az-cosmosdb-sql-database-create).
@@ -102,7 +102,7 @@ procedureSection:
102102
- title: |
103103
Get Azure Cosmos DB API for NoSQL endpoint
104104
summary: |
105-
In this step, you'll query the document endpoint for the API for NoSQL account.
105+
In this step, you query the document endpoint for the API for NoSQL account.
106106
steps:
107107
- |
108108
Use ``az cosmosdb show`` with the **query** parameter set to ``documentEndpoint``. Record the result. You'll use this value in a later step.
@@ -125,11 +125,11 @@ procedureSection:
125125
```
126126
127127
> [!NOTE]
128-
> This variable will be re-used in a later step.
128+
> This variable is reused in a later step.
129129
- title: |
130130
Grant access to your Azure Cosmos DB account
131131
summary: |
132-
In this step, you'll assign a role to the function app's system-assigned managed identity. Azure Cosmos DB has multiple built-in roles that you can assign to the managed identity for control-plane access. For data-plane access, you'll create a new custom role with access to read metadata.
132+
In this step, you assign a role to the function app's system-assigned managed identity. Azure Cosmos DB has multiple built-in roles that you can assign to the managed identity for control-plane access. For data-plane access, you create a new custom role with access to read metadata.
133133
134134
> [!TIP]
135135
> 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.
@@ -150,7 +150,7 @@ procedureSection:
150150
```
151151
152152
> [!NOTE]
153-
> This variable will be re-used in a later step.
153+
> This variable is reused in a later step.
154154
- |
155155
Use ``az webapp identity show`` with the **query** parameter set to ``principalId``. Store the result in a shell variable named ``principal``.
156156
@@ -296,8 +296,25 @@ procedureSection:
296296
- title: |
297297
(Optional) Run the function locally
298298
summary: |
299-
In a local environment, the [``DefaultAzureCredential``](/dotnet/api/azure.identity.defaultazurecredential) class will use various local credentials to determine the current identity. While running locally isn't required for the how-to, you can develop locally using your own identity or a service principal.
300-
steps:
299+
In a local environment, the [``DefaultAzureCredential``](/dotnet/api/azure.identity.defaultazurecredential) class uses various local credentials to determine the current identity. While running locally isn't required for the how-to, you can develop locally using your own identity or a service principal.
300+
steps:
301+
- |
302+
Get your local account's principal identifier using [`az ad signed-in-user show`](/cli/azure/ad/signed-in-user#az-ad-signed-in-user-show).
303+
304+
```azurecli-interactive
305+
az ad signed-in-user show --query "id"
306+
```
307+
- |
308+
Assign your local account role-based access control access to the Azure Cosmos DB account using [`az cosmosdb sql role assignment create`](/cli/azure/cosmosdb/sql/role/assignment#az-cosmosdb-sql-role-assignment-create) command. Use the built-in "Cosmos DB Data Contributor" role with an id of `00000000-0000-0000-0000-000000000002`.
309+
310+
```azurecli-interactive
311+
az cosmosdb sql role assignment create \
312+
--resource-group $resourceGroupName \
313+
--account-name $cosmosName \
314+
--role-definition-id "00000000-0000-0000-0000-000000000002" \
315+
--principal-id "<your-principal-id>" \
316+
--scope "/"
317+
```
301318
- |
302319
In the **local.settings.json** file, add a new setting named ``COSMOS_ENDPOINT`` in the **Values** object. The value of the setting should be the document endpoint you recorded earlier in this how-to guide.
303320
@@ -322,7 +339,7 @@ procedureSection:
322339
- title: |
323340
Deploy to Azure
324341
summary: |
325-
Once published, the ``DefaultAzureCredential`` class will use credentials from the environment or a managed identity. For this guide, the system-assigned managed identity will be used as a credential for the [``CosmosClient``](/dotnet/api/microsoft.azure.cosmos.cosmosclient) constructor.
342+
Once published, the ``DefaultAzureCredential`` class uses credentials from the environment or a managed identity. For this guide, the system-assigned managed identity will be used as a credential for the [``CosmosClient``](/dotnet/api/microsoft.azure.cosmos.cosmosclient) constructor.
326343
steps:
327344
- |
328345
Set the ``COSMOS_ENDPOINT`` setting on the function app already deployed in Azure.

0 commit comments

Comments
 (0)