Private blob storage - azure

I have an Azure App Service which uses Blob Storage to host it's static files. For this particular app (staging environment) we only want to allow access from the app service and a specific set of ip addresses.
What is the best way to go about this? I tried providing an identity for the app service with the role of Owner but it keeps getting a 403 when trying to access blob storage.

I can reproduce your problem:
Why you still get 403 is because you are missing the necessary steps.
You have two way.
1, add service outbound ip to the firewall of storage.
2, put the app under a virtual network and then allow the VNET to access.
Common solution:
First of all, create a virtual network on azure.
Then add the network to the firewall setting of storage:
After above configuration, my Azure App Service can access the storage with no problem. Please have a try on your side.(Pleace notice that VNET configuration will not work immediately, you need wait for a little time.)

Related

.Net application, running in a Docker container unable to connect to Azure Storage when running on the virtual node

We have a .Net application, running in a docker container, connecting to Azure Storage, running on Azure AKS. We use the connectionString to connect to the Azure Storage, for both temporary file storage, as well as logging purposes. Our AKS sits within a vNet, with it's own subnet, and it happily connects to the storage, which also sits in its own subnet, with the two subnets linked via a service endpoint. The storage is not open to all networks, it's been set to only be enabled from selected virtual networks and IP addresses.
Now, if we try and move / run the container on the AKS virtual node, it's starts up amd runs without any issues, but if we try and hit the storage from within the container, we now have authorization issues:
Status: 403 (This request is not authorized to perform this
operation.) ErrorCode: AuthorizationFailure
Content: AuthorizationFailureThis
request is not authorized to perform this operation.
RequestId:131fd452-901e-001a-4329-f3010f000000
Time:2022-11-08T04:23:09.0663031Z
If I enable the storage to have public network access, it works, but we don't want this. So what our options to fix this seeing as we can't add a service endpoint to the underlying subnet / vNet on which the virtual node is running. We're also concerned, because this will probably affect any db connections as well, which will be an issue if we want to run our db backed containers on the virtual node.
Status: 403 (This request is not authorized to perform this operation.) ErrorCode: AuthorizationFailure
Content: AuthorizationFailureThis request is not authorized to perform this operation.
The above 403 errors occur you may not give proper permission and also you may not assign roles in storage account.
For principal authentication purpose you need to assign roles in your storage account.
Storage blob data owner
Storage blob data contributor.
Portal:
In portal go to your storage account -> Access Control (IAM) -> Add ->Add role assignments-> Storage blob data owner or Storage blob data contributor with your service principal.
After assigning it you can view the access through portal by referring below snap:
Make sure with Networking and Firewalls and virtual networks in the public access is set to Enabled from selected virtual networks and IP addresses.
Make sure you were adding correct virtual network and subnets in the portal and also virtual node client IP address in your environment issue may client IP was not added to the firewall rules for the storage account and also check the Allow Azure services on the trusted services list to access this storage account. in Checked state, Then, these trusted providers will establish a secure connection to your storage account using strong authentication.
Go to Azure Portal -> Storage Accounts -> Networking-> Enabled from selected virtual networks and IP addresses.
Reference:
Creating Azure Storage Containers in a storage account with network rules, with Terraform by Ansuman Bal

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.

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