Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

[Premium] Function App errors when storage account has VNET ACL

Open ishepherd opened this issue 5 years ago • 37 comments

We want to add a VNET ACL to the storage account used by a function app

The networking page says this can be done, if you can wait 12 hours: https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options#restricting-your-storage-account-to-a-virtual-network,

We've found it doesn't work. Gives access denied trying to access D:\home\LogFiles\Application\Functions\Host

Actually, the page I linked to above explains this error:

There are some things that VNet Integration doesn't support including: Mounting a drive

Can this be fixed? We have a requirement to lock down all resources.

ishepherd avatar Oct 03 '19 04:10 ishepherd

paraphrasing off-thread with @alexkarcher-msft: This is supposed to work - if left alone long enough. The documentation point "doesn't support ... Mounting a drive" is unrelated.

I will see if I can repro the issue.

ishepherd avatar Oct 10 '19 02:10 ishepherd

@alexkarcher-msft I have a repro for this now. UnauthorizedAccessExceptions for 16 hours and counting.

Access to the path 'D:\home\LogFiles\Application\Functions\Host' is denied. 

System.UnauthorizedAccessException:
   at System.IO.FileSystem.CreateDirectory (System.IO.FileSystem, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
   at System.IO.Directory.CreateDirectory (System.IO.FileSystem, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
   at System.IO.Abstractions.DirectoryWrapper.CreateDirectory (System.IO.Abstractions, Version=2.1.0.227, Culture=neutral, PublicKeyToken=96bf224d23c43e59)
   at Microsoft.Azure.WebJobs.Script.FileUtility.EnsureDirectoryExists (Microsoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-script\src\WebJobs.Script\Extensions\FileUtility.csMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: 38)
   at Microsoft.Azure.WebJobs.Script.ScriptHost.InitializeFileSystem (Microsoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.csMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: 433)
   at Microsoft.Azure.WebJobs.Script.ScriptHost.PreInitialize (Microsoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.csMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: 425)
   at Microsoft.Azure.WebJobs.Script.ScriptHost+<InitializeAsync>d__80.MoveNext (Microsoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.csMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: 256)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Script.ScriptHost+<StartAsyncCore>d__79.MoveNext (Microsoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.csMicrosoft.Azure.WebJobs.Script, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: 237)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Extensions.Hosting.Internal.Host+<StartAsync>d__9.MoveNext (Microsoft.Extensions.Hosting, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Script.WebHost.WebJobsScriptHostService+<UnsynchronizedStartHostAsync>d__37.MoveNext (Microsoft.Azure.WebJobs.Script.WebHost, Version=2.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Script.WebHost, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\WebJobsScriptHostService.csMicrosoft.Azure.WebJobs.Script.WebHost, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null: 209)

image

ishepherd avatar Oct 15 '19 23:10 ishepherd

Edit Restarting the app did not help.

ishepherd avatar Oct 15 '19 23:10 ishepherd

Off-thread with @alexkarcher-msft: The issue is understood and a fix is coming

Alex you might consider updating the relevant doc in the meantime - Cheers

ishepherd avatar Oct 17 '19 04:10 ishepherd

Good call out! I have a PR out to update the docs

https://github.com/MicrosoftDocs/azure-docs-pr/pull/92236

alexkarcher-msft avatar Oct 17 '19 18:10 alexkarcher-msft

@fabiocav you closed this, but @alexkarcher-msft is the fix still coming? How will we know when it's arrived?

ishepherd avatar Oct 30 '19 00:10 ishepherd

Ah, sorry. I confused this with a separate issue. We identified a workaround for this scenario, and need to fully document it.

It looks like you can connect to a secured storage account using run from package as a URL and that will allow your code to be stored in a VNET secured storage account https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package#enabling-functions-to-run-from-a-package

With that configuration you will need a separate storage account with just your code as a zip. Then, you should be able to secure your other account with VNET service endpoints.

I haven't had a chance to test this configuration, but this is the current workaround we're tracking :)

alexkarcher-msft avatar Oct 30 '19 18:10 alexkarcher-msft

Thanks @alexkarcher-msft

Good that there's a workaround but anything that compromises reliability is a no-go - Below re an incident we had on 2019-05-28, investigated by @FinVamp1. our ref SMDS-1894. Also your link notes the impact on cold start performance which is not great either.

Will we be able to use WEBSITE_RUN_FROM_PACKAGE = 1 and any guesses on ETA?


For the 404 issue on the 28th of May three of the four workers assigned to the site ran into this pattern.

  1. The worker is assigned.
  2. It goes to download the Zip file from Storage for the application.
  3. The Storage Account takes time to respond (up to 29 seconds on two of the instances.)
  4. The Zip download fails.
  5. A file called "FAILED TO DOWNLOAD ZIP FILE.txt" is created at D:\Home\Site\wwwroot
  6. As we have no Host.json we create an empty one.
  7. We cannot save this to disk as D:\Home\Site\wwwrot is still read only.
  8. We send requests to this worker anyway and these return a 404.

ishepherd avatar Oct 30 '19 20:10 ishepherd

@alexkarcher-msft , is it still not possible to secure the underlying storage account of a (Premium Plan) Function App with Vnet integration? How should I undrestand "wait 12h" - we cannot have a downtime for 12h if func app cannot connect to storage account ... Is WEBSITE_RUN_FROM_PACKAGE = 1 the only way how this can work? I understand it is not recommended due to cold start issues, or is it fine for Premium Plan Function Apps?

deyanp avatar May 06 '20 12:05 deyanp

At this moment you shouldn’t need to wait for the VNet routes to establish when adding a service endpoint / private link service to call from your function. However, you still need some storage account that doesn’t have a VNet for the WEBSITE_CONTENTFILECONNECTIONSTRING app setting. That’s where your code is stored when doing general publish gestures (anything but run from package = some URL to a zip file). The feature to allow even that storage account to be behind a VNet via private link is checked in and rolling out in our next platform update. Likely about 2 months out.

jeffhollan avatar May 06 '20 14:05 jeffhollan

@jeffhollan this is great news, assuming I got it correctly - we will be finally able to network/firewall-secure (using service endpoints and vnet integration) the underlying storage account of a function app in 2 months!

Or will only private link be supported, and no service endpoints?

deyanp avatar May 07 '20 06:05 deyanp

Any updates? service endpoint for storage accounts and KeyVault really impact many customers.

alexandrelimait avatar Jun 18 '20 09:06 alexandrelimait

Same Issue

justinimel avatar Sep 01 '20 04:09 justinimel

I got the same issue

Carrie810 avatar Sep 12 '20 03:09 Carrie810

Still coming - best ETA would be end of this year. We hit an issue with the deployment for the earlier ETA so doing a bit phased rollout later this year

jeffhollan avatar Sep 12 '20 03:09 jeffhollan

same issue

alona-shevliakova avatar Oct 13 '20 07:10 alona-shevliakova

same issue

fanasere avatar Oct 18 '20 08:10 fanasere

Heads up preview just went live for West Europe - let us know if you have any issues with this and hope to push it out globally in the coming weeks https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options#restrict-your-storage-account-to-a-virtual-network-preview

jeffhollan avatar Oct 28 '20 17:10 jeffhollan

Same issue here, will follow this issue.

JamesDLD avatar Nov 24 '20 10:11 JamesDLD

Thanks @jeffhollan for mentioning that link. I have my solution for West Europe and it did work. Following changes were done in function appsettings to make it work.

WEBSITE_CONTENTOVERVNET = 1. WEBSITE_VNET_ROUTE_ALL = 1. WEBSITE_DNS_SERVER =168.63.129.16.

VishalNagarAR avatar Dec 17 '20 14:12 VishalNagarAR

I have this issue as well. @jeffhollan, will the preview be available globally soon? I am in West US 2 and would like to try it.

knaidoo33 avatar Dec 28 '20 17:12 knaidoo33

Just updating - this is now GLOBAL, and generally available.

jeffhollan avatar Feb 05 '21 00:02 jeffhollan

Just updating - this is now GLOBAL, and generally available.

Any ETA on when this will support Linux Plans please?

Bunzab avatar Feb 17 '21 19:02 Bunzab

@jeffhollan - I am still not able to get this working with a storage account secured by Private Endpoint. I did create a PV3 App Service plan (To ensure we are on the latest scale unit) and then scaled it to EP1 using ARM Template but I still keep on getting -

Access to the path 'C:\home\site\wwwroot' is denied.
System.Private.CoreLib: Access to the path 'C:\home\site\wwwroot\host.json' is denied.

I have the following App Settings in place -

- AzureWebJobsStorage
- WEBSITE_CONTENTAZUREFILECONNECTIONSTRING
- WEBSITE_CONTENTOVERVNET = 1
- WEBSITE_VNET_ROUTE_ALL = 1

Both AzureWebJobsStorage & WEBSITE_CONTENTAZUREFILECONNECTIONSTRING are backed by a Storage Account which is accessible only over a Private Endpoint. Here is the support ticket # for reference - 2102280040000493

Thanks, Pranav

blueelvis avatar Feb 28 '21 17:02 blueelvis

@blueelvis I am facing the same issue and I am not sure if your support ticket got any resolution? Can you please share if there was any resolution. I am facing exactly same issue as you are having and its now July 2021 and I have ensured the configuration have all those App settings as well. @jeffhollan any help on this please?

image

DeepMalh44 avatar Jul 10 '21 15:07 DeepMalh44

Resolved: it seems that adding the "WEBSITE_RUN_FROM_PACKAGE" = 1 app settings to the Function App settings gets rid of that error.

DeepMalh44 avatar Jul 10 '21 20:07 DeepMalh44

@ketaanhshah did you run into a 503 error on the scm? i get service unavailable the function app gets created

judedaryl avatar Aug 25 '21 12:08 judedaryl

@blueelvis I am facing the same issue and I am not sure if your support ticket got any resolution? Can you please share if there was any resolution. I am facing exactly same issue as you are having and its now July 2021 and I have ensured the configuration have all those App settings as well. @jeffhollan any help on this please?

image

This helped me.

victormendozalex avatar Sep 08 '21 07:09 victormendozalex

We are facing the same error in a function with a dedicated App service plan in production.

We have a storage account that we secured and had no problems in the staging environments. Our staging environments use a dedicated app service plan as well, but is not a premium: tier - Standard, size -S1 , capacity - 1. However, the above mentioned error appeared in production: tier - PremiumV2, size -P1v2 , capacity - 2.

We had to revert the security changes in prod and now I'm trying to reproduce the problem in staging but it seems to be really tricky. I have not managed to reproduce the error even after scaling up the staging environment to the same tier as in prod. Does anyone have any suggestions? I can't try the fixes from this thread until I am able to check if they fix the problem or not. And I can't do this in prod.

ben-002 avatar Sep 22 '21 14:09 ben-002

Same issue here. I am deploying both the function app and it's staging deployment slot through terraform using the Elastic Premium Linux. The deployment slot is working fine, but somehow the production slot is not able to reach the storage account. Disabling the vnet integration and network deny in the storage account bring the function back online. The settings are the same as @ketaanhshah posted. The NSG, Service Endpoints are configured correctly (tested it with SSH tcpping). I feel like the CONTENTSHARE is not suitable for the scenario where the SA configured with deny rule, or at least not suitable for File Share, since the WebJobsStorage configuration is reachting the blobs behind a firewall.

apsi15 avatar Nov 30 '21 07:11 apsi15