Tutorial: Inspect private endpoint traffic with Azure Firewall

Azure Private Endpoint is the fundamental building block for Azure Private Link. Private endpoints enable Azure resources deployed in a virtual network to communicate privately with private link resources.

Private endpoints allow resources access to the private link service deployed in a virtual network. Access to the private endpoint through virtual network peering and on-premises network connections extend the connectivity.

You may need to inspect or block traffic from clients to the services exposed via private endpoints. Complete this inspection by using Azure Firewall or a third-party network virtual appliance.

For more information and scenarios that involve private endpoints and Azure Firewall, see Azure Firewall scenarios to inspect traffic destined to a private endpoint.

Diagram of Azure resources created in tutorial.

In this tutorial, you learn how to:

  • Create a virtual network and bastion host for the test virtual machine.
  • Create the private endpoint virtual network.
  • Create a test virtual machine.
  • Deploy Azure Firewall.
  • Create an Azure SQL database.
  • Create a private endpoint for Azure SQL.
  • Create a network peer between the private endpoint virtual network and the test virtual machine virtual network.
  • Link the virtual networks to a private DNS zone.
  • Configure application rules in Azure Firewall for Azure SQL.
  • Route traffic between the test virtual machine and Azure SQL through Azure Firewall.
  • Test the connection to Azure SQL and validate in Azure Firewall logs.

If you don't have an Azure subscription, create a free account before you begin.

Prerequisites

Sign in to the Azure portal

Sign in to the Azure portal.

Create a virtual network and an Azure Bastion host

The following procedure creates a virtual network with a resource subnet, an Azure Bastion subnet, and a Bastion host:

  1. In the portal, search for and select Virtual networks.

  2. On the Virtual networks page, 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 Create new.
    Enter test-rg for the name.
    Select OK.
    Instance details
    Name Enter vnet-1.
    Region Select East US 2.

    Screenshot of the Basics tab for creating a virtual network in the Azure portal.

  4. Select Next to proceed to the Security tab.

  5. In the Azure Bastion section, select Enable Azure Bastion.

    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, see What is 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.

  6. In Azure Bastion, enter or select the following information:

    Setting Value
    Azure Bastion host name Enter bastion.
    Azure Bastion public IP address Select Create a public IP address.
    Enter public-ip-bastion in Name.
    Select OK.

    Screenshot of options for enabling an Azure Bastion host as part of creating a virtual network in the Azure portal.

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

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

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

    Setting Value
    Subnet purpose Leave the default of Default.
    Name Enter subnet-1.
    IPv4
    IPv4 address range Leave the default of 10.0.0.0/16.
    Starting address Leave the default of 10.0.0.0.
    Size Leave the default of /24 (256 addresses).

    Screenshot of configuration details for a subnet.

  10. Select Save.

  11. Select Review + create at the bottom of the window. When validation passes, select Create.

Create a virtual network for a private endpoint

The following procedure creates a virtual network with a subnet.

  1. In the portal, search for and select Virtual networks.

  2. On the Virtual networks page, 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-private-endpoint.
    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. Select Delete address space with the trash can icon to remove the default address space.

  7. Select Add IPv4 address space.

  8. Enter 10.1.0.0 and leave the pull-down box at the default of /16 (65,536 addresses).

  9. Select + Add a subnet.

  10. In Add a subnet, enter or select the following information:

    Setting Value
    Subnet details
    Subnet template Leave the default Default.
    Name Enter subnet-private.
    Starting address Leave the default of 10.1.0.0.
    Subnet size Leave the default of /24(256 addresses).
  11. Select Add.

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

Create test virtual machine

The following procedure creates a test virtual machine (VM) named vm-1 in the virtual network.

  1. In the portal, search for and select Virtual machines.

  2. In Virtual machines, select + Create, then Azure virtual machine.

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

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Virtual machine name Enter vm-1.
    Region Select East US 2.
    Availability options Select No infrastructure redundancy required.
    Security type Leave the default of Standard.
    Image Select Ubuntu Server 22.04 LTS - x64 Gen2.
    VM architecture Leave the default of x64.
    Size Select a size.
    Administrator account
    Authentication type Select Password.
    Username Enter azureuser.
    Password Enter a password.
    Confirm password Reenter the password.
    Inbound port rules
    Public inbound ports Select None.
  4. Select the Networking tab at the top of the page.

  5. Enter or select the following information in the Networking tab:

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

  7. Review the settings and 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.
  • The VM is placed in the backend pool of a standard load balancer, with or without outbound rules.
  • An Azure NAT Gateway resource is assigned to the subnet of the VM.

VMs that you create by using virtual machine scale sets in flexible orchestration mode don't have default outbound access.

For more information about outbound connections in Azure, see Default outbound access in Azure and Use Source Network Address Translation (SNAT) for outbound connections.

Deploy Azure Firewall

  1. In the search box at the top of the portal, enter Firewall. Select Firewalls in the search results.

  2. In Firewalls, select + Create.

  3. Enter or select the following information in the Basics tab of Create a firewall:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Name Enter firewall.
    Region Select East US 2.
    Availability zone Select None.
    Firewall SKU Select Standard.
    Firewall management Select Use a Firewall Policy to manage this firewall.
    Firewall policy Select Add new.
    Enter firewall-policy in Policy name.
    Select East US 2 in region.
    Select OK.
    Choose a virtual network Select Create new.
    Virtual network name Enter vnet-firewall.
    Address space Enter 10.2.0.0/16.
    Subnet address space Enter 10.2.1.0/26.
    Public IP address Select Add new.
    Enter public-ip-firewall in Name.
    Select OK.
  4. Select Review + create.

  5. Select Create.

Wait for the firewall deployment to complete before you continue.

Enable firewall logs

In this section, you enable the firewall logs and send them to the log analytics workspace.

Note

You must have a log analytics workspace in your subscription before you can enable firewall logs. For more information, see Prerequisites.

  1. In the search box at the top of the portal, enter Firewall. Select Firewalls in the search results.

  2. Select firewall.

  3. In Monitoring select Diagnostic settings.

  4. Select + Add diagnostic setting.

  5. In Diagnostic setting enter or select the following information:

    Setting Value
    Diagnostic setting name Enter diagnostic-setting-firewall.
    Logs
    Categories Select Azure Firewall Application Rule (Legacy Azure Diagnostics) and Azure Firewall Network Rule (Legacy Azure Diagnostics).
    Destination details
    Destination Select Send to Log Analytics workspace.
    Subscription Select your subscription.
    Log Analytics workspace Select your log analytics workspace.
  6. Select Save.

Create an Azure SQL database

  1. In the search box at the top of the portal, enter SQL. Select SQL databases in the search results.

  2. In SQL databases, select + Create.

  3. In the Basics tab of Create SQL Database, enter or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Database details
    Database name Enter sql-db.
    Server Select Create new.
    Enter server-name in Server name (Server names must be unique, replace server-name with a unique value).
    Select (US) East US 2 in Location.
    Select Use SQL authentication.
    Enter a server admin sign-in and password.
    Select OK.
    Want to use SQL elastic pool? Select No.
    Workload environment Leave the default of Production.
    Backup storage redundancy
    Backup storage redundancy Select Locally redundant backup storage.
  4. Select Next: Networking.

  5. In the Networking tab of Create SQL Database, enter or select the following information:

    Setting Value
    Network connectivity
    Connectivity method Select Private endpoint.
    Private endpoints
    Select +Add private endpoint.
    Create private endpoint
    Subscription Select your subscription.
    Resource group Select test-rg.
    Location Select East US 2.
    Name Enter private-endpoint-sql.
    Target subresource Select SqlServer.
    Networking
    Virtual network Select vnet-private-endpoint.
    Subnet Select subnet-private-endpoint.
    Private DNS integration
    Integrate with private DNS zone Select Yes.
    Private DNS zone Leave the default of privatelink.database.windows.net.
  6. Select OK.

  7. Select Review + create.

  8. Select Create.

Connect virtual networks with virtual network peering

In this section, you connect the virtual networks with virtual network peering. The networks vnet-1 and vnet-private-endpoint are connected to vnet-firewall. There isn't direct connectivity between vnet-1 and vnet-private-endpoint.

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

  2. Select vnet-firewall.

  3. In Settings select Peerings.

  4. In Peerings select + Add.

  5. In Add peering, enter or select the following information:

    Setting Value
    This virtual network
    Peering link name Enter vnet-firewall-to-vnet-1.
    Traffic to remote virtual network Select Allow (default).
    Traffic forwarded from remote virtual network Select Allow (default).
    Virtual network gateway or Route Server Select None (default).
    Remote virtual network
    Peering link name Enter vnet-1-to-vnet-firewall.
    Virtual network deployment model Select Resource manager.
    Subscription Select your subscription.
    Virtual network Select vnet-1.
    Traffic to remote virtual network Select Allow (default).
    Traffic forwarded from remote virtual network Select Allow (default).
    Virtual network gateway or Route Server Select None (default).
  6. Select Add.

  7. In Peerings select + Add.

  8. In Add peering, enter or select the following information:

    Setting Value
    This virtual network
    Peering link name Enter vnet-firewall-to-vnet-private-endpoint.
    Allow 'vnet-1' to access 'vnet-private-endpoint' Leave the default of selected.
    Allow 'vnet-1' to receive forwarded traffic from 'vnet-private-endpoint' Select the checkbox.
    Allow gateway in 'vnet-1' to forward traffic to 'vnet-private-endpoint' Leave the default of cleared.
    Enable 'vnet-1' to use 'vnet-private-endpoint' remote gateway Leave the default of cleared.
    Remote virtual network
    Peering link name Enter vnet-private-endpoint-to-vnet-firewall.
    Virtual network deployment model Select Resource manager.
    Subscription Select your subscription.
    Virtual network Select vnet-private-endpoint.
    Allow 'vnet-private-endpoint' to access 'vnet-1' Leave the default of selected.
    Allow 'vnet-private-endpoint' to receive forwarded traffic from 'vnet-1' Select the checkbox.
    Allow gateway in 'vnet-private-endpoint' to forward traffic to 'vnet-1' Leave the default of cleared.
    Enable 'vnet-private-endpoint' to use 'vnet-1's' remote gateway Leave the default of cleared.
  9. Select Add.

  10. Verify the Peering status displays Connected for both network peers.

The private DNS zone created during the private endpoint creation in the previous section must be linked to the vnet-1 and vnet-firewall virtual networks.

  1. In the search box at the top of the portal, enter Private DNS zone. Select Private DNS zones in the search results.

  2. Select privatelink.database.windows.net.

  3. In Settings select Virtual network links.

  4. Select + Add.

  5. In Add virtual network link, enter or select the following information:

    Setting Value
    Virtual network link
    Virtual network link name Enter link-to-vnet-1.
    Subscription Select your subscription.
    Virtual network Select vnet-1 (test-rg).
    Configuration Leave the default of unchecked for Enable auto registration.
  6. Select OK.

  7. Select + Add.

  8. In Add virtual network link, enter or select the following information:

    Setting Value
    Virtual network link
    Virtual network link name Enter link-to-vnet-firewall.
    Subscription Select your subscription.
    Virtual network Select vnet-firewall (test-rg).
    Configuration Leave the default of unchecked for Enable auto registration.
  9. Select OK.

Create route between vnet-1 and vnet-private-endpoint

A network link between vnet-1 and vnet-private-endpoint doesn't exist. You must create a route to allow traffic to flow between the virtual networks through Azure Firewall.

The route sends traffic from vnet-1 to the address space of virtual network vnet-private-endpoint, through the Azure Firewall.

  1. In the search box at the top of the portal, enter Route tables. Select Route tables in the search results.

  2. Select + Create.

  3. In the Basics tab of Create Route table, enter or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select test-rg.
    Instance details
    Region Select East US 2.
    Name Enter vnet-1-to-vnet-firewall.
    Propagate gateway routes Leave the default of Yes.
  4. Select Review + create.

  5. Select Create.

  6. In the search box at the top of the portal, enter Route tables. Select Route tables in the search results.

  7. Select vnet-1-to-vnet-firewall.

  8. In Settings select Routes.

  9. Select + Add.

  10. In Add route, enter or select the following information:

    Setting Value
    Route name Enter subnet-1-to-subnet-private-endpoint.
    Destination type Select IP Addresses.
    Destination IP addresses/CIDR ranges Enter 10.1.0.0/16.
    Next hop type Select Virtual appliance.
    Next hop address Enter 10.2.1.4.
  11. Select Add.

  12. In Settings, select Subnets.

  13. Select + Associate.

  14. In Associate subnet, enter or select the following information:

    Setting Value
    Virtual network Select vnet-1(test-rg).
    Subnet Select subnet-1.
  15. Select OK.

Configure an application rule in Azure Firewall

Create an application rule to allow communication from vnet-1 to the private endpoint of the Azure SQL server server-name.database.windows.net. Replace server-name with the name of your Azure SQL server.

  1. In the search box at the top of the portal, enter Firewall. Select Firewall Policies in the search results.

  2. In Firewall Policies, select firewall-policy.

  3. In Settings select Application rules.

  4. Select + Add a rule collection.

  5. In Add a rule collection, enter or select the following information:

    Setting Value
    Name Enter rule-collection-sql.
    Rule collection type Leave the selection of Application.
    Priority Enter 100.
    Rule collection action Select Allow.
    Rule collection group Leave the default of DefaultApplicationRuleCollectionGroup.
    Rules
    Rule 1
    Name Enter SQLPrivateEndpoint.
    Source type Select IP Address.
    Source Enter 10.0.0.0/16
    Protocol Enter mssql:1433
    Destination type Select FQDN.
    Destination Enter server-name.database.windows.net.
  6. Select Add.

Test connection to Azure SQL from 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 vm-1.

  3. In Operations select Bastion.

  4. Enter the username and password for the virtual machine.

  5. Select Connect.

  6. To verify name resolution of the private endpoint, enter the following command in the terminal window:

    nslookup server-name.database.windows.net
    

    You receive a message similar to the following example. The IP address returned is the private IP address of the private endpoint.

    Server:    127.0.0.53
    Address:   127.0.0.53#53
    
    Non-authoritative answer:
    sql-server-8675.database.windows.netcanonical name = sql-server-8675.privatelink.database.windows.net.
    Name:sql-server-8675.privatelink.database.windows.net
    Address: 10.1.0.4
    
  7. Install the SQL server command line tools from Install the SQL Server command-line tools sqlcmd and bcp on Linux. Proceed with the next steps after the installation is complete.

  8. Use the following commands to connect to the SQL server you created in the previous steps.

    • Replace <server-admin> with the admin username you entered during the SQL server creation.

    • Replace <admin-password> with the admin password you entered during SQL server creation.

    • Replace server-name with the name of your SQL server.

    sqlcmd -S server-name.database.windows.net -U '<server-admin>' -P '<admin-password>'
    
  9. A SQL command prompt is displayed on successful sign in. Enter exit to exit the sqlcmd tool.

Validate traffic in the Azure Firewall logs

  1. In the search box at the top of the portal, enter Log Analytics. Select Log Analytics in the search results.

  2. Select your log analytics workspace. In this example, the workspace is named log-analytics-workspace.

  3. In the General settings, select Logs.

  4. In the example Queries in the search box, enter Application rule. In the returned results in Network, select the Run button for Application rule log data.

  5. In the log query output, verify server-name.database.windows.net is listed under FQDN and SQLPrivateEndpoint is listed under Rule.

When you finish using the resources that you created, you can delete the resource group and all its resources.

  1. In the Azure portal, search for and select Resource groups.

  2. On the Resource groups page, select the test-rg resource group.

  3. On the test-rg page, select Delete resource group.

  4. Enter test-rg in Enter resource group name to confirm deletion, and then select Delete.

Next steps

Advance to the next article to learn how to use a private endpoint with Azure Private Resolver: