Skip to content

Commit 649da1a

Browse files
authored
Merge pull request #108562 from plzm/cosmosdb-powershell-updates
Cosmos DB - Powershell sample docs update
2 parents 76e2f62 + 7e957fe commit 649da1a

35 files changed

+669
-751
lines changed

articles/cosmos-db/certificate-based-authentication.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ In this step, you will register a sample web application in your Azure AD accoun
3434

3535
* **Name** – Provide a name for your application, it can be any name such as "sampleApp".
3636
* **Supported account types** – Choose **Accounts in this organizational directory only (Default Directory)** to allow resources in your current directory to access this application.
37-
* **Redirect URL** – Choose application of type **Web** and provide a URL where your application is hosted, it can be any URL. For this example, you can provide a test URL such as `https://sampleApp.com` its okay even if the app doesnt exist.
37+
* **Redirect URL** – Choose application of type **Web** and provide a URL where your application is hosted, it can be any URL. For this example, you can provide a test URL such as `https://sampleApp.com` it's okay even if the app doesn't exist.
3838

3939
![Registering a sample web application](./media/certificate-based-authentication/register-sample-web-app.png)
4040

@@ -48,7 +48,7 @@ In this step, you will register a sample web application in your Azure AD accoun
4848

4949
In this step, you will install the Azure AD PowerShell module. This module is required to get the ID of the application you registered in the previous step and associate a self-signed certificate to that application.
5050

51-
1. Open Windows PowerShell ISE with administrator rights. If you havent already done, install the AZ PowerShell module and connect to your subscription. If you have multiple subscriptions, you can set the context of current subscription as shown in the following commands:
51+
1. Open Windows PowerShell ISE with administrator rights. If you haven't already done, install the AZ PowerShell module and connect to your subscription. If you have multiple subscriptions, you can set the context of current subscription as shown in the following commands:
5252

5353
```powershell
5454
Install-Module -Name Az -AllowClobber
@@ -133,18 +133,20 @@ In this step, you will sign into Azure by using the application and the certific
133133
Disconnect-AzAccount -Username <Your_Azure_account_email_id>
134134
```
135135

136-
1. Next validate that you can sign into Azure portal by using the applications credentials and access the Azure Cosmos DB keys:
136+
1. Next validate that you can sign into Azure portal by using the application's credentials and access the Azure Cosmos DB keys:
137137

138138
```powershell
139139
Login-AzAccount -ApplicationId <Your_Application_ID> -CertificateThumbprint $cert.Thumbprint -ServicePrincipal -Tenant <Tenant_ID_of_your_application>
140140
141-
Invoke-AzResourceAction -Action listKeys -ResourceType "Microsoft.DocumentDB/databaseAccounts" -ApiVersion "2015-04-08" -ResourceGroupName <Resource_Group_Name_of_your_Azure_Cosmos_account> -ResourceName <Your_Azure_Cosmos_Account_Name>
141+
Get-AzCosmosDBAccountKey `
142+
-ResourceGroupName "<Resource_Group_Name_of_your_Azure_Cosmos_account>" `
143+
-Name "<Your_Azure_Cosmos_Account_Name>" `
144+
-Type "Keys"
142145
```
143146

144-
The previous command will display the primary and secondary master keys of your Azure Cosmos account. You can view the Activity log of your Azure Cosmos account to validate that the get keys request succeeded and the event is initiated by the "sampleApp" application.
145-
146-
![Validate the get keys call in the Azure AD](./media/certificate-based-authentication/activity-log-validate-results.png)
147+
The previous command will display the primary and secondary master keys of your Azure Cosmos account. You can view the Activity log of your Azure Cosmos account to validate that the get keys request succeeded and the event is initiated by the "sampleApp" application.
147148

149+
![Validate the get keys call in the Azure AD](./media/certificate-based-authentication/activity-log-validate-results.png)
148150

149151
## Access the keys from a C# application
150152

articles/cosmos-db/how-to-configure-vnet-service-endpoint.md

Lines changed: 59 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This document describes the steps required to set up a virtual netw
44
author: markjbrown
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 09/28/2019
7+
ms.date: 03/26/2020
88
ms.author: mjbrown
99

1010
---
@@ -36,7 +36,7 @@ The following sections describe how to configure a virtual network service endpo
3636

3737
1. To grant access to an existing virtual network's subnet, under **Virtual networks**, select **Add existing Azure virtual network**.
3838

39-
1. Select the **Subscription** from which you want to add an Azure virtual network. Select the Azure **Virtual networks** and **Subnets** that you want to provide access to your Azure Cosmos DB account. Next, select **Enable** to enable selected networks with service endpoints for "Microsoft.AzureCosmosDB". When its complete, select **Add**.
39+
1. Select the **Subscription** from which you want to add an Azure virtual network. Select the Azure **Virtual networks** and **Subnets** that you want to provide access to your Azure Cosmos DB account. Next, select **Enable** to enable selected networks with service endpoints for "Microsoft.AzureCosmosDB". When it's complete, select **Add**.
4040

4141
![Select virtual network and subnet](./media/how-to-configure-vnet-service-endpoint/choose-subnet-and-vnet.png)
4242

@@ -72,13 +72,13 @@ To ensure that you have access to Azure Cosmos DB metrics from the portal, you n
7272

7373
1. From the **All resources** blade, find the Azure Cosmos DB account for which you assigned service endpoints.
7474

75-
2. Select **Firewalls and virtual networks** from the settings menu.
75+
1. Select **Firewalls and virtual networks** from the settings menu.
7676

77-
3. To remove a virtual network or subnet rule, select **...** next to the virtual network or subnet, and select **Remove**.
77+
1. To remove a virtual network or subnet rule, select **...** next to the virtual network or subnet, and select **Remove**.
7878

7979
![Remove a virtual network](./media/how-to-configure-vnet-service-endpoint/remove-a-vnet.png)
8080

81-
4. Select **Save** to apply your changes.
81+
1. Select **Save** to apply your changes.
8282

8383
## <a id="configure-using-powershell"></a>Configure a service endpoint by using Azure PowerShell
8484

@@ -92,91 +92,58 @@ Use the following steps to configure a service endpoint to an Azure Cosmos DB ac
9292
1. Enable the service endpoint for an existing subnet of a virtual network.
9393

9494
```powershell
95-
$rgname = "<Resource group name>"
96-
$vnName = "<Virtual network name>"
97-
$sname = "<Subnet name>"
95+
$resourceGroupName = "<Resource group name>"
96+
$vnetName = "<Virtual network name>"
97+
$subnetName = "<Subnet name>"
9898
$subnetPrefix = "<Subnet address range>"
99+
$serviceEndpoint = "Microsoft.AzureCosmosDB"
99100
100101
Get-AzVirtualNetwork `
101-
-ResourceGroupName $rgname `
102-
-Name $vnName | Set-AzVirtualNetworkSubnetConfig `
103-
-Name $sname `
104-
-AddressPrefix $subnetPrefix `
105-
-ServiceEndpoint "Microsoft.AzureCosmosDB" | Set-AzVirtualNetwork
102+
-ResourceGroupName $resourceGroupName `
103+
-Name $vnetName | Set-AzVirtualNetworkSubnetConfig `
104+
-Name $subnetName `
105+
-AddressPrefix $subnetPrefix `
106+
-ServiceEndpoint $serviceEndpoint | Set-AzVirtualNetwork
106107
```
107108

108109
1. Get virtual network information.
109110

110111
```powershell
111-
$vnProp = Get-AzVirtualNetwork `
112-
-Name $vnName `
113-
-ResourceGroupName $rgName
114-
```
115-
116-
1. Get properties of the Azure Cosmos DB account by running the following cmdlet:
112+
$vnet = Get-AzVirtualNetwork `
113+
-ResourceGroupName $resourceGroupName `
114+
-Name $vnetName
117115
118-
```powershell
119-
$apiVersion = "2015-04-08"
120-
$acctName = "<Azure Cosmos DB account name>"
121-
122-
$cosmosDBConfiguration = Get-AzResource `
123-
-ResourceType "Microsoft.DocumentDB/databaseAccounts" `
124-
-ApiVersion $apiVersion `
125-
-ResourceGroupName $rgName `
126-
-Name $acctName
116+
$subnetId = $vnet.Id + "/subnets/" + $subnetName
127117
```
128118

129-
1. Initialize the variables for use later. Set up all the variables from the existing account definition.
119+
1. Prepare a Cosmos DB Virtual Network Rule
130120

131121
```powershell
132-
$locations = @()
133-
134-
foreach ($readLocation in $cosmosDBConfiguration.Properties.readLocations) {
135-
$locations += , @{
136-
locationName = $readLocation.locationName;
137-
failoverPriority = $readLocation.failoverPriority;
138-
}
139-
}
140-
141-
$virtualNetworkRules = @(@{
142-
id = "$($vnProp.Id)/subnets/$sname";
143-
})
144-
145-
if ($cosmosDBConfiguration.Properties.isVirtualNetworkFilterEnabled) {
146-
$virtualNetworkRules = $cosmosDBConfiguration.Properties.virtualNetworkRules + $virtualNetworkRules
147-
}
122+
$vnetRule = New-AzCosmosDBVirtualNetworkRule `
123+
-Id $subnetId
148124
```
149125

150-
1. Update Azure Cosmos DB account properties with the new configuration by running the following cmdlets:
126+
1. Update Azure Cosmos DB account properties with the new Virtual Network endpoint configuration:
151127

152128
```powershell
153-
$cosmosDBProperties = @{
154-
databaseAccountOfferType = $cosmosDBConfiguration.Properties.databaseAccountOfferType;
155-
consistencyPolicy = $cosmosDBConfiguration.Properties.consistencyPolicy;
156-
ipRangeFilter = $cosmosDBConfiguration.Properties.ipRangeFilter;
157-
locations = $locations;
158-
virtualNetworkRules = $virtualNetworkRules;
159-
isVirtualNetworkFilterEnabled = $True;
160-
}
161-
162-
Set-AzResource `
163-
-ResourceType "Microsoft.DocumentDB/databaseAccounts" `
164-
-ApiVersion $apiVersion `
165-
-ResourceGroupName $rgName `
166-
-Name $acctName `
167-
-Properties $CosmosDBProperties
129+
$accountName = "<Cosmos DB account name>"
130+
131+
Update-AzCosmosDBAccount `
132+
-ResourceGroupName $resourceGroupName `
133+
-Name $accountName `
134+
-EnableVirtualNetwork $true `
135+
-VirtualNetworkRuleObject @($vnetRule)
168136
```
169137

170138
1. Run the following command to verify that your Azure Cosmos DB account is updated with the virtual network service endpoint that you configured in the previous step:
171139

172140
```powershell
173-
$UpdatedcosmosDBConfiguration = Get-AzResource `
174-
-ResourceType "Microsoft.DocumentDB/databaseAccounts" `
175-
-ApiVersion $apiVersion `
176-
-ResourceGroupName $rgName `
177-
-Name $acctName
141+
$account = Get-AzCosmosDBAccount `
142+
-ResourceGroupName $resourceGroupName `
143+
-Name $accountName
178144
179-
$UpdatedcosmosDBConfiguration.Properties
145+
$account.IsVirtualNetworkFilterEnabled
146+
$account.VirtualNetworkRules
180147
```
181148

182149
## <a id="configure-using-cli"></a>Configure a service endpoint by using the Azure CLI
@@ -289,88 +256,47 @@ az network vnet subnet update \
289256

290257
## <a id="migrate-from-firewall-to-vnet"></a>Migrating from an IP firewall rule to a virtual network ACL
291258

292-
Use the following steps only for Azure Cosmos DB accounts with existing IP firewall rules that allow a subnet, when you want to use virtual network and subnet-based ACLs instead of an IP firewall rule.
259+
To migrate an Azure Cosmos DB account from using IP firewall rules to using virtual network service endpoints, use the following steps.
293260

294-
After a service endpoint for an Azure Cosmos DB account is turned on for a subnet, the requests are sent with a source that contains virtual network and subnet information instead of a public IP. These requests don't match an IP filter. This source switch happens for all Azure Cosmos DB accounts accessed from the subnet with a service endpoint enabled. To prevent downtime, use the following steps:
261+
After an Azure Cosmos DB account is configured for a service endpoint for a subnet, requests from that subnet are sent to Azure Cosmos DB with virtual network and subnet source information instead of a source public IP address. These requests will no longer match an IP filter configured on the Azure Cosmos DB account, which is why the following steps are necessary to avoid downtime.
295262

296-
1. Get properties of the Azure Cosmos DB account by running the following cmdlet:
297-
298-
```powershell
299-
$apiVersion = "2015-04-08"
300-
$acctName = "<Azure Cosmos DB account name>"
301-
302-
$cosmosDBConfiguration = Get-AzResource `
303-
-ResourceType "Microsoft.DocumentDB/databaseAccounts" `
304-
-ApiVersion $apiVersion `
305-
-ResourceGroupName $rgName `
306-
-Name $acctName
307-
```
263+
Before proceeding, enable the Azure Cosmos DB service endpoint on the virtual network and subnet using the step shown above in "Enable the service endpoint for an existing subnet of a virtual network".
308264

309-
1. Initialize the variables to use them later. Set up all the variables from the existing account definition. Add the virtual network ACL to all Azure Cosmos DB accounts being accessed from the subnet with `ignoreMissingVNetServiceEndpoint` flag.
265+
1. Get virtual network and subnet information:
310266

311267
```powershell
312-
$locations = @()
268+
$resourceGroupName = "myResourceGroup"
269+
$accountName = "mycosmosaccount"
270+
$vnetName = "myVnet"
271+
$subnetName = "mySubnet"
313272
314-
foreach ($readLocation in $cosmosDBConfiguration.Properties.readLocations) {
315-
$locations += , @{
316-
locationName = $readLocation.locationName;
317-
failoverPriority = $readLocation.failoverPriority;
318-
}
319-
}
273+
$vnet = Get-AzVirtualNetwork `
274+
-ResourceGroupName $resourceGroupName `
275+
-Name $vnetName
320276
321-
$subnetID = "Subnet ARM URL" e.g "/subscriptions/f7ddba26-ab7b-4a36-a2fa-7d01778da30b/resourceGroups/testrg/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/subnet1"
322-
323-
$virtualNetworkRules = @(@{
324-
id = $subnetID;
325-
ignoreMissingVNetServiceEndpoint = "True";
326-
})
327-
328-
if ($cosmosDBConfiguration.Properties.isVirtualNetworkFilterEnabled) {
329-
$virtualNetworkRules = $cosmosDBConfiguration.Properties.virtualNetworkRules + $virtualNetworkRules
330-
}
277+
$subnetId = $vnet.Id + "/subnets/" + $subnetName
331278
```
332279

333-
1. Update Azure Cosmos DB account properties with the new configuration by running the following cmdlets:
280+
1. Prepare a new Virtual Network rule object for the Azure Cosmos DB account:
334281

335282
```powershell
336-
$cosmosDBProperties = @{
337-
databaseAccountOfferType = $cosmosDBConfiguration.Properties.databaseAccountOfferType;
338-
consistencyPolicy = $cosmosDBConfiguration.Properties.consistencyPolicy;
339-
ipRangeFilter = $cosmosDBConfiguration.Properties.ipRangeFilter;
340-
locations = $locations;
341-
virtualNetworkRules = $virtualNetworkRules;
342-
isVirtualNetworkFilterEnabled = $True;
343-
}
344-
345-
Set-AzResource `
346-
-ResourceType "Microsoft.DocumentDB/databaseAccounts" `
347-
-ApiVersion $apiVersion `
348-
-ResourceGroupName $rgName `
349-
-Name $acctName `
350-
-Properties $CosmosDBProperties
283+
$vnetRule = New-AzCosmosDBVirtualNetworkRule `
284+
-Id $subnetId
351285
```
352286

353-
1. Repeat steps 1-3 for all Azure Cosmos DB accounts that you access from the subnet.
354-
355-
1. Wait 15 minutes, and then update the subnet to enable the service endpoint.
287+
1. Update the Azure Cosmos DB account to enable service endpoint access from the subnet:
356288

357-
1. Enable the service endpoint for an existing subnet of a virtual network.
358-
359-
```powershell
360-
$rgname= "<Resource group name>"
361-
$vnName = "<virtual network name>"
362-
$sname = "<Subnet name>"
363-
$subnetPrefix = "<Subnet address range>"
289+
```powershell
290+
Update-AzCosmosDBAccount `
291+
-ResourceGroupName $resourceGroupName `
292+
-Name $accountName `
293+
-EnableVirtualNetwork $true `
294+
-VirtualNetworkRuleObject @($vnetRule)
295+
```
364296

365-
Get-AzVirtualNetwork `
366-
-ResourceGroupName $rgname `
367-
-Name $vnName | Set-AzVirtualNetworkSubnetConfig `
368-
-Name $sname `
369-
-AddressPrefix $subnetPrefix `
370-
-ServiceEndpoint "Microsoft.AzureCosmosDB" | Set-AzVirtualNetwork
371-
```
297+
1. Repeat the previous steps for all Azure Cosmos DB accounts accessed from the subnet.
372298

373-
1. Remove the IP firewall rule for the subnet.
299+
1. Remove the IP firewall rule for the subnet from the Azure Cosmos DB account's Firewall rules.
374300

375301
## Next steps
376302

0 commit comments

Comments
 (0)