I'm trying to secure an application, deployed in Azure, consisting of an Angular frontend and a Node (Nest.js) backend. I want the frontend to be accessible via the internet unlike the backend which should only be accessible from the frontend (without being accessible via the internet). The backend seems to restrict access by taking the client's IP instead of the frontend's IP which causes a 403 IP Forbidden error.
In summary (version with path to Bicep file below)
To do this, I created:
And I made the following configuration:
Results
On my frontend, I make an HTTP request to my backend API. The backend responds to me ERR_FAILED 403 (Ip Forbidden). In the response headers, I see "x-ms-forbidden-ip: xxx.xxx.xx.xx" (the public ip of my company's network that my PC is on). See here. Shouldn't I see my frontend App Service IP?
For Information, if in App Service backend > Networking > Access restriction, I add a rule authorizing the public IP of my company, the request returns me a code 200 and no longer 403.
How do I block public access to the backend but still manage to perform requests from the frontend? (After many research, I haven't found any successful answers to solve this yet).
Version with Bicep file
I followed this tutorial. At the end of the article, a Bicep file is available.
So I did the following:
az group create --name SecureNTierApp --location "France Central"
az deployment group create --name DeployementSecureNTierApp --resource-group SecureNTierApp --template-file <file-name>.bicep
az resource update --resource-group SecureNTierApp --name scm --namespace Microsoft.Web --resource-type basicPublishingCredentialsPolicies --parent sites/<frontend-name> --set properties.allow=true
az resource update --resource-group SecureNTierApp --name scm --namespace Microsoft.Web --resource-type basicPublishingCredentialsPolicies --parent sites/<backend-name> --set properties.allow=true
From what I see you have your Azure environment set up correctly. I suspect the code in your Angular frontend is asking your web browser to make direct calls to the backend. You probably want your browser to make calls to the front end, which will then be routed or passed on to the back end.
You can confirm the current behavior by running Wireshark on the machine you're using your browser to access the website. You'll see traffic going to your backend IPs.