How to access restrict a Http Azure Function from another - azure

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)

Related

Configuring Networking for Azure function app

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:

How can I route outbound traffic from an App Service integrated with a VNet containing a Service Endpoint to an external Azure hosted API?

I'm trying to secure my containerized web app with a Premium V2 App Service Plan. I've enabled Service Endpoints for an integration subnet for the different App Services to restrict incoming traffic from each other except for the frontend (so all of them are integrated with the VNet and all have incoming traffic restricted to that VNet except for the frontend).
I have also other Azure services like Azure Functions or a Storage Account that can have inbound traffic restricted by using those Service Endpoints. However, One of the App Services calls an external 3rd party API that lies on Azure too. That API may or not be behind a static IP. However, it has a Custom Domain associated.
The problem arises when I try to connect to that API from one of the VNet integrated App Services. As the destination IP is inside one of the IP ranges that are added to the routing with the use of a Service Endpoint, traffic is sent via that Service Endpoint instead of simple Azure routing. I've tried overriding the route with a Route Table associated to that subnet but that seems not to be possible, with or without a NAT Gateway attached to the subnet. I guess Azure routing is prioritized here. I'm sure the route is not effective as I used it on a different subnet where I deployed a VM.
Is there any way I can use that Service Endpoint for my internal traffic only so it's not used when it goes to an Azure hosted API or I need to switch to a different approach like Private Endpoints or an ASE?
I am unsure what you're looking for but if you want to explicitly define routes you should try using app services setting "WEBSITE_VNET_ROUTE_ALL" = 1 which overrides the default precedence of routing and makes sure that every outbound call follows the route defined inside route table of subnet.
Use the following steps to add the WEBSITE_VNET_ROUTE_ALL setting in your app:
Go to the Configuration UI in your app portal. Select New application setting.
Enter WEBSITE_VNET_ROUTE_ALL in the Name box, and enter 1 in the Value box.
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.
We've been able to ask the 3rd party to disable blocking rules. It turns out they had a rule that blocked this specific traffic.
I already tried changing that setting, but didn't try putting a route table on it. However, it'd make no difference as I can't define a list of allowed outbound IPs belonging to Azure since we have no static IP to call.

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.

How do I restrict the clients that can access my Azure App Service?

Given that I create an Azure 'App Service'
How do I ensure that this service is only callable from ...
A.> 2 existing external servers (whose IP addresses will be known)
B.> 3 other App Services which I will be creating, but whose IP Addresses may not be known since I may need to scale those out (Over multiple additional instances)
To clarify... Is there some Azure service that will allow me to treat this collective of machines (both real and virtual) as a single group, such that I can apply some test on incoming requests to see if they originate from this group?
on Azure WebApps, You may wish to know; the IP Restrictions (https://learn.microsoft.com/en-us/azure/app-service/app-service-ip-restrictions) allow you to define a list of IP addresses that are allowed to access your app. The allow list can include individual IP addresses or a range of IP addresses defined by a subnet mask. When a request to the app is generated from a client, the IP address is evaluated against the allow list. If the IP address is not in the list, the app replies with an HTTP 403 status code.
You can use IP and Domain Restrictions to control the set of IP addresses, and address ranges, that are either allowed or denied access to in your websites. With Azure WebApps you can enable/disable the feature, as well as customize its behavior, using web.config files located in their website.
Additionally, VNET Integration gives your web app access to resources in your virtual network but does not grant private access to your web app from the virtual network. Private site access is only available with an ASE configured with an Internal Load Balancer (ILB).
If you haven’t checked this already, checkout Integrate your app with an Azure Virtual Network for more details on VNET Integration (https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet)
I strongly suggest dropping the whole what's my IP approach and throwing in OAuth. Azure AD gives you access tokens with moderate effort —
Service to service calls using client credentials (shared secret or certificate)
Else, TLS client authentication would be next on my list. Although that tends to really suck if you have to deal with several programming stacks, TLS offloaders and what not.

Resources