简体   繁体   English

Azure function 连接到 Azure Vnet 问题后的 Blob 存储

[英]Azure function connection to Azure Blob storage behind Vnet issue

We are currently migrating to a new Azure Subscription and are having issues executing Azure Functions that worked as expected in our old Azure Subscription.我们目前正在迁移到新的 Azure 订阅,并且在执行 Azure 功能时遇到问题,这些功能在我们的旧 Azure 订阅中按预期工作。 The man difference between our old Subscription and our new Subscription is that we have set up a Virtual Network with Subnets and have deployed our Resources behind the Subnets.我们的旧订阅和新订阅之间的差异在于我们已经建立了一个带有子网的虚拟网络,并在子网后面部署了我们的资源。

We have also had to migrate from an Azure App Service in the old Subscription to a Azure App Environment in the new Subscription.我们还必须从旧订阅中的 Azure 应用服务迁移到新订阅中的 Azure 应用环境。

Our Azure environment consist of:我们的 Azure 环境包括:

App Service Environment应用服务环境

App Service Plan I1应用服务计划 I1

The Azure App Environment and Storage Containers are on the same Virtual Network but different Sub Nets. Azure 应用环境和存储容器在同一个虚拟网络上,但在不同的子网上。 The Function is using a Managed Identity which has Owner Role on Storage Account. Function 使用在存储帐户上具有所有者角色的托管身份。

The code listed below worked just fine in our old environment which did not contain the Virtual Network, but fails in our new environment.下面列出的代码在我们不包含虚拟网络的旧环境中运行良好,但在我们的新环境中失败。

Any guidance would be greatly appreciated.任何指导将不胜感激。

The Azure function which connects to Azure Storage works when run locally from Visual Studio 2019, but fails when run from Azure portal. The Azure function which connects to Azure Storage works when run locally from Visual Studio 2019, but fails when run from Azure portal.

Code Snippet below:代码片段如下:

This section works just fine:

     string storageConnectionString = XXXXConn.ConnectionETLFileContainer();//Get Storage connection string

                var myDirectory = "XXXX/Uploads"; ///XXXX-etl-file-ingest/ABSS/Uploads/                     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();// Create a CloudBlobClient object for credentialed access to Azure Blob.                                      CloudBlobContainer blobContainer = blobClient.GetContainerReference("XXXX-etl-blobfile-ingest");// Get a reference to the Blob Container we created previously.                                      CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(myDirectory);// Get a reference to the Blob Directory.

                var blobs = blobDirectory.ListBlobs(useFlatBlobListing: true); //set useFlatBlobListing as true 

This statement fails: Failure occurs when trying to iterate through the Blob files and get specific file info.此语句失败:尝试遍历 Blob 文件并获取特定文件信息时发生故障。

foreach (var myblob in blobs) foreach (var myblob in blob)

In the azure portal open storage account blade under that go to configuration blade, you will be able to see the list of networks for which your storage account has allowed access to.Once you have the allowed network list kindly check if the function app is on one of those networks if not then you need to get the network on which your function app is hosted added to the list.在 azure 门户打开存储帐户刀片下 go 到配置刀片,您将能够看到您的存储帐户允许访问的网络列表。一旦您拥有允许的网络列表,请检查 ZC1C425268E617A74D 上是否存在如果不是其中一个网络,那么您需要将托管 function 应用程序的网络添加到列表中。

Update 2:更新 2:
The simplest explanation/cause that I found is when an App Service or Function App has the setting WEBSITE_VNET_ROUTE_ALL set to 1 , all traffic to public endpoints is blocked.我发现的最简单的解释/原因是,当应用服务或 Function 应用的设置WEBSITE_VNET_ROUTE_ALL设置为1时,到公共端点的所有流量都被阻止。 So if your Storage Account has no private endpoint configured, requests to it will fail.因此,如果您的存储帐户没有配置专用端点,对它的请求将失败。

Docs: "To block traffic to public addresses, you must have the application setting WEBSITE_VNET_ROUTE_ALL set to 1."文档:“要阻止到公共地址的流量,您必须将应用程序设置 WEBSITE_VNET_ROUTE_ALL 设置为 1。”
https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet.network-security-groups https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet.network-security-groups

Update 1:更新1:
My answer below was only a workaround for my problem.我在下面的回答只是解决我的问题的方法。 Turns out I did not link the Private DNS Zone (this is created for you when you create a new Private Endpoint) to my VNET.原来我没有将私有 DNS 区域(这是在您创建新的私有端点时为您创建的)链接到我的 VNET。

To do this, go to your Private DNS Zone in the Azure Portal and click on Virtual network links in the left menu bar.为此,go 到 Azure 门户中的私有 DNS 区域,然后单击左侧菜单栏中的Virtual network links There add a new link to the VNET your Function is integrated in.向您的 Function 集成的 VNET 添加一个新链接。

This may not have been relevant for the OP, but hopefully it will help others.这可能与 OP 无关,但希望它能对其他人有所帮助。


Original answer:原答案:
In my case this was solved by enabling the Microsoft.Storage Service Endpoint on the App Service's subnet (dedicated subnet).在我的情况下,这是通过在应用服务的子网(专用子网)上启用Microsoft.Storage服务端点来解决的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM