|
| 1 | +--- |
| 2 | +title: Configure service firewall rules |
| 3 | +description: Configure IP rules to enable access to an Azure container registry from selected public IP addresses or address ranges. |
| 4 | +ms.topic: article |
| 5 | +ms.date: 05/04/2020 |
| 6 | +--- |
| 7 | + |
| 8 | +# Configure public IP network rules |
| 9 | + |
| 10 | +An Azure container registry by default accepts connections over the internet from hosts on any network. This article shows how to configure your container registry to allow access from only specific public IP addresses or address ranges. Equivalent steps using the Azure CLI and Azure portal are provided. |
| 11 | + |
| 12 | +IP network rules are configured on the public registry endpoint. IP network rules do not apply to private endpoints configured with [Private Link](container-registry-private-link.md) |
| 13 | + |
| 14 | +Configuring IP access rules is available in the **Premium** container registry service tier. For information about registry service tiers and limits, see [Azure Container Registry tiers](container-registry-skus.md). |
| 15 | + |
| 16 | +## Access from selected public network - CLI |
| 17 | + |
| 18 | +### Change default network access to registry |
| 19 | + |
| 20 | +To limit access to a selected public network, first change the default action to deny access. Substitute the name of your registry in the following [az acr update][az-acr-update] command: |
| 21 | + |
| 22 | +```azurecli |
| 23 | +az acr update --name myContainerRegistry --default-action Deny |
| 24 | +``` |
| 25 | + |
| 26 | +### Add network rule to registry |
| 27 | + |
| 28 | +Use the [az acr network-rule add][az-acr-network-rule-add] command to add a network rule to your registry that allows access from a public IP address or range. For example, substitute the container registry's name and the public IP address of a VM in a virtual network. |
| 29 | + |
| 30 | +```azurecli |
| 31 | +az acr network-rule add \ |
| 32 | + --name mycontainerregistry \ |
| 33 | + --ip-address <public-IP-address> |
| 34 | +``` |
| 35 | + |
| 36 | +> [!NOTE] |
| 37 | +> After adding a rule, it takes a few minutes for the rule to take effect. |
| 38 | +
|
| 39 | +## Access from selected public network - portal |
| 40 | + |
| 41 | +1. In the portal, navigate to your container registry. |
| 42 | +1. Under **Settings**, select **Networking**. |
| 43 | +1. On the **Public access** tab, select to allow public access from **Selected networks**. |
| 44 | +1. Under **Firewall**, enter a public IP address, such as the public IP address of a VM in a virtual network. Or, enter an address range in CIDR notation that contains the VM's IP address. |
| 45 | +1. Select **Save**. |
| 46 | + |
| 47 | +![Configure firewall rule for container registry][acr-access-selected-networks] |
| 48 | + |
| 49 | +> [!NOTE] |
| 50 | +> After adding a rule, it takes a few minutes for the rule to take effect. |
| 51 | +
|
| 52 | +> [!TIP] |
| 53 | +> Optionally, enable registry access from a local client computer or IP address range. To allow this access, you need the computer's public IPv4 address. You can find this address by searching "what is my IP address" in an internet browser. The current client IPv4 address also appears automatically when you configure firewall settings on the **Networking** page in the portal. |
| 54 | +
|
| 55 | +## Disable public network access |
| 56 | + |
| 57 | +To limit traffic to virtual networks using [Private Link](container-registry-private-link.md), disable the public endpoint on the registry. Disabling the public endpoint overrides all firewall configurations. |
| 58 | + |
| 59 | +### Disable public access - Portal |
| 60 | + |
| 61 | +1. In the portal, navigate to your container registry and select **Settings > Networking**. |
| 62 | +1. On the **Public access** tab, in **Allow public access**, select **Disabled**. Then select **Save**. |
| 63 | + |
| 64 | +![Disable public access][acr-access-disabled] |
| 65 | + |
| 66 | +## Restore default registry access |
| 67 | + |
| 68 | +To restore the registry to allow access by default, update the default action. |
| 69 | + |
| 70 | +### Restore default registry access - portal |
| 71 | + |
| 72 | +1. In the portal, navigate to your container registry and select **Settings > Networking**. |
| 73 | +1. Under **Firewall**, select each address range, and then select the Delete icon. |
| 74 | +1. On the **Public access** tab, in **Allow public access**, select **All networks**. Then select **Save**. |
| 75 | + |
| 76 | +![Public access from all networks][acr-access-all-networks] |
| 77 | + |
| 78 | +## Next steps |
| 79 | + |
| 80 | +* To restrict access to a registry using a private endpoint in a virtual network, see [Configure Azure Private Link for an Azure container registry](container-registry-private-link.md). |
| 81 | +* If you need to set up registry access rules from behind a client firewall, see [Configure rules to access an Azure container registry behind a firewall](container-registry-firewall-access-rules.md). |
| 82 | + |
| 83 | +[az-acr-login]: /cli/azure/acr#az-acr-login |
| 84 | +[az-acr-network-rule-add]: /cli/azure/acr/network-rule/#az-acr-network-rule-add |
| 85 | +[az-acr-network-rule-remove]: /cli/azure/acr/network-rule/#az-acr-network-rule-remove |
| 86 | +[az-acr-network-rule-list]: /cli/azure/acr/network-rule/#az-acr-network-rule-list |
| 87 | +[az-acr-run]: /cli/azure/acr#az-acr-run |
| 88 | +[az-acr-update]: /cli/azure/acr#az-acr-update |
| 89 | +[quickstart-portal]: container-registry-get-started-portal.md |
| 90 | +[quickstart-cli]: container-registry-get-started-azure-cli.md |
| 91 | +[azure-portal]: https://portal.azure.com |
| 92 | + |
| 93 | +[acr-access-selected-networks]: ./media/container-registry-access-selected-networks/acr-access-selected-networks.png |
| 94 | +[acr-access-disabled]: ./media/container-registry-access-selected-networks/acr-access-disabled.png |
| 95 | +[acr-access-all-networks]: ./media/container-registry-access-selected-networks/acr-access-all-networks.png |
0 commit comments