Skip to content

Commit a055b2c

Browse files
authored
Merge pull request #89905 from markjbrown/mjbrown-cli-update
Mega update for az cli articles
2 parents 5cdbd0e + a1602c8 commit a055b2c

12 files changed

+642
-867
lines changed

articles/cosmos-db/how-to-configure-firewall.md

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to configure IP access control policies for firewall supp
44
author: markjbrown
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 07/25/2019
7+
ms.date: 09/28/2019
88
ms.author: mjbrown
99
---
1010

@@ -18,7 +18,7 @@ You can secure the data stored in your Azure Cosmos DB account by using IP firew
1818

1919
## <a id="configure-ip-policy"></a> Configure an IP firewall by using the Azure portal
2020

21-
To set the IP access control policy in the Azure portal, go to the Azure Cosmos DB account page and select **Firewall and virtual networks** on the navigation menu. Change the **Allow access from** value to **Selected networks**, and then select **Save**.
21+
To set the IP access control policy in the Azure portal, go to the Azure Cosmos DB account page and select **Firewall and virtual networks** on the navigation menu. Change the **Allow access from** value to **Selected networks**, and then select **Save**.
2222

2323
![Screenshot showing how to open the Firewall page in the Azure portal](./media/how-to-configure-firewall/azure-portal-firewall.png)
2424

@@ -38,7 +38,7 @@ When you enable an IP access control policy programmatically, you need to add th
3838
|US Gov|52.244.48.71|
3939
|All other regions|104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26|
4040

41-
You can enable access to the Azure portal by selecting the **Allow access from Azure portal** option, as shown in the following screenshot:
41+
You can enable access to the Azure portal by selecting the **Allow access from Azure portal** option, as shown in the following screenshot:
4242

4343
![Screenshot showing how to enable Azure portal access](./media/how-to-configure-firewall/enable-azure-portal.png)
4444

@@ -49,23 +49,23 @@ If you access your Azure Cosmos DB account from services that don’t provide a
4949
> [!NOTE]
5050
> This option configures the firewall to allow all requests from Azure, including requests from the subscriptions of other customers deployed in Azure. The list of IPs allowed by this option is wide, so it limits the effectiveness of a firewall policy. Use this option only if your requests don’t originate from static IPs or subnets in virtual networks. Choosing this option automatically allows access from the Azure portal because the Azure portal is deployed in Azure.
5151
52-
You can enable access to the Azure portal by selecting the **Accept connections from within public Azure datacenters** option, as shown in the following screenshot:
52+
You can enable access to the Azure portal by selecting the **Accept connections from within Azure datacenters** option, as shown in the following screenshot:
5353

5454
![Screenshot showing how to open the Firewall page in the Azure portal](./media/how-to-configure-firewall/enable-azure-services.png)
5555

5656
### Requests from your current IP
5757

58-
To simplify development, the Azure portal helps you identify and add the IP of your client machine to the allowed list. Apps running your machine can then access your Azure Cosmos DB account.
58+
To simplify development, the Azure portal helps you identify and add the IP of your client machine to the allowed list. Apps running your machine can then access your Azure Cosmos DB account.
5959

60-
The portal automatically detects the client IP address. It might be the client IP address of your machine, or the IP address of your network gateway. Make sure to remove this IP address before you take your workloads to production.
60+
The portal automatically detects the client IP address. It might be the client IP address of your machine, or the IP address of your network gateway. Make sure to remove this IP address before you take your workloads to production.
6161

6262
To add your current IP to the list of IPs, select **Add my current IP**. Then select **Save**.
6363

6464
![Screenshot showing a how to configure firewall settings for the current IP](./media/how-to-configure-firewall/enable-current-ip.png)
6565

6666
### Requests from cloud services
6767

68-
In Azure, cloud services are a common way for hosting middle-tier service logic by using Azure Cosmos DB. To enable access to your Azure Cosmos DB account from a cloud service, you must add the public IP address of the cloud service to the allowed list of IP addresses associated with your Azure Cosmos DB account by [configuring the IP access control policy](#configure-ip-policy). This ensures that all role instances of cloud services have access to your Azure Cosmos DB account.
68+
In Azure, cloud services are a common way for hosting middle-tier service logic by using Azure Cosmos DB. To enable access to your Azure Cosmos DB account from a cloud service, you must add the public IP address of the cloud service to the allowed list of IP addresses associated with your Azure Cosmos DB account by [configuring the IP access control policy](#configure-ip-policy). This ensures that all role instances of cloud services have access to your Azure Cosmos DB account.
6969

7070
You can retrieve IP addresses for your cloud services in the Azure portal, as shown in the following screenshot:
7171

@@ -75,7 +75,7 @@ When you scale out your cloud service by adding role instances, those new instan
7575

7676
### Requests from virtual machines
7777

78-
You can also use [virtual machines](https://azure.microsoft.com/services/virtual-machines/) or [virtual machine scale sets](../virtual-machine-scale-sets/virtual-machine-scale-sets-overview.md) to host middle-tier services by using Azure Cosmos DB. To configure your Cosmos DB account such that it allows access from virtual machines, you must configure the public IP address of the virtual machine and/or virtual machine scale set as one of the allowed IP addresses for your Azure Cosmos DB account by [configuring the IP access control policy](#configure-ip-policy).
78+
You can also use [virtual machines](https://azure.microsoft.com/services/virtual-machines/) or [virtual machine scale sets](../virtual-machine-scale-sets/virtual-machine-scale-sets-overview.md) to host middle-tier services by using Azure Cosmos DB. To configure your Cosmos DB account such that it allows access from virtual machines, you must configure the public IP address of the virtual machine and/or virtual machine scale set as one of the allowed IP addresses for your Azure Cosmos DB account by [configuring the IP access control policy](#configure-ip-policy).
7979

8080
You can retrieve IP addresses for virtual machines in the Azure portal, as shown in the following screenshot:
8181

@@ -89,7 +89,7 @@ When you access your Azure Cosmos DB account from a computer on the internet, th
8989

9090
## <a id="configure-ip-firewall-arm"></a>Configure an IP firewall by using a Resource Manager template
9191

92-
To configure access control to your Azure Cosmos DB account, make sure that the Resource Manager template specifies the **ipRangeFilter** attribute with a list of allowed IP ranges. If configuring IP Firewall to an already deployed Cosmos account, ensure the `locations` array matches what is currently deployed. You cannot simultaneously modify the `locations` array and other properties. For more information and samples of ARM Templates for Azure Cosmos DB see, [Azure Resource Manager templates for Azure Cosmos DB](resource-manager-samples.md)
92+
To configure access control to your Azure Cosmos DB account, make sure that the Resource Manager template specifies the **ipRangeFilter** attribute with a list of allowed IP ranges. If configuring IP Firewall to an already deployed Cosmos account, ensure the `locations` array matches what is currently deployed. You cannot simultaneously modify the `locations` array and other properties. For more information and samples of Azure Resource Manager templates for Azure Cosmos DB see, [Azure Resource Manager templates for Azure Cosmos DB](resource-manager-samples.md)
9393

9494
```json
9595
{
@@ -111,83 +111,73 @@ To configure access control to your Azure Cosmos DB account, make sure that the
111111

112112
## <a id="configure-ip-firewall-cli"></a>Configure an IP access control policy by using the Azure CLI
113113

114-
The following command shows how to create an Azure Cosmos DB account with IP access control:
114+
The following command shows how to create an Azure Cosmos DB account with IP access control:
115115

116116
```azurecli-interactive
117+
# Create a Cosmos DB account with default values and IP Firewall enabled
118+
resourceGroupName='MyResourceGroup'
119+
accountName='mycosmosaccount'
120+
ipRangeFilter='192.168.221.17,183.240.196.255,40.76.54.131'
117121
118-
name="<Azure Cosmos DB account name>"
119-
resourceGroupName="<Resource group name>"
120-
122+
# Make sure there are no spaces in the comma-delimited list of IP addresses or CIDR ranges.
121123
az cosmosdb create \
122-
--name $name \
123-
--kind GlobalDocumentDB \
124-
--resource-group $resourceGroupName \
125-
--max-interval 10 \
126-
--max-staleness-prefix 200 \
127-
--ip-range-filter "183.240.196.255,104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26"
128-
```
129-
130-
To update the firewall settings for an existing account, run the following command:
131-
132-
```azurecli-interactive
133-
az cosmosdb update \
134-
--name $name \
135-
--resource-group $resourceGroupName \
136-
--ip-range-filter "183.240.196.255,104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26"
124+
-n $accountName \
125+
-g $resourceGroupName \
126+
--locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \
127+
--locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False \
128+
--ip-range-filter $ipRangeFilter
137129
```
138130

139131
## <a id="configure-ip-firewall-ps"></a>Configure an IP access control policy by using PowerShell
140132

141133
The following script shows how to create an Azure Cosmos DB account with IP access control:
142134

143135
```azurepowershell-interactive
144-
136+
# Create a Cosmos DB account with default values and IP Firewall enabled
145137
$resourceGroupName = "myResourceGroup"
146-
$accountName = "myaccountname"
138+
$accountName = "mycosmosaccount"
139+
$ipRangeFilter = "192.168.221.17,183.240.196.255,40.76.54.131"
147140
148141
$locations = @(
149-
@{ "locationName"="West US"; "failoverPriority"=0 },
150-
@{ "locationName"="East US"; "failoverPriority"=1 }
142+
@{ "locationName"="West US 2"; "failoverPriority"=0; "isZoneRedundant"=False },
143+
@{ "locationName"="East US 2"; "failoverPriority"=1, "isZoneRedundant"=False }
151144
)
152145
153-
# Add local machine's IP address to firewall, InterfaceAlias is your Network Adapter's name
154-
$ipRangeFilter = Get-NetIPConfiguration | Where-Object InterfaceAlias -eq "Ethernet 2" | Select-Object IPv4Address
155-
156-
$consistencyPolicy = @{ "defaultConsistencyLevel"="Session" }
157-
146+
# Make sure there are no spaces in the comma-delimited list of IP addresses or CIDR ranges.
158147
$CosmosDBProperties = @{
159148
"databaseAccountOfferType"="Standard";
160149
"locations"=$locations;
161-
"consistencyPolicy"=$consistencyPolicy;
162150
"ipRangeFilter"=$ipRangeFilter
163151
}
164152
165-
Set-AzResource -ResourceType "Microsoft.DocumentDb/databaseAccounts" `
153+
New-AzResource -ResourceType "Microsoft.DocumentDb/databaseAccounts" `
166154
-ApiVersion "2015-04-08" -ResourceGroupName $resourceGroupName `
167155
-Name $accountName -PropertyObject $CosmosDBProperties
168156
```
169157

170158
## <a id="troubleshoot-ip-firewall"></a>Troubleshoot issues with an IP access control policy
171159

172-
You can troubleshoot issues with an IP access control policy by using the following options:
160+
You can troubleshoot issues with an IP access control policy by using the following options:
161+
162+
### Azure portal
173163

174-
### Azure portal
175164
By enabling an IP access control policy for your Azure Cosmos DB account, you block all requests to your account from machines outside the allowed list of IP address ranges. To enable portal data-plane operations like browsing containers and querying documents, you need to explicitly allow Azure portal access by using the **Firewall** pane in the portal.
176165

177-
### SDKs
178-
When you access Azure Cosmos DB resources by using SDKs from machines that are not in the allowed list, a generic **403 Forbidden** response is returned with no additional details. Verify the allowed IP list for your account, and make sure that the correct policy configuration is applied to your Azure Cosmos DB account.
166+
### SDKs
167+
168+
When you access Azure Cosmos DB resources by using SDKs from machines that are not in the allowed list, a generic **403 Forbidden** response is returned with no additional details. Verify the allowed IP list for your account, and make sure that the correct policy configuration is applied to your Azure Cosmos DB account.
179169

180170
### Source IPs in blocked requests
171+
181172
Enable diagnostic logging on your Azure Cosmos DB account. These logs show each request and response. The firewall-related messages are logged with a 403 return code. By filtering these messages, you can see the source IPs for the blocked requests. See [Azure Cosmos DB diagnostic logging](logging.md).
182173

183174
### Requests from a subnet with a service endpoint for Azure Cosmos DB enabled
184-
Requests from a subnet in a virtual network that has a service endpoint for Azure Cosmos DB enabled sends the virtual network and subnet identity to Azure Cosmos DB accounts. These requests don't have the public IP of the source, so IP filters reject them. To allow access from specific subnets in virtual networks, add an access control list as outlined in [How to configure virtual network and subnet-based access for your Azure Cosmos DB account](how-to-configure-vnet-service-endpoint.md). It can take up to 15 minutes for firewall rules to apply.
185175

176+
Requests from a subnet in a virtual network that has a service endpoint for Azure Cosmos DB enabled sends the virtual network and subnet identity to Azure Cosmos DB accounts. These requests don't have the public IP of the source, so IP filters reject them. To allow access from specific subnets in virtual networks, add an access control list as outlined in [How to configure virtual network and subnet-based access for your Azure Cosmos DB account](how-to-configure-vnet-service-endpoint.md). It can take up to 15 minutes for firewall rules to apply.
186177

187178
## Next steps
188179

189180
To configure a virtual network service endpoint for your Azure Cosmos DB account, see the following articles:
190181

191182
* [Virtual network and subnet access control for your Azure Cosmos DB account](vnet-service-endpoint.md)
192183
* [Configure virtual network and subnet-based access for your Azure Cosmos DB account](how-to-configure-vnet-service-endpoint.md)
193-

0 commit comments

Comments
 (0)