Configuring Networking for Azure function app - azure

I created Azure function app and Azure function, I am able to hit the Azure with default URL from internet.
I want to restrict access to my function so that it can be accessed only from the specified vnet/subnet
If I configure the Networking for the function (Function app ->network-> Access restriction ) with allow access , source setting of subscription , vnet/subnet , I am getting 403 error (forbidden).
Please suggest the work around/correct way to configure Azure function app
Thanks
Ramabadran

To access the Function App within the Virtual Network defined:
Created the Function App in Consumption Plan.
Created the Virtual Machine in the Same location of Function Ap and allowed the Ports 3389 (for Testing purpose) and HTTPS in the VM Networking.
In Azure Portal Function App, Menu > Networking > Access Restrictions > Click on Add Rule >
Priority: 200
Name: AllowVNetSource
Type: Virtual Network / default subnet
Go to the VM > Disable Firewall > Access the HTTP Trigger Function URL:
To access the function app out of the VNet, add the IP range or IP address as shown in the Rule 100 (1st Image):
If it is accessed out of the specified Subnet or IP Range, then it will be resulted in 403-forbidden as shown below:

Related

How to access restrict a Http Azure Function from another

I have a Http trigged Azure Function App on resource group A, and I need to invoke this one from another Azure Function app on a resource group B.
I've tried Networking > Access Restrictions
I got the Azure Function ( resource group B) ip address from Settings > Properties
Back on the first Azure Function ( resource group A) and set this ip address on Access Restrictions as allowed
But I'm facing 403 Forbidden warning
[Information] StatusCode: 403, ReasonPhrase: 'Ip Forbidden', Version: 1.1
Have anyone a idea how can I restrict the first AF?
Azure Function outbound can use multiple ips.
You can get that list in Settings > Properties.
You must whitelist at least the Outbound IP addresses list
If you plan to scale your function app, you must whitelist the Additional Outbound IP Addresses
Another solution is to use a Service tag in the Access Restrictions of the Function
https://learn.microsoft.com/en-us/azure/virtual-network/service-tags-overview
The service tag for this scenario is AppService. This service can be regional, so you may use AppService.your-region
None of this solution will ensure that only function B can call function A. To have a single public IP to whitelist, you should use a Nat Gateway, to ensure all outbound traffic use the same public IP.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-nat-gateway
(the documentation is not up to date, a premium plan is no longer required)

Azure function: Detected host offline in your function app

We have an Azure Function that is integrated with VNET. Function uses Key Vault to read configuration values from. MSI has been enabled on function and access policy is added in the KV to allow function to access it. Traffic to Key Vault is restricted to be allowed from the said VNET. We have received this error in the diagnostics yesterday, which has affected our execution flow. The App was offline for a few minutes resulting in failures. This is what the diagnostic report says:
Detected host offline in your function app.
Description
A host error has occurred during startup operation 'd732fccb-40ae-40a1-8d14-ea3cdba0e725'.
Last offline at
5/4/2021 10:32:13 AM
Details
Microsoft.Azure.KeyVault.Models.KeyVaultErrorException : Client address is not authorized and caller is not a trusted service.
Client address: x.x.x.x
The function started working properly after being down for about 4 minutes. This could be an issue with VNET integration.
Has anyone encountered this? Is there any way to prevent this?
In this case, you could add the application settings WEBSITE_VNET_ROUTE_ALL = 1 of your azure function, this will force all outbound traffic from your azure function into that VNet.
When you route all of your outbound traffic into your VNet, it's
subject to the NSGs and UDRs that are applied to your integration
subnet. When WEBSITE_VNET_ROUTE_ALL is set to 1, outbound traffic is
still sent from the addresses that are listed in your app properties,
unless you provide routes that direct the traffic elsewhere.
Reference from https://learn.microsoft.com/en-us/azure/azure-functions/functions-networking-options#regional-virtual-network-integration

Access restricted Azure App Service returns "Error 403 - This web app is stopped"

I have two Allow rules in Access Restrictions for the API web app, the corporate network and the VNET subnet with a VM used for development. The API published to the App Service works as expected from the corporate network but returns Error 403 - This web app is stopped" when called from the VM.
I double checked the rule and the subnet in the rule (x.x.x.0/24) correctly reflects the VM's subnet.
What could cause this?
The VM is most likely using a public IP address to talk with the App Service, not its private IP address.
The request would need to be routed through the VM's VNET to the App Service in order for the private address to be used.
You could add the VM subnet instead of a private CIDR range x.x.x.0/24 in the rules of Access Restrictions for the API web app. You should enable service endpoints on both the networking side as well as the service that it is being enabled with. If service endpoints are not already enabled with Microsoft.Web for the subnet that you selected, it will automatically be enabled for you unless you check the box asking not to do that.
When you finish it, you will find a virtual network/subnet as the source of the rule.
For more reference, you could get Azure App Service Access Restrictions.

Azure functions : Getting 403 error while accessing the storage account

I have been using azure timer based function in my project.
Since I started using the function, I was getting error 403 related to access forbidden from Azure storage account.
I tried adding AzureWebJobsStorage Key in function's configuration
I tried adding outbound IPs of Allowed ip ranges of azure storage accounts
I tried checking the option of allowing azure managed services to the storage account.
However, I'm still getting the error in that particular timer function of my function app. The other functions run properly.
Although, if I allow all the networks in storage account firewall and VN settings, my function runs proper.
Both the function and storage account are in same region.
I want to enable it somehow that I do not need to choose the allow all networks. What can be done?
In case anyone else is searching for this... I had a similar issue. I had a function app that I had created a private endpoint and regional VNet integration back with the VNet interacting with a Storage Account that also had a private endpoint with the same VNet. The Storage Account's network/firewall settings only allowed connections from the VNet (no external traffic allowed). Both the storage account and function app reside in the same region.
Attempt at fix #1 (not ideal):
I added code to determine what IP the function app was running from. That led me to add all of the IP's in the portal under function app --> Properties --> Additional Outbound IP Addresses. This is exposed by Terraform if using that.
Attempt at fix #2 (better):
The resolution is to ensure you have the proper function app settings set.
See: Microsoft documentation
Setting
Suggested value
Description
WEBSITE_CONTENTOVERVNET
1
Create this app setting. A value of 1 enables your function app to scale when your storage account is restricted to a virtual network.
WEBSITE_DNS_SERVER
168.63.129.16
Create this app setting. When your app integrates with a virtual network, it will use the same DNS server as the virtual network. Your function app needs this setting so it can work with Azure DNS private zones. It's required when you use private endpoints. This setting and WEBSITE_VNET_ROUTE_ALL will send all outbound calls from your app into your virtual network.
WEBSITE_VNET_ROUTE_ALL
1
Create this app setting. When your app integrates with a virtual network, it uses the same DNS server as the virtual network. Your function app needs this setting so it can work with Azure DNS private zones. It's required when you use private endpoints. This setting and WEBSITE_DNS_SERVER will send all outbound calls from your app into your virtual network.
Note: The 168.63.129.16 is a static value for Azure DNS.
After setting all of these, my function app was able to connect to the storage account through the VNet as expected.
There're already some answers about this issue, you can see here and here.
In short, if the function and storage account are in same region, they communicate in an internal way without going through outboundIpAddresses.
The workaround is that create them in different regions.

Azure API Management and Function Apps

I am trying to set up a new environment on azure.
The main idea is to have multiple Function Apps accessible only using API Management, so Im trying to set apps restriction to only Virtual Network.
I've done:
created Virtual Network with default subnet with address space 192.168.0.0/24
created APIM with Virtual Network set to External and connected to that VNet I've created
created Function apps within ConsumptionPlan with IP restriction only from the created VNet
imported APIs from Functions to APIM
set up AAD login
Now when I try to access some function endpoint directly (using the URL of the function app), it throws me 403 error, what is fine. When I call some endpoint using APIM, it redirects me to the function app URL and throws me 403 again. When I add my IP to allowed list of the function, I can connect, but also directly using function URL.
My idea was to have accessible e.g. https://apim.azure-api.net/endpoint-url and not directly https://functionapp.azurewebsites.net/endpoint-url (only using APIM)
Any ideas how could I proceed with this?

Resources