Lau
Lau

Reputation: 1465

Do NSGs apply to Servic Endpoints of the Subnet

I created a Subnet, where I connect a Cosmos DB as Service Endpoint. Besides the IP firewall of the Cosmos DB I want to control the Outbound via NSG rules. However if I create a rule, that denies all Outbound (also tested with deny all Inbound) it seems to have to effect, when connecting to the DB via the Mongo client.

Is this expected behaviour ?

Upvotes: 0

Views: 1433

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28284

Yes, It's expected behavior when access the Cosmos DB from service endpoint enabled VNet. Here are two points in your question:

  • The NSG can be associated with a subnet or network interface level. In this case, when an NSG is associated with a subnet, the rules apply to all resources connected to the subnet. If a subnet NSG has a matching rule that denies traffic, packets are dropped, even if a VM\NIC NSG has a matching rule that allows traffic. Read here1 and here2.

enter image description here

  • When you enable a Cosmos DB as Service Endpoint in a VNet, it will extend your virtual network private address space and the identity of your VNet to the Azure services, over a direct connection. Traffic from your VNet to the Azure service always remains on the Microsoft Azure backbone network.

    Today, Azure service traffic from a virtual network uses public IP addresses as source IP addresses. With service endpoints, service traffic switches to use virtual network private addresses as the source IP addresses when accessing the Azure service from a virtual network. This switch allows you to access the services without the need for reserved, public IP addresses used in IP firewalls.

So, if you are accessing the Cosmos DB from a VNet, it will use the private IP address in that VNet to access the Azure Cosmos DB service. If you are accessing the Cosmos DB outside of Azure, you will be restrcited by the firewall IP address of the Cosmos DB.

Upvotes: 2

Related Questions