Skip to content

Commit b4237b8

Browse files
authored
Merge pull request #101157 from MarkusVi/arturo115
arturo115
2 parents 2cf7a77 + e73bcf5 commit b4237b8

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

articles/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-cosmos-db.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ services: active-directory
55
documentationcenter: ''
66
author: MarkusVi
77
manager: daveba
8-
editor: daveba
8+
editor:
99
ms.service: active-directory
1010
ms.subservice: msi
1111
ms.devlang: na
1212
ms.topic: tutorial
1313
ms.tgt_pltfrm: na
1414
ms.workload: identity
15-
ms.date: 01/10/2020
15+
ms.date: 01/14/2020
1616
ms.author: markvi
1717
ms.collection: M365-identity-device-management
1818
---
@@ -35,7 +35,17 @@ This tutorial shows you how to use a system-assigned managed identity for a Wind
3535

3636
- Install the latest version of [Azure PowerShell](/powershell/azure/install-az-ps)
3737

38-
## Create a Cosmos DB account
38+
39+
## Enable
40+
41+
[!INCLUDE [msi-tut-enable](../../../includes/active-directory-msi-tut-enable.md)]
42+
43+
44+
45+
## Grant access
46+
47+
48+
### Create a Cosmos DB account
3949

4050
If you don't already have one, create a Cosmos DB account. You can skip this step and use an existing Cosmos DB account.
4151

@@ -46,15 +56,16 @@ If you don't already have one, create a Cosmos DB account. You can skip this ste
4656
5. Ensure the **Subscription** and **Resource Group** match the ones you specified when you created your VM in the previous step. Select a **Location** where Cosmos DB is available.
4757
6. Click **Create**.
4858

49-
## Create a collection
59+
### Create a collection
5060

5161
Next, add a data collection in the Cosmos DB account that you can query in later steps.
5262

5363
1. Navigate to your newly created Cosmos DB account.
5464
2. On the **Overview** tab click the **+/Add Collection** button, and an "Add Collection" panel slides out.
5565
3. Give the collection a database ID, collection ID, select a storage capacity, enter a partition key, enter a throughput value, then click **OK**. For this tutorial, it is sufficient to use "Test" as the database ID and collection ID, select a fixed storage capacity and lowest throughput (400 RU/s).
5666

57-
## Grant access
67+
68+
### Grant access to the Cosmos DB account access keys
5869

5970
This section shows how to grant Windows VM system-assigned managed identity access to the Cosmos DB account access keys. Cosmos DB does not natively support Azure AD authentication. However, you can use a system-assigned managed identity to retrieve a Cosmos DB access key from the Resource Manager, and use the key to access Cosmos DB. In this step, you grant your Windows VM system-assigned managed identity access to the keys to the Cosmos DB account.
6071

@@ -64,11 +75,15 @@ To grant the Windows VM system-assigned managed identity access to the Cosmos DB
6475
$spID = (Get-AzVM -ResourceGroupName myRG -Name myVM).identity.principalid
6576
New-AzRoleAssignment -ObjectId $spID -RoleDefinitionName "Cosmos DB Account Reader Role" -Scope "/subscriptions/<mySubscriptionID>/resourceGroups/<myResourceGroup>/providers/Microsoft.DocumentDb/databaseAccounts/<COSMOS DB ACCOUNT NAME>"
6677
```
67-
## Get an access token
78+
## Access data
79+
80+
This section shows how to call Azure Resource Manager using an access token for the Windows VM system-assigned managed identity. For the remainder of the tutorial, we will work from the VM we created earlier.
81+
82+
You need to install the latest version of [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) on your Windows VM.
6883

69-
This section shows how to get an access token using the Windows VM system-assigned managed identity to call Azure Resource Manager. For the remainder of the tutorial, we will work from the VM we created earlier.
7084

71-
You will need to install the latest version of [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) on your Windows VM.
85+
86+
### Get an access token
7287

7388
1. In the Azure portal, navigate to **Virtual Machines**, go to your Windows virtual machine, then from the **Overview** page click **Connect** at the top.
7489
2. Enter in your **Username** and **Password** for which you added when you created the Windows VM.
@@ -93,7 +108,7 @@ You will need to install the latest version of [Azure CLI](https://docs.microsof
93108
$ArmToken = $content.access_token
94109
```
95110

96-
## Get access keys
111+
### Get access keys
97112

98113
This section shows how to get access keys from Azure Resource Manager to make Cosmos DB calls. Now use PowerShell to call Resource Manager using the access token retrieved in the previous section to retrieve the Cosmos DB account access key. Once we have the access key, we can query Cosmos DB. Be sure to replace the `<SUBSCRIPTION ID>`, `<RESOURCE GROUP>`, and `<COSMOS DB ACCOUNT NAME>` parameter values with your own values. Replace the `<ACCESS TOKEN>` value with the access token you retrieved earlier. If you want to retrieve read/write keys, use key operation type `listKeys`. If you want to retrieve read-only keys, use the key operation type `readonlykeys`:
99114

@@ -172,6 +187,13 @@ This CLI command returns details about the collection:
172187
}
173188
```
174189

190+
191+
## Disable
192+
193+
[!INCLUDE [msi-tut-disable](../../../includes/active-directory-msi-tut-disable.md)]
194+
195+
196+
175197
## Next steps
176198

177199
In this tutorial, you learned how to use a Windows VM system-assigned identity to access Cosmos DB. To learn more about Cosmos DB see:

0 commit comments

Comments
 (0)