Edit

Tutorial: Restrict network access to PaaS resources with virtual network service endpoints

Virtual network service endpoints enable you to limit network access to some Azure service resources to a virtual network subnet. You can also remove internet access to the resources. Service endpoints provide direct connection from your virtual network to supported Azure services, allowing you to use your virtual network's private address space to access the Azure services. Traffic destined to Azure resources through service endpoints always stays on the Microsoft Azure backbone network.

Diagram of Azure resources created in tutorial.

In this tutorial, you learn how to:

  • Create a virtual network with one subnet
  • Add a subnet and enable a service endpoint
  • Create an Azure resource and allow network access to it from only a subnet
  • Deploy a virtual machine (VM) to each subnet
  • Confirm access to a resource from a subnet
  • Confirm access is denied to a resource from a subnet and the internet

Prerequisites

Create a resource group

  1. Sign in to the Azure portal.

  2. In the search box at the top of the portal, enter Resource group. Select Resource groups in the search results.

  3. Select + Create.

  4. In the Basics tab of Create a resource group, enter, or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Enter test-rg.
    Region Select East US 2.
  5. Select Review + create.

  6. Select Create.

Create a virtual network

  1. In the search box at the top of the portal, enter Virtual network. Select Virtual networks in the search results.

  2. Select + Create.

  3. On the Basics tab of Create virtual network, enter, or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Name Enter vnet-1.
    Region Select East US 2.
  4. Select Next to proceed to the Security tab.

  5. Select Next to proceed to the IP Addresses tab.

  6. In the address space box in Subnets, select the default subnet.

  7. In Edit subnet, enter, or select the following information:

    Setting Value
    Subnet details
    Subnet template Leave the default Default.
    Name Enter subnet-1.
    Starting address Leave the default of 10.0.0.0.
    Subnet size Leave the default of /24 (256 addresses).
  8. Select Save.

  9. Select Review + create at the bottom of the screen, and when validation passes, select Create.

Deploy Azure Bastion

Azure Bastion uses your browser to connect to VMs in your virtual network over secure shell (SSH) or remote desktop protocol (RDP) by using their private IP addresses. The VMs don't need public IP addresses, client software, or special configuration. For more information about Azure Bastion, see Azure Bastion.

Note

Hourly pricing starts from the moment that Bastion is deployed, regardless of outbound data usage. For more information, see Pricing and SKUs. If you're deploying Bastion as part of a tutorial or test, we recommend that you delete this resource after you finish using it.

  1. In the search box at the top of the portal, enter Bastion. Select Bastions in the search results.

  2. Select + Create.

  3. In the Basics tab of Create a Bastion, enter, or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Name Enter bastion.
    Region Select East US 2.
    Tier Select Developer.
    Configure virtual networks
    Virtual network Select vnet-1.
  4. Select Review + create.

  5. Select Create.

Enable a service endpoint

Service endpoints are enabled per service, per subnet.

  1. In the search box at the top of the portal page, search for Virtual network. Select Virtual networks in the search results.

  2. In Virtual networks, select vnet-1.

  3. In the Settings section of vnet-1, select Subnets.

  4. Select + Subnet.

  5. On the Add subnet page, enter, or select the following information:

    Setting Value
    Name subnet-private
    Subnet address range Leave the default of 10.0.2.0/24.
    SERVICE ENDPOINTS
    Services Select Microsoft.Storage
  6. Select Save.

Caution

Before enabling a service endpoint for an existing subnet that has resources in it, see Change subnet settings.

Restrict network access for a subnet

By default, all virtual machine instances in a subnet can communicate with any resources. You can limit communication to and from all resources in a subnet by creating a network security group, and associating it to the subnet.

  1. In the search box at the top of the portal page, search for Network security group. Select Network security groups in the search results.

  2. In Network security groups, select + Create.

  3. In the Basics tab of Create network security group, enter, or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Name Enter nsg-storage.
    Region Select East US 2.
  4. Select Review + create, then select Create.

Create outbound Network Security Group (NSG) rules

  1. In the search box at the top of the portal page, search for Network security group. Select Network security groups in the search results.

  2. Select nsg-storage.

  3. Select Outbound security rules in Settings.

  4. Select + Add.

  5. Create a rule that allows outbound communication to the Azure Storage service. Enter or select the following information in Add outbound security rule:

    Setting Value
    Source Select Service Tag.
    Source service tag Select VirtualNetwork.
    Source port ranges Leave the default of *.
    Destination Select Service Tag.
    Destination service tag Select Storage.
    Service Leave default of Custom.
    Destination port ranges Enter 445.
    Protocol Select Any.
    Action Select Allow.
    Priority Leave the default of 100.
    Name Enter allow-storage-all.
  6. Select + Add.

  7. Create another outbound security rule that denies communication to the internet. This rule overrides a default rule in all network security groups that allows outbound internet communication. Complete the previous steps with the following values in Add outbound security rule:

    Setting Value
    Source Select Service Tag.
    Source service tag Select VirtualNetwork.
    Source port ranges Leave the default of *.
    Destination Select Service Tag.
    Destination service tag Select Internet.
    Service Leave default of Custom.
    Destination port ranges Enter *.
    Protocol Select Any.
    Action Select Deny.
    Priority Leave the default 110.
    Name Enter deny-internet-all.
  8. Select Add.

  9. In the search box at the top of the portal page, search for Network security group. Select Network security groups in the search results.

  10. Select nsg-storage.

  11. Select Subnets in Settings.

  12. Select + Associate.

  13. In Associate subnet, select vnet-1 in Virtual network. Select subnet-private in Subnet.

  14. Select OK.

Restrict network access to a resource

The steps required to restrict network access to resources created through Azure services, which are enabled for service endpoints vary across services. See the documentation for individual services for specific steps for each service. The rest of this tutorial includes steps to restrict network access for an Azure Storage account, as an example.

Create a storage account

  1. In the search box at the top of the portal, enter Storage account. Select Storage accounts in the search results.

  2. Select + Create.

  3. On the Basics tab of Create a storage account, enter, or select the following information:

    Setting Value
    Project Details
    Subscription Select your Azure subscription.
    Resource Group Select test-rg.
    Instance details
    Storage account name Enter a unique name. This tutorial uses storage1. If the name is unavailable, enter a unique name.
    Location Select (US) East US 2.
    Performance Leave the default Standard.
    Redundancy Select Locally-redundant storage (LRS).
  4. Select Review.

  5. Select Create.

Important

Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.

For more information about connecting to a storage account using a managed identity, see Use a managed identity to access Azure Storage.

Create a file share in the storage account

  1. In the search box at the top of the portal, enter Storage account. Select Storage accounts in the search results.

  2. In Storage accounts, select the storage account you created in the previous step.

  3. In Data storage, select File shares.

  4. Select + File share.

  5. Enter or select the following information in New file share:

    Setting Value
    Name Enter file-share.
    Tier Leave the default of Transaction optimized.
  6. Select Next: Backup.

  7. Deselect Enable backup.

  8. Select Review + create, then select Create.

Restrict network access to a subnet

By default, storage accounts accept network connections from clients in any network, including the internet. You can restrict network access from the internet, and all other subnets in all virtual networks (except the subnet-private subnet in the vnet-1 virtual network.)

To restrict network access to a subnet:

  1. In the search box at the top of the portal, enter Storage account. Select Storage accounts in the search results.

  2. Select your storage account.

  3. In Security + networking, select Networking.

  4. In the Firewalls and virtual networks tab, select Enabled from selected virtual networks and IP addresses in Public network access.

  5. In Virtual networks, select + Add existing virtual network.

  6. In Add networks, enter or select the following information:

    Setting Value
    Subscription Select your subscription.
    Virtual networks Select vnet-1.
    Subnets Select subnet-private.

    Screenshot of restriction of storage account to the subnet and virtual network created previously.

  7. Select Add.

  8. Select Save to save the virtual network configurations.

Deploy virtual machines to subnets

To test network access to a storage account, deploy a virtual machine to each subnet.

Create the first virtual machine

  1. In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.

  2. Select + Create then Azure virtual machine.

  3. In Create a virtual machine enter, or select the following information in the Basics tab:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Virtual machine name Enter vm-1.
    Region Select (US) East US 2.
    Availability options Select No infrastructure redundancy required.
    Security type Select Standard.
    Image Select Ubuntu Server 24.04 LTS - x64 Gen2.
    VM architecture Leave the default of x64.
    Size Select a size.
    Administrator account
    Authentication type Select SSH public key.
    Username Enter a username.
    SSH public key source Select Generate new key pair.
    Key pair name Enter vm-1-key.
    Inbound port rules
    Public inbound ports Select None.
  4. Select Next: Disks then Next: Networking.

  5. In the Networking tab, enter, or select the following information:

    Setting Value
    Network interface
    Virtual network Select vnet-1.
    Subnet Select subnet-1 (10.0.0.0/24).
    Public IP Select None.
    Network interface (NIC) network security group Select Advanced.
    Configure network security group Select Create new.
    In Name enter nsg-1.
    Select OK.
  6. Leave the rest of the options at the defaults and select Review + create.

  7. Select Create.

Note

Virtual machines in a virtual network with a bastion host don't need public IP addresses. Bastion provides the public IP, and the VMs use private IPs to communicate within the network. You can remove the public IPs from any VMs in bastion hosted virtual networks. For more information, see Dissociate a public IP address from an Azure VM.

Note

Azure provides a default outbound access IP for VMs that either aren't assigned a public IP address or are in the backend pool of an internal basic Azure load balancer. The default outbound access IP mechanism provides an outbound IP address that isn't configurable.

The default outbound access IP is disabled when one of the following events happens:

  • A public IP address is assigned to the VM.