Hello Quincy
Unless specific firewall rules have been set, adding a private endpoint makes your Azure Cosmos DB account accessible through private endpoints only. This means that the Azure Cosmos DB account could be reached from public traffic after it's created and before a private endpoint gets added.
To fix 403 error You need to Configure the service endpoint for the Azure virtual network and subnet. You can do it in Cosmos DB settings' Firewall and virtual networks
option.
- Select Firewalls and virtual networks from the settings menu, and choose to allow access from Selected networks.
- To grant access to an existing virtual network's subnet, under Virtual networks, select Add existing Azure virtual network.
- Select the Subscription from which you want to add an Azure virtual network. Select the Azure Virtual networks and Subnets that you want to provide access to your Azure Cosmos DB account. Next, select Enable to enable selected networks with service endpoints for "Microsoft.AzureCosmosDB". When it's complete, select Add. Refer below image.
- After the Azure Cosmos DB account is enabled for access from a virtual network, it will allow traffic from only this chosen subnet. The virtual network and subnet that you added should appear as shown in the following screenshot: https://stackoverflow.com/questions/71639169/request-originated-from-vnet-through-service-endpoint-this-is-blocked-by-your-c
The following situations and outcomes are possible when you use Private Link in combination with firewall rules:
- If you don't configure any firewall rules, then by default, all traffic can access an Azure Cosmos DB account.
- If you configure public traffic or a service endpoint and you create private endpoints, then different types of incoming traffic are authorized by the corresponding type of firewall rule. If a private endpoint is configured in a subnet where service endpoint is also configured:
- traffic to the database account mapped by the private endpoint is routed via private endpoint,
- traffic to other database accounts from the subnet is routed via service endpoint.
- If you don't configure any public traffic or service endpoint and you create private endpoints, then the Azure Cosmos DB account is accessible only through the private endpoints. If you don't configure public traffic or a service endpoint, after all approved private endpoints are rejected or deleted, the account is open to the entire network unless
PublicNetworkAccess
is set to Disabled.
https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/troubleshoot-forbidden