Azure File Storage access by Azure Function - azure

Azure File Storage and Azure Function are under the same subscription.
File Storage has limited access to just:
"Enabled from selected virtual networks and IP addresses"
and I have a Function which doesn't have static IP address (even the IP addresses that it supposed to use are not correct).
Is there a way to enable access to this File Storage by my function from any IP address?
In the worst case scenario, is there a range for all Azure Function IP addresses?

You can lock down your storage account when you have your Function App VNet-integrated. This requires your Function to be deployed in either a Dedicated AppServicePlan or as a Premium Function plan. There is a detailed tutorial about this here:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-vnet#lock-down-your-storage-account

Related

Access Azure storage account from Azure Function App

I am trying to deploy azure function to function App via Visual studio code. But facing access issue forbidden 403 to storage account. Azure storage account access level is private. Due to data security reason I don't want to change access level. Do we have any option to resolve this issue without changing access level in storage account?
One of the workarounds is to whitelist the outbound IPs of the Function App in your storage account.
Before doing this make sure the function and the storage account are in different regions because if they are in the same region the requests take place internally which wouldn't go through any outbound IP Addresses.
If they are in different regions the storage account checks the IP addresses and allows the requests.
Since the storage account doesn't allow public access it wouldn't have the IPs listed which are to be allowed and therefore you need to add the outbound IP Addressess in the storage account.

How do I set a public static IP address to a storage account?

I have an Azure storage account with a blob endpoint of: 'blobstorageaccountname.blob.core.windows.net'. I want to choose a static IP Address, because some of my more zealous customers want to only allocate a known set of IP addresses through their firewall. I have already provided them with the list of Azure IP ranges for my Azure region, but they don't want to allocate such broad ranges.
Also: 1
In Azure portal | Storage | Networking | Custom domain: it says "Configure a custom domain for accessing blob data in your Azure storage account, like www.contoso.com".
If that is possible could I allocate the custom domain a static IP address?
Is it really only blob specific, what about queue endpoints? I could configure my DNS with each endpoint having a new CNAME entry.
Also: 2
Azure portal | Add new resource "Public IP Address", allows me to add a public statis IP address for a virtual network gateway (VNG?). I know it's possible to apply a static IP to a VM. How does one create or configure a VNG? or Azure VNet? to apply a static IP to a Storage endpoint?
I read these, but they were not helpful:
https://social.msdn.microsoft.com/forums/en-US/b7dbea96-5349-45c6-8774-f8c766d08e31/help-assign-static-ip-to-a-blob-storage-account?forum=windowsazuredata
Virtual Public IP address
Also posted on the Azure Docs Questions forum
As of 2022, Azure Storage service does not support public IPs, but Azure API management does.
Configuring APIm service with a public static IP, then create a 'pass through' endpoint for each storage type.
Each client's app.config needs "AzureWebJobsStorage" updated to send requests through an API Management route for each endpoint type. I am currently using a generic connection not specifying the endpoints, so each client will need updating to use the 'explicit storage endpoint connection string
Alternative to APIm: investigate dotnet YARP as a reverse proxy hosted on an Azure WebApp and manage re-routing that way.

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 Functions storage account network security

I am currently working with a client that requires access to all Azure resource locking down as much as possible and I am having problems with the Storage Account that is utilised by our Azure Functions.
With the Firewalls and Virtual Networks blade in portal set to "All Networks" I am able to deploy to the Function App and it runs without issue.
However once I enable the access restriction by checking "Selected Networks"no matter what virtual network subnets I enter or IP Addresses I can not get the communication to work
I have entered the Outbound IP Addresses of our Consumption based Function App and also check that the additional IP Addresses from the Powershell and all have been added to the whitelist. I have also added all the CIDR IP ranges of the local Azure datacenter but again it does not work.
The problem we have is that once the access restrictions have been put into place we are unable to deploy to the Function App and the app no longer runs. Is this scenario supported and what is the mechanism for tying down access to the Storage Account so that only the Function App can utilise it.
As far as I know, you have two options to restrict access to your storage account from your function app or web app.
Whitelist the outboundIpAddresses and possibleOutboundIpAddresses of the function app in the firewall of the storage account. However, it does not work if the Azure function app and Azure storage located in the same region refer to Sam's answer.
when you hit the storage account from your function, because they are
in the same region as each other, all the traffic goes over the
internal Azure network on internal IP's, not the public IPs listed in
the web app, and so is not allowed over the firewall.
If your resources were in different regions, you could use the network section of function app to allow function app to access resources in a VNet, then enable service endpoint for Microsoft.Storage in this app integration subnet. But you need Azure Functions Premium plan referring to this tutorial: integrate Functions with an Azure virtual network.
Sometimes, the deployment order for networking is important. In this case, you will deploy the followings:
Firstly, you could deploy new VNet integration with an unused subnet. After the VNet Integration is completed and the function app is restarted, you could enable service endpoint for this subnet. In the end, you could add the subnet in the firewall of the storage account.
Note that the new version is in Preview, currently. You could also check these characteristics and get more references from this thread.

Azure Functions access to Azure Storage Account Firewall

What am I trying to achieve
Connect to an Azure BLOB storage account that sits behind a firewall through an Azure Function.
Steps Taken so Far
Azure Function developed and tested against public storage account which works as expected.
Following Azure Resource Explorer for my Azure Function I find out the outbound addresses("outboundIpAddresses" entry) and I add them in the firewall of the storage Account.
Issue
While trying to run the Azure Function against the storage account with the firewall I am getting a Status: 500 Internal Server Error - This request is not authorized to perform this operation.
What am I missing here?
You won't be able to achieve what you want here currently. When you hit the storage account from your funciton, because they are in the same region as each other, all the traffic goes over the internal Azure network on internal IP's, not the public IPs listed in the web app, and so is not allowed over the firewall (I have had this confirmed by Azure support). Because you don't have access to the internal IPs of the function, and even if you did they can change, you can't whitelist them.
If your resources were in different regions, traffic would go over the external IPs and you would have more success.

Resources